@scp-dev/broker 0.3.0 → 0.4.1

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/dist/index.js CHANGED
@@ -1805,7 +1805,8 @@ async function startBroker(options) {
1805
1805
  if (typeof key === "string") s.data.process = key;
1806
1806
  const was2 = before2.get(endpoint2.id)?.address;
1807
1807
  if (join5 !== void 0) membership(endpoint2, core.sessionOf(endpoint2.id), true, was2?.slice(was2.lastIndexOf("/") + 1));
1808
- if (under !== void 0 && before2.get(endpoint2.id)?.parent !== endpoint2.parent) bridge?.resync();
1808
+ const tookOver = join5 !== void 0 && [...before2.values()].some((view) => view.id !== endpoint2.id && view.address === endpoint2.address);
1809
+ if (tookOver || under !== void 0 && before2.get(endpoint2.id)?.parent !== endpoint2.parent) bridge?.resync();
1809
1810
  else if ((before2.get(endpoint2.id)?.presence ?? "offline") !== endpoint2.presence) presenceChanged(endpoint2);
1810
1811
  return {
1811
1812
  endpoint: endpoint2,
@@ -1966,20 +1967,37 @@ async function startBroker(options) {
1966
1967
  return { changed };
1967
1968
  }
1968
1969
  case "rename": {
1969
- const renamed = core.rename(actorOf(s), { ...params.endpoint !== void 0 ? { endpoint: params.endpoint } : {}, handle: params.handle });
1970
+ const renamed = core.rename(actorOf(s), {
1971
+ ...params.endpoint !== void 0 ? { endpoint: params.endpoint } : {},
1972
+ handle: params.handle,
1973
+ ...params.take_over !== void 0 ? { take_over: params.take_over } : {}
1974
+ });
1970
1975
  membership(renamed.endpoint, renamed.session, true, renamed.from);
1976
+ if (renamed.retired) bridge?.resync();
1971
1977
  return renamed.endpoint;
1972
1978
  }
1973
1979
  case "adopt": {
1974
1980
  const actor = actorOf(s);
1975
- const adopted = core.adopt(
1981
+ const adopted = await core.adopt(
1976
1982
  actor,
1977
1983
  { endpoint: params.endpoint, ...params.parent !== void 0 ? { parent: params.parent } : {} },
1978
- { tty: actor.kind === "endpoint" && s.data.terminal === true }
1984
+ {
1985
+ tty: actor.kind === "endpoint" && s.data.terminal === true,
1986
+ send: (from, send, origin) => {
1987
+ loadPolicy();
1988
+ if (policyError) throw new RelayError3("policy_refused", policyError);
1989
+ return judge.send(from, send, { tty: false, ...origin }, deliver);
1990
+ }
1991
+ }
1979
1992
  );
1980
1993
  bridge?.resync();
1981
1994
  return adopted;
1982
1995
  }
1996
+ case "link_accept": {
1997
+ const linked = core.linkAccept(actorOf(s), { id: params.id });
1998
+ bridge?.resync();
1999
+ return linked;
2000
+ }
1983
2001
  case "unlink": {
1984
2002
  const unlinked = core.unlink(actorOf(s), params.endpoint !== void 0 ? { endpoint: params.endpoint } : {});
1985
2003
  bridge?.resync();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scp-dev/broker",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Swarm Communication Protocol local broker: a unix socket JSON-RPC daemon over the relay core, its client and the bridge to an account hub.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://scp.dev",
@@ -37,8 +37,8 @@
37
37
  "typecheck": "tsc -p ."
38
38
  },
39
39
  "dependencies": {
40
- "@scp-dev/core": "0.2.0",
41
- "@scp-dev/hub": "0.6.0"
40
+ "@scp-dev/core": "0.3.1",
41
+ "@scp-dev/hub": "0.6.2"
42
42
  },
43
43
  "devDependencies": {
44
44
  "tsup": "^8.5.1"
package/src/server.ts CHANGED
@@ -795,7 +795,8 @@ export async function startBroker(options: BrokerOptions): Promise<Broker> {
795
795
  if (typeof key === "string") s.data.process = key
796
796
  const was = before.get(endpoint.id)?.address
797
797
  if (join !== undefined) membership(endpoint, core.sessionOf(endpoint.id), true, was?.slice(was.lastIndexOf("/") + 1))
798
- if (under !== undefined && before.get(endpoint.id)?.parent !== endpoint.parent) bridge?.resync()
798
+ const tookOver = join !== undefined && [...before.values()].some((view) => view.id !== endpoint.id && view.address === endpoint.address)
799
+ if (tookOver || (under !== undefined && before.get(endpoint.id)?.parent !== endpoint.parent)) bridge?.resync()
799
800
  else if ((before.get(endpoint.id)?.presence ?? "offline") !== endpoint.presence) presenceChanged(endpoint)
800
801
  return {
801
802
  endpoint,
@@ -956,20 +957,37 @@ export async function startBroker(options: BrokerOptions): Promise<Broker> {
956
957
  return { changed }
957
958
  }
958
959
  case "rename": {
959
- const renamed = core.rename(actorOf(s), { ...(params.endpoint !== undefined ? { endpoint: params.endpoint } : {}), handle: params.handle })
960
+ const renamed = core.rename(actorOf(s), {
961
+ ...(params.endpoint !== undefined ? { endpoint: params.endpoint } : {}),
962
+ handle: params.handle,
963
+ ...(params.take_over !== undefined ? { take_over: params.take_over } : {}),
964
+ })
960
965
  membership(renamed.endpoint, renamed.session, true, renamed.from)
966
+ if (renamed.retired) bridge?.resync()
961
967
  return renamed.endpoint
962
968
  }
963
969
  case "adopt": {
964
970
  const actor = actorOf(s)
965
- const adopted = core.adopt(
971
+ const adopted = await core.adopt(
966
972
  actor,
967
973
  { endpoint: params.endpoint, ...(params.parent !== undefined ? { parent: params.parent } : {}) },
968
- { tty: actor.kind === "endpoint" && s.data.terminal === true },
974
+ {
975
+ tty: actor.kind === "endpoint" && s.data.terminal === true,
976
+ send: (from: string, send: SendParams, origin: { link: "session" | "self" }) => {
977
+ loadPolicy()
978
+ if (policyError) throw new RelayError("policy_refused", policyError)
979
+ return judge.send(from, send, { tty: false, ...origin }, deliver)
980
+ },
981
+ },
969
982
  )
970
983
  bridge?.resync()
971
984
  return adopted
972
985
  }
986
+ case "link_accept": {
987
+ const linked = core.linkAccept(actorOf(s), { id: params.id })
988
+ bridge?.resync()
989
+ return linked
990
+ }
973
991
  case "unlink": {
974
992
  const unlinked = core.unlink(actorOf(s), params.endpoint !== undefined ? { endpoint: params.endpoint } : {})
975
993
  bridge?.resync()