@pickleball/server-sdk 0.1.1 → 0.3.0
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/CHANGELOG.md +30 -0
- package/README.md +22 -0
- package/dist/{chunk-HBTNLURN.js → chunk-UPS4VFER.js} +188 -21
- package/dist/index.cjs +189 -21
- package/dist/index.d.cts +168 -3
- package/dist/index.d.ts +168 -3
- package/dist/index.js +3 -1
- package/dist/proxy.cjs +321 -23
- package/dist/proxy.d.cts +11 -1
- package/dist/proxy.d.ts +11 -1
- package/dist/proxy.js +133 -3
- package/package.json +2 -2
package/dist/proxy.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
PickleballNetworkError,
|
|
7
7
|
PickleballTimeoutError,
|
|
8
8
|
createPickleballLiveClient
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-UPS4VFER.js";
|
|
10
10
|
|
|
11
11
|
// src/proxy.ts
|
|
12
12
|
var MAX_BODY_BYTES = 16 * 1024;
|
|
@@ -138,8 +138,9 @@ function startBody(value) {
|
|
|
138
138
|
"visibility",
|
|
139
139
|
"consentVersion",
|
|
140
140
|
"metadata",
|
|
141
|
-
"standby"
|
|
142
|
-
|
|
141
|
+
"standby",
|
|
142
|
+
"quality"
|
|
143
|
+
]) || !nonblank(value.externalSessionId, 256) || !nonblank(value.title, 200) || !nonblank(value.consentVersion, 100) || value.visibility !== void 0 && value.visibility !== "public" && value.visibility !== "private" || value.standby !== void 0 && typeof value.standby !== "boolean" || value.quality !== void 0 && value.quality !== 720 && value.quality !== 1080) {
|
|
143
144
|
throw new InvalidRequest();
|
|
144
145
|
}
|
|
145
146
|
if (value.metadata !== void 0) {
|
|
@@ -395,9 +396,138 @@ async function handleSessionAction(request, params, deps) {
|
|
|
395
396
|
return null;
|
|
396
397
|
});
|
|
397
398
|
}
|
|
399
|
+
var DEVICE_INFO_FIELDS = ["appVersion", "deviceName", "deviceModel", "osVersion"];
|
|
400
|
+
var DEVICE_METRIC_NUMBER_FIELDS = [
|
|
401
|
+
"ramFreeMb",
|
|
402
|
+
"ramTotalMb",
|
|
403
|
+
"storageFreeGb",
|
|
404
|
+
"batteryPct",
|
|
405
|
+
"batteryTempC",
|
|
406
|
+
"thermal",
|
|
407
|
+
"linkMbps",
|
|
408
|
+
"rssi"
|
|
409
|
+
];
|
|
410
|
+
var DEVICE_METRIC_STRING_FIELDS = ["netType", "connQuality"];
|
|
411
|
+
function deviceInfoFields(value) {
|
|
412
|
+
const info = {};
|
|
413
|
+
for (const field of DEVICE_INFO_FIELDS) {
|
|
414
|
+
const entry = value[field];
|
|
415
|
+
if (entry === void 0) continue;
|
|
416
|
+
if (!nonblank(entry, 200)) throw new InvalidRequest();
|
|
417
|
+
info[field] = entry;
|
|
418
|
+
}
|
|
419
|
+
return info;
|
|
420
|
+
}
|
|
421
|
+
function deviceRegisterBody(value) {
|
|
422
|
+
if (!hasOnlyKeys(value, [
|
|
423
|
+
"sdkVersion",
|
|
424
|
+
"platform",
|
|
425
|
+
"bundleId",
|
|
426
|
+
"installationId",
|
|
427
|
+
...DEVICE_INFO_FIELDS
|
|
428
|
+
])) {
|
|
429
|
+
throw new InvalidRequest();
|
|
430
|
+
}
|
|
431
|
+
const identity = bootstrapBody({
|
|
432
|
+
sdkVersion: value.sdkVersion,
|
|
433
|
+
platform: value.platform,
|
|
434
|
+
bundleId: value.bundleId,
|
|
435
|
+
installationId: value.installationId
|
|
436
|
+
});
|
|
437
|
+
return { ...identity, ...deviceInfoFields(value) };
|
|
438
|
+
}
|
|
439
|
+
function deviceMetricsFields(value) {
|
|
440
|
+
if (value === void 0) return void 0;
|
|
441
|
+
if (!isObject(value)) throw new InvalidRequest();
|
|
442
|
+
if (!hasOnlyKeys(value, [...DEVICE_METRIC_NUMBER_FIELDS, ...DEVICE_METRIC_STRING_FIELDS])) {
|
|
443
|
+
throw new InvalidRequest();
|
|
444
|
+
}
|
|
445
|
+
const metrics = {};
|
|
446
|
+
for (const field of DEVICE_METRIC_NUMBER_FIELDS) {
|
|
447
|
+
const entry = value[field];
|
|
448
|
+
if (entry === void 0) continue;
|
|
449
|
+
if (typeof entry !== "number" || !Number.isFinite(entry)) throw new InvalidRequest();
|
|
450
|
+
metrics[field] = entry;
|
|
451
|
+
}
|
|
452
|
+
for (const field of DEVICE_METRIC_STRING_FIELDS) {
|
|
453
|
+
const entry = value[field];
|
|
454
|
+
if (entry === void 0) continue;
|
|
455
|
+
if (!nonblank(entry, 50)) throw new InvalidRequest();
|
|
456
|
+
metrics[field] = entry;
|
|
457
|
+
}
|
|
458
|
+
return metrics;
|
|
459
|
+
}
|
|
460
|
+
function deviceHeartbeatBody(value) {
|
|
461
|
+
if (!hasOnlyKeys(value, [
|
|
462
|
+
"sdkVersion",
|
|
463
|
+
"platform",
|
|
464
|
+
"bundleId",
|
|
465
|
+
"installationId",
|
|
466
|
+
"agentState",
|
|
467
|
+
"currentSessionId",
|
|
468
|
+
"appVersion",
|
|
469
|
+
"metrics"
|
|
470
|
+
])) {
|
|
471
|
+
throw new InvalidRequest();
|
|
472
|
+
}
|
|
473
|
+
const identity = bootstrapBody({
|
|
474
|
+
sdkVersion: value.sdkVersion,
|
|
475
|
+
platform: value.platform,
|
|
476
|
+
bundleId: value.bundleId,
|
|
477
|
+
installationId: value.installationId
|
|
478
|
+
});
|
|
479
|
+
if (value.agentState !== void 0 && !nonblank(value.agentState, 50)) {
|
|
480
|
+
throw new InvalidRequest();
|
|
481
|
+
}
|
|
482
|
+
if (value.currentSessionId !== void 0 && value.currentSessionId !== null && !nonblank(value.currentSessionId, 256)) {
|
|
483
|
+
throw new InvalidRequest();
|
|
484
|
+
}
|
|
485
|
+
if (value.appVersion !== void 0 && !nonblank(value.appVersion, 200)) {
|
|
486
|
+
throw new InvalidRequest();
|
|
487
|
+
}
|
|
488
|
+
const metrics = deviceMetricsFields(value.metrics);
|
|
489
|
+
return {
|
|
490
|
+
...identity,
|
|
491
|
+
...value.agentState === void 0 ? {} : { agentState: value.agentState },
|
|
492
|
+
...value.currentSessionId === void 0 ? {} : { currentSessionId: value.currentSessionId },
|
|
493
|
+
...value.appVersion === void 0 ? {} : { appVersion: value.appVersion },
|
|
494
|
+
...metrics === void 0 ? {} : { metrics }
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
function deviceClientFor(deps) {
|
|
498
|
+
const client = clientFor(deps);
|
|
499
|
+
if (!client.devices) {
|
|
500
|
+
throw new PickleballConfigurationError("Proxy client does not support devices");
|
|
501
|
+
}
|
|
502
|
+
return client.devices;
|
|
503
|
+
}
|
|
504
|
+
async function handleDeviceRegister(request, deps) {
|
|
505
|
+
return execute(deps, async () => {
|
|
506
|
+
const authorization = userAuthorization(request.headers);
|
|
507
|
+
const attestation = appAttestation(request.headers);
|
|
508
|
+
const identity = identityFromHeaders(request.headers);
|
|
509
|
+
const input = deviceRegisterBody(await bodyObject(request));
|
|
510
|
+
if (!identitiesMatch(identity, input)) throw new InvalidRequest();
|
|
511
|
+
await authorize(deps, authorization, "device_register", identity, {}, attestation);
|
|
512
|
+
return deviceClientFor(deps).register(input);
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
async function handleDeviceHeartbeat(request, deps) {
|
|
516
|
+
return execute(deps, async () => {
|
|
517
|
+
const authorization = userAuthorization(request.headers);
|
|
518
|
+
const attestation = appAttestation(request.headers);
|
|
519
|
+
const identity = identityFromHeaders(request.headers);
|
|
520
|
+
const input = deviceHeartbeatBody(await bodyObject(request));
|
|
521
|
+
if (!identitiesMatch(identity, input)) throw new InvalidRequest();
|
|
522
|
+
await authorize(deps, authorization, "device_heartbeat", identity, {}, attestation);
|
|
523
|
+
return deviceClientFor(deps).heartbeat(input);
|
|
524
|
+
});
|
|
525
|
+
}
|
|
398
526
|
export {
|
|
399
527
|
createStableIdempotencyKey,
|
|
400
528
|
handleBootstrap,
|
|
529
|
+
handleDeviceHeartbeat,
|
|
530
|
+
handleDeviceRegister,
|
|
401
531
|
handleSessionAction,
|
|
402
532
|
handleSessions
|
|
403
533
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pickleball/server-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Framework-free server SDK for Pickleball Live",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "tsup src/index.ts src/proxy.ts --format esm,cjs --dts --clean",
|
|
60
60
|
"test": "vitest run",
|
|
61
|
-
"typecheck": "
|
|
61
|
+
"typecheck": "tsc --noEmit && pnpm run typecheck:nodenext",
|
|
62
62
|
"typecheck:nodenext": "tsc --noEmit -p tsconfig.nodenext.json",
|
|
63
63
|
"verify:pack": "node scripts/verify-pack.mjs"
|
|
64
64
|
}
|