@sockethub/platform-xmpp 5.0.0-alpha.10 → 5.0.0-alpha.11

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
@@ -161,7 +161,7 @@ var require_escaping = __commonJS((exports, module) => {
161
161
  }
162
162
  return local.replaceAll(/^\s+|\s+$/g, "").replaceAll("\\", String.raw`\5c`).replaceAll(" ", String.raw`\20`).replaceAll('"', String.raw`\22`).replaceAll("&", String.raw`\26`).replaceAll("'", String.raw`\27`).replaceAll("/", String.raw`\2f`).replaceAll(":", String.raw`\3a`).replaceAll("<", String.raw`\3c`).replaceAll(">", String.raw`\3e`).replaceAll("@", String.raw`\40`);
163
163
  };
164
- exports.unescape = function unescape(local) {
164
+ exports.unescape = function unescape2(local) {
165
165
  if (local === null) {
166
166
  return null;
167
167
  }
@@ -5107,9 +5107,9 @@ var require_caller = __commonJS((exports, module) => {
5107
5107
  }
5108
5108
  }
5109
5109
  module.exports = function iqCaller(...args) {
5110
- const iqCaller = new IQCaller(...args);
5111
- iqCaller.start();
5112
- return iqCaller;
5110
+ const iqCaller2 = new IQCaller(...args);
5111
+ iqCaller2.start();
5112
+ return iqCaller2;
5113
5113
  };
5114
5114
  });
5115
5115
 
@@ -5161,7 +5161,7 @@ var require_callee = __commonJS((exports, module) => {
5161
5161
  return xml("error", { type }, xml(condition, NS_STANZA));
5162
5162
  }
5163
5163
  function iqHandler(entity) {
5164
- return async function iqHandler(ctx, next) {
5164
+ return async function iqHandler2(ctx, next) {
5165
5165
  if (!isQuery(ctx))
5166
5166
  return next();
5167
5167
  const { stanza } = ctx;
@@ -7807,7 +7807,7 @@ var require_ponyfill_es2018 = __commonJS((exports, module) => {
7807
7807
  return isDOMExceptionConstructor(ctor) ? ctor : undefined;
7808
7808
  }
7809
7809
  function createPolyfill() {
7810
- const ctor = function DOMException(message, name) {
7810
+ const ctor = function DOMException2(message, name) {
7811
7811
  this.message = message || "";
7812
7812
  this.name = name || "Error";
7813
7813
  if (Error.captureStackTrace) {
@@ -11540,7 +11540,7 @@ var require_resolve2 = __commonJS((exports, module) => {
11540
11540
  entity.Socket = Transport.prototype.Socket;
11541
11541
  entity.Parser = Transport.prototype.Parser;
11542
11542
  }
11543
- module.exports = function resolve({ entity }) {
11543
+ module.exports = function resolve2({ entity }) {
11544
11544
  const _connect = entity.connect;
11545
11545
  entity.connect = async function connect(service) {
11546
11546
  if (!service || /:\/\//.test(service)) {
@@ -12410,7 +12410,7 @@ class IncomingHandlers {
12410
12410
  console.debug("close event received but session is undefined");
12411
12411
  return;
12412
12412
  }
12413
- this.session.debug("received close event with no handler specified");
12413
+ this.session.log.debug("received close event with no handler specified");
12414
12414
  if (this.session.actor && this.session.sendToClient) {
12415
12415
  this.session.sendToClient({
12416
12416
  context: "xmpp",
@@ -12418,7 +12418,7 @@ class IncomingHandlers {
12418
12418
  actor: this.session.actor,
12419
12419
  target: this.session.actor
12420
12420
  });
12421
- this.session.debug(`**** xmpp this.session.for ${this.session.actor.id} closed`);
12421
+ this.session.log.debug(`**** xmpp this.session.for ${this.session.actor.id} closed`);
12422
12422
  }
12423
12423
  if (this.session.connection && typeof this.session.connection.disconnect === "function") {
12424
12424
  this.session.connection.disconnect();
@@ -12436,7 +12436,7 @@ class IncomingHandlers {
12436
12436
  }
12437
12437
  });
12438
12438
  } catch (e2) {
12439
- this.session.debug("*** XMPP ERROR (rl catch): ", e2);
12439
+ this.session.log.debug("*** XMPP ERROR (rl catch): ", e2);
12440
12440
  }
12441
12441
  }
12442
12442
  presence(stanza) {
@@ -12460,11 +12460,11 @@ class IncomingHandlers {
12460
12460
  } else {
12461
12461
  obj.actor.name = stanza.attrs.from.split("/")[1];
12462
12462
  }
12463
- this.session.debug(`received contact presence update from ${stanza.attrs.from}`);
12463
+ this.session.log.debug(`received contact presence update from ${stanza.attrs.from}`);
12464
12464
  this.session.sendToClient(obj);
12465
12465
  }
12466
12466
  subscribe(to, from, name) {
12467
- this.session.debug(`received subscribe request from ${from}`);
12467
+ this.session.log.debug(`received subscribe request from ${from}`);
12468
12468
  const actor = { id: from, type: "person" };
12469
12469
  if (name) {
12470
12470
  actor.name = name;
@@ -12576,7 +12576,7 @@ class IncomingHandlers {
12576
12576
  }
12577
12577
  }
12578
12578
  online() {
12579
- this.session.debug("online");
12579
+ this.session.log.debug("online");
12580
12580
  }
12581
12581
  stanza(stanza) {
12582
12582
  if (stanza.attrs.type === "error") {
@@ -12587,7 +12587,7 @@ class IncomingHandlers {
12587
12587
  this.presence(stanza);
12588
12588
  } else if (stanza.is("iq")) {
12589
12589
  if (stanza.attrs.id === "muc_id" && stanza.attrs.type === "result") {
12590
- this.session.debug("got room attendance list");
12590
+ this.session.log.debug("got room attendance list");
12591
12591
  return this.notifyRoomAttendance(stanza);
12592
12592
  }
12593
12593
  const query = stanza.getChild("query");
@@ -12597,7 +12597,7 @@ class IncomingHandlers {
12597
12597
  if (!entries.hasOwn(e2)) {
12598
12598
  continue;
12599
12599
  }
12600
- this.session.debug("STANZA ATTRS: ", entries[e2].attrs);
12600
+ this.session.log.debug("STANZA ATTRS: ", entries[e2].attrs);
12601
12601
  if (entries[e2].attrs.subscription === "both") {
12602
12602
  this.session.sendToClient({
12603
12603
  context: "xmpp",
@@ -12634,7 +12634,7 @@ class IncomingHandlers {
12634
12634
  }
12635
12635
  }
12636
12636
  } else {
12637
- this.session.debug(`got XMPP unknown stanza... ${stanza}`);
12637
+ this.session.log.debug(`got XMPP unknown stanza... ${stanza}`);
12638
12638
  }
12639
12639
  }
12640
12640
  }
@@ -12642,7 +12642,7 @@ class IncomingHandlers {
12642
12642
  var package_default = {
12643
12643
  name: "@sockethub/platform-xmpp",
12644
12644
  description: "A sockethub platform module implementing XMPP functionality",
12645
- version: "5.0.0-alpha.10",
12645
+ version: "5.0.0-alpha.11",
12646
12646
  private: false,
12647
12647
  type: "module",
12648
12648
  author: "Nick Jennings <nick@silverbucket.net>",
@@ -12680,26 +12680,27 @@ var package_default = {
12680
12680
  scripts: {
12681
12681
  build: "bun build src/index.js --outdir dist --target node --format esm --sourcemap=external",
12682
12682
  clean: "rm -rf dist",
12683
+ "clean:deps": "rm -rf node_modules",
12683
12684
  doc: "jsdoc2md --no-gfm --heading-depth 1 src/index.js > API.md"
12684
12685
  },
12685
12686
  dependencies: {
12686
12687
  "@xmpp/client": "^0.13.6"
12687
12688
  },
12688
12689
  devDependencies: {
12689
- "@sockethub/schemas": "^3.0.0-alpha.10",
12690
+ "@sockethub/schemas": "^3.0.0-alpha.11",
12690
12691
  "@xmpp/xml": "^0.13.2",
12691
12692
  "jsdoc-to-markdown": "^8.0.3",
12692
12693
  sinon: "^17.0.2"
12693
12694
  },
12694
12695
  peerDependencies: {
12695
- "@sockethub/server": "^5.0.0-alpha.10"
12696
+ "@sockethub/server": "^5.0.0-alpha.11"
12696
12697
  },
12697
12698
  peerDependenciesMeta: {
12698
12699
  "@sockethub/server": {
12699
12700
  optional: true
12700
12701
  }
12701
12702
  },
12702
- gitHead: "2dc0a34eab5c62afed5a336fc89a8b0318c8b5d4"
12703
+ gitHead: "f7fb4fa2599da1def438c710ce81a41b6cfee8a7"
12703
12704
  };
12704
12705
 
12705
12706
  // src/schema.js
@@ -12787,10 +12788,10 @@ class XMPP {
12787
12788
  this.config = {
12788
12789
  connectTimeoutMs: 1e4,
12789
12790
  persist: true,
12790
- initialized: false,
12791
12791
  requireCredentials: ["connect"]
12792
12792
  };
12793
- this.debug = session.debug;
12793
+ this.__initialized = false;
12794
+ this.log = session.log;
12794
12795
  this.sendToClient = session.sendToClient;
12795
12796
  this.createClient();
12796
12797
  this.createXml();
@@ -12802,13 +12803,13 @@ class XMPP {
12802
12803
  this.__xml = $xml;
12803
12804
  }
12804
12805
  __markDisconnected(stopReconnection = false) {
12805
- this.debug(`marking client as disconnected for ${this.id}`);
12806
+ this.log.debug(`marking client as disconnected for ${this.id}`);
12806
12807
  if (stopReconnection && this.__client) {
12807
- this.debug(`stopping automatic reconnection for ${this.id}`);
12808
+ this.log.debug(`stopping automatic reconnection for ${this.id}`);
12808
12809
  this.__client.stop();
12809
12810
  }
12810
12811
  this.__client = undefined;
12811
- this.config.initialized = false;
12812
+ this.__initialized = false;
12812
12813
  }
12813
12814
  __classifyError(err) {
12814
12815
  const errorString = err.toString();
@@ -12836,44 +12837,57 @@ class XMPP {
12836
12837
  try {
12837
12838
  return this.__client.socket && this.__client.socket.writable !== false && this.__client.status === "online";
12838
12839
  } catch (err) {
12839
- this.debug("Error checking client connection status:", err);
12840
+ this.log.debug("Error checking client connection status:", err);
12840
12841
  return false;
12841
12842
  }
12842
12843
  }
12843
12844
  get schema() {
12844
12845
  return PlatformSchema;
12845
12846
  }
12847
+ isInitialized() {
12848
+ return this.__initialized;
12849
+ }
12846
12850
  connect(job, credentials, done) {
12847
12851
  if (this.__isClientConnected()) {
12848
- this.debug(`client connection already exists for ${job.actor.id}`);
12849
- this.config.initialized = true;
12852
+ this.log.debug(`client connection already exists for ${job.actor.id}`);
12853
+ this.__initialized = true;
12850
12854
  return done();
12851
12855
  }
12852
- this.debug(`connect() called for ${job.actor.id}`);
12856
+ this.log.debug(`connect() called for ${job.actor.id}`);
12853
12857
  const xmppCreds = utils.buildXmppCredentials(credentials);
12854
- this.debug(`building XMPP credentials for ${job.actor.id}:`, JSON.stringify({
12858
+ this.log.debug(`building XMPP credentials for ${job.actor.id}:`, JSON.stringify({
12855
12859
  service: xmppCreds.service,
12856
12860
  username: xmppCreds.username,
12857
12861
  resource: xmppCreds.resource,
12858
12862
  timeout: this.config.connectTimeoutMs
12859
12863
  }));
12860
- this.debug(`creating XMPP client for ${job.actor.id}`);
12864
+ this.log.debug(`creating XMPP client for ${job.actor.id}`);
12861
12865
  try {
12862
12866
  this.__client = this.__clientConstructor({
12863
12867
  ...xmppCreds,
12864
12868
  ...{ timeout: this.config.connectTimeoutMs, tls: false }
12865
12869
  });
12866
- this.debug(`XMPP client created successfully for ${job.actor.id}`);
12870
+ this.log.debug(`XMPP client created successfully for ${job.actor.id}`);
12867
12871
  } catch (err) {
12868
- this.debug(`XMPP client creation failed for ${job.actor.id}:`, err);
12872
+ this.log.debug(`XMPP client creation failed for ${job.actor.id}:`, err);
12869
12873
  return done(`client creation failed: ${err.message}`);
12870
12874
  }
12871
12875
  this.__client.on("offline", () => {
12872
- this.debug(`offline event received for ${job.actor.id}`);
12873
- this.__markDisconnected();
12876
+ this.log.debug(`offline event received for ${job.actor.id}`);
12877
+ if (!this.__initialized) {
12878
+ this.log.debug(`offline during initial connection for ${job.actor.id}`);
12879
+ this.__markDisconnected();
12880
+ } else {
12881
+ this.log.debug(`offline after successful connection for ${job.actor.id}, will auto-reconnect`);
12882
+ }
12874
12883
  });
12875
12884
  this.__client.on("error", (err) => {
12876
- this.debug(`network error event for ${job.actor.id}:${err.toString()}`);
12885
+ if (err instanceof TypeError || err instanceof ReferenceError || err instanceof SyntaxError) {
12886
+ this.log.error(`FATAL: Internal code error in XMPP platform: ${err.toString()}`);
12887
+ this.log.error(err.stack);
12888
+ process.exit(1);
12889
+ }
12890
+ this.log.debug(`network error event for ${job.actor.id}:${err.toString()}`);
12877
12891
  const errorType = this.__classifyError(err);
12878
12892
  const as = {
12879
12893
  context: "xmpp",
@@ -12881,7 +12895,6 @@ class XMPP {
12881
12895
  actor: { id: job.actor.id }
12882
12896
  };
12883
12897
  if (errorType === "RECOVERABLE") {
12884
- this.__markDisconnected(false);
12885
12898
  as.error = `Connection lost: ${err.toString()}. Attempting automatic reconnection...`;
12886
12899
  as.object = {
12887
12900
  type: "connect",
@@ -12900,19 +12913,19 @@ class XMPP {
12900
12913
  this.sendToClient(as);
12901
12914
  });
12902
12915
  this.__client.on("online", () => {
12903
- this.debug(`online event received for ${job.actor.id}`);
12916
+ this.log.debug(`online event received for ${job.actor.id}`);
12904
12917
  });
12905
- this.debug(`starting XMPP client connection for ${job.actor.id}`);
12918
+ this.log.debug(`starting XMPP client connection for ${job.actor.id}`);
12906
12919
  const startTime = Date.now();
12907
12920
  this.__client.start().then(() => {
12908
12921
  const duration = Date.now() - startTime;
12909
- this.debug(`connection successful for ${job.actor.id} after ${duration}ms`);
12910
- this.config.initialized = true;
12922
+ this.log.debug(`connection successful for ${job.actor.id} after ${duration}ms`);
12923
+ this.__initialized = true;
12911
12924
  this.__registerHandlers();
12912
12925
  return done();
12913
12926
  }).catch((err) => {
12914
12927
  const duration = Date.now() - startTime;
12915
- this.debug(`connection failed for ${job.actor.id} after ${duration}ms:`, {
12928
+ this.log.debug(`connection failed for ${job.actor.id} after ${duration}ms:`, {
12916
12929
  error: err,
12917
12930
  message: err?.message,
12918
12931
  code: err?.code,
@@ -12923,7 +12936,7 @@ class XMPP {
12923
12936
  });
12924
12937
  }
12925
12938
  async join(job, done) {
12926
- this.debug(`sending join from ${job.actor.id} to ` + `${job.target.id}/${job.actor.name}`);
12939
+ this.log.debug(`sending join from ${job.actor.id} to ` + `${job.target.id}/${job.actor.name}`);
12927
12940
  const id = job.target.id.split("/")[0];
12928
12941
  const presence = this.__xml("presence", {
12929
12942
  from: job.actor.id,
@@ -12932,7 +12945,7 @@ class XMPP {
12932
12945
  return this.__client.send(presence).then(done).catch(done);
12933
12946
  }
12934
12947
  leave(job, done) {
12935
- this.debug(`sending leave from ${job.actor.id} to ` + `${job.target.id}/${job.actor.name}`);
12948
+ this.log.debug(`sending leave from ${job.actor.id} to ` + `${job.target.id}/${job.actor.name}`);
12936
12949
  const id = job.target.id.split("/")[0];
12937
12950
  this.__client.send(this.__xml("presence", {
12938
12951
  from: job.actor.id,
@@ -12941,7 +12954,7 @@ class XMPP {
12941
12954
  })).then(done);
12942
12955
  }
12943
12956
  send(job, done) {
12944
- this.debug(`send() called for ${job.actor.id}`);
12957
+ this.log.debug(`send() called for ${job.actor.id}`);
12945
12958
  const message = this.__xml("message", {
12946
12959
  type: job.target.type === "room" ? "groupchat" : "chat",
12947
12960
  to: job.target.id,
@@ -12953,7 +12966,7 @@ class XMPP {
12953
12966
  this.__client.send(message).then(done);
12954
12967
  }
12955
12968
  update(job, done) {
12956
- this.debug(`update() called for ${job.actor.id}`);
12969
+ this.log.debug(`update() called for ${job.actor.id}`);
12957
12970
  const props = {};
12958
12971
  const show = {};
12959
12972
  const status = {};
@@ -12966,35 +12979,35 @@ class XMPP {
12966
12979
  if (job.object.content) {
12967
12980
  status.status = job.object.content;
12968
12981
  }
12969
- this.debug(`setting presence: ${job.object.presence}`);
12982
+ this.log.debug(`setting presence: ${job.object.presence}`);
12970
12983
  this.__client.send(this.__xml("presence", props, show, status)).then(done);
12971
12984
  } else {
12972
12985
  done(`unknown update object type: ${job.object.type}`);
12973
12986
  }
12974
12987
  }
12975
12988
  "request-friend"(job, done) {
12976
- this.debug(`request-friend() called for ${job.actor.id}`);
12989
+ this.log.debug(`request-friend() called for ${job.actor.id}`);
12977
12990
  this.__client.send(this.__xml("presence", {
12978
12991
  type: "subscribe",
12979
12992
  to: job.target.id
12980
12993
  })).then(done);
12981
12994
  }
12982
12995
  "remove-friend"(job, done) {
12983
- this.debug(`remove-friend() called for ${job.actor.id}`);
12996
+ this.log.debug(`remove-friend() called for ${job.actor.id}`);
12984
12997
  this.__client.send(this.__xml("presence", {
12985
12998
  type: "unsubscribe",
12986
12999
  to: job.target.id
12987
13000
  })).then(done);
12988
13001
  }
12989
13002
  "make-friend"(job, done) {
12990
- this.debug(`make-friend() called for ${job.actor.id}`);
13003
+ this.log.debug(`make-friend() called for ${job.actor.id}`);
12991
13004
  this.__client.send(this.__xml("presence", {
12992
13005
  type: "subscribe",
12993
13006
  to: job.target.id
12994
13007
  })).then(done);
12995
13008
  }
12996
13009
  query(job, done) {
12997
- this.debug(`sending query from ${job.actor.id} for ${job.target.id}`);
13010
+ this.log.debug(`sending query from ${job.actor.id} for ${job.target.id}`);
12998
13011
  this.__client.send(this.__xml("iq", {
12999
13012
  id: "muc_id",
13000
13013
  type: "get",
@@ -13005,12 +13018,12 @@ class XMPP {
13005
13018
  }))).then(done);
13006
13019
  }
13007
13020
  disconnect(job, done) {
13008
- this.debug("disconnecting");
13021
+ this.log.debug("disconnecting");
13009
13022
  this.cleanup(done);
13010
13023
  }
13011
13024
  cleanup(done) {
13012
- this.debug("cleanup");
13013
- this.config.initialized = false;
13025
+ this.log.debug("cleanup");
13026
+ this.__initialized = false;
13014
13027
  this.__client.stop();
13015
13028
  done();
13016
13029
  }
@@ -13026,4 +13039,4 @@ export {
13026
13039
  XMPP as default
13027
13040
  };
13028
13041
 
13029
- //# debugId=4DA52DDAE3F63AEC64756E2164756E21
13042
+ //# debugId=C3F55E34F6FAE0AE64756E2164756E21