@deveye/types 0.17.1 → 0.18.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/src/sdk/server.ts CHANGED
@@ -29,6 +29,8 @@ import type {
29
29
  CloudSyncStatePush
30
30
  } from '../protocol/agent';
31
31
 
32
+ export { isPublicIp, isSafePublicUrl } from './net';
33
+
32
34
  /**
33
35
  * Server-side SDK surface: what a feature module's handlers and background
34
36
  * service are given, and nothing else.
@@ -543,6 +545,31 @@ export interface SdkLive {
543
545
  * this data.
544
546
  */
545
547
  changed(workspaceId: number, topics?: readonly string[]): void;
548
+ /**
549
+ * Pushes one frame to every member of `workspaceId` connected right now
550
+ * and holding `read` on YOUR feature (capability `'live.publish'`). The
551
+ * client reads it with `onServerEvent(event, schema, cb)`.
552
+ *
553
+ * The lane for what must be seen AS it happens rather than re-fetched: a
554
+ * cell someone just drew on a shared board. It carries the CHANGE, never
555
+ * the whole state, and it is best-effort by construction, so a client that
556
+ * missed one must be able to recover on its own (a periodic epoch, a
557
+ * re-fetch on reconnection) rather than assume every frame lands.
558
+ *
559
+ * `event` must start with `<manifest.id>.`, like a command; a `requestId`
560
+ * is never attached, so it can never be mistaken for a reply.
561
+ */
562
+ publish(workspaceId: number, event: string, payload: unknown): void;
563
+ }
564
+
565
+ /**
566
+ * The live engine seen from a HANDLER, where the workspace is the caller's.
567
+ * Invalidation stays declarative there (`mutates` on the command), so the only
568
+ * thing left to do by hand is the push lane.
569
+ */
570
+ export interface SdkContextLive {
571
+ /** {@link SdkLive.publish}, in the workspace of the call. */
572
+ publish(event: string, payload: unknown): void;
546
573
  }
547
574
 
548
575
  /** The whole fleet, sessionless (capability `'devices.read'`), for services. */
@@ -599,6 +626,8 @@ export interface SdkFeatureContext<Repo = unknown> {
599
626
  requestId: string;
600
627
  /** The server key derivations, the same `keys` a service gets. */
601
628
  keys: SdkServerKeys;
629
+ /** The push lane, in this workspace (capability `'live.publish'`). */
630
+ live: SdkContextLive;
602
631
  /**
603
632
  * Where DevEye lives, as URLs without a trailing slash: `app` is the
604
633
  * origin members use (`PUBLIC_ORIGIN`), `public` the one reachable
@@ -109,6 +109,8 @@ export interface RecordedCalls {
109
109
  agentRequests: { method: string; deviceId: string }[];
110
110
  /** Instants pinned through `telemetry.pinInstant`. */
111
111
  pinnedInstants: { deviceId: string; ts: number }[];
112
+ /** Frames pushed through `live.publish`, in order. */
113
+ livePublishes: { workspaceId: number; event: string; payload: unknown }[];
112
114
  }
113
115
 
114
116
  function recordingNotify(
@@ -306,7 +308,8 @@ export function createTestContext<Repo = undefined>(
306
308
  liveMessages: [],
307
309
  audits: [],
308
310
  agentRequests: [],
309
- pinnedInstants: []
311
+ pinnedInstants: [],
312
+ livePublishes: []
310
313
  };
311
314
  const isOwner = overrides.isOwner ?? true;
312
315
  const workspaceId = overrides.workspaceId ?? 1;
@@ -354,6 +357,11 @@ export function createTestContext<Repo = undefined>(
354
357
  openBytes: () => null,
355
358
  derive: fakeDerive
356
359
  },
360
+ live: {
361
+ publish(event, payload) {
362
+ recorded.livePublishes.push({ workspaceId, event, payload });
363
+ }
364
+ },
357
365
  items: {
358
366
  restrictions: () => Promise.resolve(restrictions),
359
367
  // The exact rule of the app's dispatcher: the feature first (a
@@ -472,6 +480,7 @@ export function createTestServiceDeps<Repo = undefined>(
472
480
  audits: [],
473
481
  agentRequests: [],
474
482
  pinnedInstants: [],
483
+ livePublishes: [],
475
484
  tickers: [],
476
485
  liveChanges: [],
477
486
  liveTopicChanges: []
@@ -535,6 +544,9 @@ export function createTestServiceDeps<Repo = undefined>(
535
544
  changed(workspaceId, topics) {
536
545
  recorded.liveChanges.push(workspaceId);
537
546
  if (topics) recorded.liveTopicChanges.push({ workspaceId, topics });
547
+ },
548
+ publish(workspaceId, event, payload) {
549
+ recorded.livePublishes.push({ workspaceId, event, payload });
538
550
  }
539
551
  },
540
552
  audit: (entry) => {