@sockethub/platform-irc 4.0.0-alpha.12 → 4.0.0-alpha.13

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
@@ -4574,6 +4574,7 @@ var require_limitLength = __commonJS((exports) => {
4574
4574
  var require_pattern = __commonJS((exports) => {
4575
4575
  Object.defineProperty(exports, "__esModule", { value: true });
4576
4576
  var code_1 = require_code2();
4577
+ var util_1 = require_util();
4577
4578
  var codegen_1 = require_codegen();
4578
4579
  var error = {
4579
4580
  message: ({ schemaCode }) => (0, codegen_1.str)`must match pattern "${schemaCode}"`,
@@ -4586,10 +4587,18 @@ var require_pattern = __commonJS((exports) => {
4586
4587
  $data: true,
4587
4588
  error,
4588
4589
  code(cxt) {
4589
- const { data, $data, schema, schemaCode, it } = cxt;
4590
+ const { gen, data, $data, schema, schemaCode, it } = cxt;
4590
4591
  const u = it.opts.unicodeRegExp ? "u" : "";
4591
- const regExp = $data ? (0, codegen_1._)`(new RegExp(${schemaCode}, ${u}))` : (0, code_1.usePattern)(cxt, schema);
4592
- cxt.fail$data((0, codegen_1._)`!${regExp}.test(${data})`);
4592
+ if ($data) {
4593
+ const { regExp } = it.opts.code;
4594
+ const regExpCode = regExp.code === "new RegExp" ? (0, codegen_1._)`new RegExp` : (0, util_1.useFunc)(gen, regExp);
4595
+ const valid = gen.let("valid");
4596
+ gen.try(() => gen.assign(valid, (0, codegen_1._)`${regExpCode}(${schemaCode}, ${u}).test(${data})`), () => gen.assign(valid, false));
4597
+ cxt.fail$data((0, codegen_1._)`!${valid}`);
4598
+ } else {
4599
+ const regExp = (0, code_1.usePattern)(cxt, schema);
4600
+ cxt.fail$data((0, codegen_1._)`!${regExp}.test(${data})`);
4601
+ }
4593
4602
  }
4594
4603
  };
4595
4604
  exports.default = def;
@@ -15749,22 +15758,22 @@ var require_ajv_formats_draft2019 = __commonJS((exports, module) => {
15749
15758
  };
15750
15759
  });
15751
15760
 
15752
- // ../../node_modules/r-result/result.js
15761
+ // ../../node_modules/irc-socket-sasl/result.js
15753
15762
  var require_result = __commonJS((exports, module) => {
15754
15763
  var inspect = __require("util").inspect;
15755
15764
  var Ok = function(t) {
15756
- const Result = Object.create(methods);
15765
+ const Result = Object.create(resultMethods);
15757
15766
  Result.is_ok = true;
15758
15767
  Result.value = t;
15759
15768
  return Result;
15760
15769
  };
15761
15770
  var Fail = function(f) {
15762
- const Result = Object.create(methods);
15771
+ const Result = Object.create(resultMethods);
15763
15772
  Result.is_ok = false;
15764
15773
  Result.value = f;
15765
15774
  return Result;
15766
15775
  };
15767
- var methods = {
15776
+ var resultMethods = {
15768
15777
  ok: function(errorMessage) {
15769
15778
  if (this.is_ok) {
15770
15779
  return this.value;
@@ -15899,29 +15908,13 @@ var require_result = __commonJS((exports, module) => {
15899
15908
  Ok,
15900
15909
  Fail
15901
15910
  };
15902
- var methodToFunction = function(method) {
15903
- return function() {
15904
- var context = arguments[0];
15905
- var args = Array.prototype.slice.call(arguments, 1);
15906
- return method.apply(context, args);
15907
- };
15908
- };
15909
- Object.keys(methods).forEach(function(key) {
15910
- if (key === "inspect") {
15911
- return;
15912
- }
15913
- var method = methods[key];
15914
- module.exports[key] = methodToFunction(method);
15915
- });
15916
15911
  });
15917
15912
 
15918
15913
  // ../../node_modules/irc-socket-sasl/irc-socket.js
15919
15914
  var require_irc_socket = __commonJS((exports, module) => {
15920
15915
  var EventEmitter = __require("events").EventEmitter;
15921
15916
  var format = __require("util").format;
15922
- var rresult = require_result();
15923
- var Ok = rresult.Ok;
15924
- var Fail = rresult.Fail;
15917
+ var { Ok, Fail } = require_result();
15925
15918
  var includes = function(array, value) {
15926
15919
  return array.indexOf(value) !== -1;
15927
15920
  };
@@ -15934,13 +15927,20 @@ var require_irc_socket = __commonJS((exports, module) => {
15934
15927
  var endsWith = function(string, postfix) {
15935
15928
  return string.lastIndexOf(postfix) === string.length - postfix.length;
15936
15929
  };
15930
+ var encodeSaslCredential = function(mechanism, username, secret) {
15931
+ if (mechanism === "OAUTHBEARER") {
15932
+ return Buffer.from("n,,\x01auth=Bearer " + secret + "\x01\x01").toString("base64");
15933
+ }
15934
+ return Buffer.from(username + "\x00" + username + "\x00" + secret).toString("base64");
15935
+ };
15937
15936
  var failures = {
15938
15937
  killed: "killed",
15939
15938
  nicknamesUnavailable: "nicknames unavailable",
15940
15939
  badProxyConfiguration: "bad proxy configuration",
15941
15940
  missingRequiredCapabilities: "missing required capabilities",
15942
15941
  badPassword: "bad password",
15943
- socketEnded: "socket ended"
15942
+ socketEnded: "socket ended",
15943
+ saslAuthenticationFailed: "sasl authentication failed"
15944
15944
  };
15945
15945
 
15946
15946
  class IrcSocket extends EventEmitter {
@@ -15965,12 +15965,16 @@ var require_irc_socket = __commonJS((exports, module) => {
15965
15965
  if (config.saslPassword) {
15966
15966
  this.saslUsername = config.saslUsername || config.username;
15967
15967
  this.saslPassword = config.saslPassword;
15968
+ this.saslMechanism = (config.saslMechanism || "PLAIN").toUpperCase();
15969
+ if (this.saslMechanism !== "PLAIN" && this.saslMechanism !== "OAUTHBEARER") {
15970
+ throw new Error("Unsupported SASL mechanism: " + config.saslMechanism);
15971
+ }
15968
15972
  }
15969
15973
  this.username = config.username;
15970
15974
  this.realname = config.realname;
15971
15975
  this.nicknames = config.nicknames.slice();
15972
15976
  this.timeout = config.timeout || 5 * 60 * 1000;
15973
- this.connectOptions = typeof config.connectOptions === "object" ? Object.create(config.connectOptions) : {};
15977
+ this.connectOptions = typeof config.connectOptions === "object" && config.connectOptions !== null ? { ...config.connectOptions } : {};
15974
15978
  this.connectOptions.port = config.port || 6667;
15975
15979
  this.connectOptions.host = config.server;
15976
15980
  this.on("data", function(line) {
@@ -16017,6 +16021,8 @@ var require_irc_socket = __commonJS((exports, module) => {
16017
16021
  this.emit("connect");
16018
16022
  timeout = setTimeout(onSilence, timeoutPeriod);
16019
16023
  let serverCapabilities, acknowledgedCapabilities, sentRequests, respondedRequests, allRequestsSent, nickname;
16024
+ let saslResponseSent = false;
16025
+ let saslChallenge = "";
16020
16026
  if (this.capabilities) {
16021
16027
  this.capabilities.requires = this.capabilities.requires || [];
16022
16028
  this.capabilities.wants = this.capabilities.wants || [];
@@ -16086,7 +16092,7 @@ var require_irc_socket = __commonJS((exports, module) => {
16086
16092
  acknowledgedCapabilities.push(capability);
16087
16093
  }
16088
16094
  if (acknowledgedCapabilities.includes("sasl")) {
16089
- this.raw(["AUTHENTICATE", "PLAIN"]);
16095
+ this.raw(["AUTHENTICATE", this.saslMechanism || "PLAIN"]);
16090
16096
  }
16091
16097
  }
16092
16098
  if (sentRequests === respondedRequests) {
@@ -16100,13 +16106,48 @@ var require_irc_socket = __commonJS((exports, module) => {
16100
16106
  if (endsWith(line, "Login unsuccessful")) {
16101
16107
  this.resolvePromise(Fail(failures.badPassword));
16102
16108
  }
16103
- } else if (parts[0] === "AUTHENTICATE") {
16104
- if (parts[1] === "+") {
16105
- const encPW = Buffer.from(this.saslUsername + "\x00" + this.saslUsername + "\x00" + this.saslPassword).toString("base64");
16106
- this.raw(["AUTHENTICATE", encPW]);
16109
+ } else if (parts[0] === "AUTHENTICATE" || numeric === "AUTHENTICATE") {
16110
+ const chunkSize = 400;
16111
+ const authArg = numeric === "AUTHENTICATE" ? parts[2] : parts[1];
16112
+ if (!saslResponseSent) {
16113
+ if (authArg !== "+") {
16114
+ return;
16115
+ }
16116
+ const payload = encodeSaslCredential(this.saslMechanism, this.saslUsername, this.saslPassword);
16117
+ if (payload.length === 0) {
16118
+ this.raw(["AUTHENTICATE", "+"]);
16119
+ } else {
16120
+ for (let i = 0;i < payload.length; i += chunkSize) {
16121
+ this.raw(["AUTHENTICATE", payload.slice(i, i + chunkSize)]);
16122
+ }
16123
+ if (payload.length % chunkSize === 0) {
16124
+ this.raw(["AUTHENTICATE", "+"]);
16125
+ }
16126
+ }
16127
+ saslResponseSent = true;
16128
+ } else {
16129
+ let challengeComplete = false;
16130
+ if (authArg === "+") {
16131
+ challengeComplete = true;
16132
+ } else {
16133
+ saslChallenge += authArg;
16134
+ if (authArg.length < chunkSize) {
16135
+ challengeComplete = true;
16136
+ }
16137
+ }
16138
+ if (challengeComplete) {
16139
+ saslChallenge = "";
16140
+ if (this.saslMechanism === "OAUTHBEARER") {
16141
+ this.raw(["AUTHENTICATE", "AQ=="]);
16142
+ }
16143
+ }
16107
16144
  }
16108
16145
  } else if (numeric === "903") {
16109
16146
  this.raw("CAP END");
16147
+ } else if (numeric === "902" || numeric === "904" || numeric === "905" || numeric === "906" || numeric === "907") {
16148
+ this.raw("QUIT");
16149
+ this.resolvePromise(Fail(failures.saslAuthenticationFailed));
16150
+ return;
16110
16151
  } else if (numeric === "001") {
16111
16152
  this.status = "running";
16112
16153
  const data = {
@@ -16251,7 +16292,7 @@ class ASEmitter {
16251
16292
  }
16252
16293
  emitEvent(code, asObject) {
16253
16294
  if (typeof asObject === "object" && !asObject.published) {
16254
- asObject.published = `${Date.now()}`;
16295
+ asObject.published = new Date().toISOString();
16255
16296
  }
16256
16297
  this.events.emit(code, asObject);
16257
16298
  }
@@ -16698,7 +16739,7 @@ class IrcToActivityStreams {
16698
16739
  }
16699
16740
  };
16700
16741
  break;
16701
- case TOPIC_SET_BY:
16742
+ case TOPIC_SET_BY: {
16702
16743
  if (!this.__buffer[TOPIC_IS]) {
16703
16744
  break;
16704
16745
  }
@@ -16708,10 +16749,14 @@ class IrcToActivityStreams {
16708
16749
  id: `${nick}@${this.server}`,
16709
16750
  name: nick
16710
16751
  };
16711
- this.__buffer[TOPIC_IS].published = msg[0];
16752
+ const topicSetEpochSeconds = Number.parseInt(msg[0], 10);
16753
+ if (Number.isFinite(topicSetEpochSeconds)) {
16754
+ this.__buffer[TOPIC_IS].published = new Date(topicSetEpochSeconds * 1000).toISOString();
16755
+ }
16712
16756
  ase.emitEvent(EVENT_INCOMING2, this.__buffer[TOPIC_IS]);
16713
16757
  delete this.__buffer[TOPIC_IS];
16714
16758
  break;
16759
+ }
16715
16760
  case WHO:
16716
16761
  case WHO_OLD:
16717
16762
  nick = msg[3].length <= 2 ? msg[2] : msg[3];
@@ -16731,6 +16776,7 @@ class IrcToActivityStreams {
16731
16776
  // ../schemas/src/context.ts
16732
16777
  var AS2_BASE_CONTEXT_URL = "https://www.w3.org/ns/activitystreams";
16733
16778
  var SOCKETHUB_BASE_CONTEXT_URL = "https://sockethub.org/ns/context/v1.jsonld";
16779
+ var PLATFORM_CONTEXT_PREFIX = "https://sockethub.org/ns/context/platform/";
16734
16780
  var ERROR_PLATFORM_ID = "error";
16735
16781
  var ERROR_PLATFORM_CONTEXT_URL = "https://sockethub.org/ns/context/platform/error/v1.jsonld";
16736
16782
  var INTERNAL_PLATFORM_ID = "sockethub:internal";
@@ -16738,12 +16784,9 @@ var INTERNAL_PLATFORM_CONTEXT_URL = "https://sockethub.org/ns/context/platform/s
16738
16784
  var platformContextToPlatformId = new Map;
16739
16785
  var platformContextToSchemaId = new Map;
16740
16786
  var platformContextToCredentialsSchemaId = new Map;
16741
- function buildCanonicalContext(platformContextUrl) {
16742
- return [
16743
- AS2_BASE_CONTEXT_URL,
16744
- SOCKETHUB_BASE_CONTEXT_URL,
16745
- platformContextUrl
16746
- ];
16787
+ function buildCanonicalContext(platform) {
16788
+ const platformUrl = platform.startsWith("https://") ? platform : `${PLATFORM_CONTEXT_PREFIX}${platform}/v1.jsonld`;
16789
+ return [AS2_BASE_CONTEXT_URL, SOCKETHUB_BASE_CONTEXT_URL, platformUrl];
16747
16790
  }
16748
16791
  function registerPlatformContext(platformId, platformContextUrl, schemaId, credentialsSchemaId) {
16749
16792
  platformContextToPlatformId.set(platformContextUrl, platformId);
@@ -16752,18 +16795,7 @@ function registerPlatformContext(platformId, platformContextUrl, schemaId, crede
16752
16795
  }
16753
16796
 
16754
16797
  // ../schemas/src/helpers/objects.ts
16755
- var validObjectRefs = [];
16756
- var validObjectDefs = {};
16757
16798
  var ObjectTypesSchema = {
16758
- credentials: {
16759
- required: ["type"],
16760
- additionalProperties: true,
16761
- properties: {
16762
- type: {
16763
- enum: ["credentials"]
16764
- }
16765
- }
16766
- },
16767
16799
  feed: {
16768
16800
  required: ["id", "type"],
16769
16801
  additionalProperties: true,
@@ -16789,36 +16821,6 @@ var ObjectTypesSchema = {
16789
16821
  }
16790
16822
  }
16791
16823
  },
16792
- message: {
16793
- required: ["type", "content"],
16794
- additionalProperties: true,
16795
- properties: {
16796
- type: {
16797
- enum: ["message"]
16798
- },
16799
- id: {
16800
- type: "string"
16801
- },
16802
- name: {
16803
- type: "string"
16804
- },
16805
- content: {
16806
- type: "string"
16807
- }
16808
- }
16809
- },
16810
- me: {
16811
- required: ["type", "content"],
16812
- additionalProperties: true,
16813
- properties: {
16814
- type: {
16815
- enum: ["me"]
16816
- },
16817
- content: {
16818
- type: "string"
16819
- }
16820
- }
16821
- },
16822
16824
  person: {
16823
16825
  required: ["id", "type"],
16824
16826
  additionalProperties: true,
@@ -16895,71 +16897,6 @@ var ObjectTypesSchema = {
16895
16897
  }
16896
16898
  }
16897
16899
  },
16898
- attendance: {
16899
- required: ["type"],
16900
- additionalProperties: false,
16901
- properties: {
16902
- type: {
16903
- enum: ["attendance"]
16904
- },
16905
- members: {
16906
- type: "array",
16907
- items: {
16908
- type: "string"
16909
- }
16910
- }
16911
- }
16912
- },
16913
- presence: {
16914
- required: ["type"],
16915
- additionalProperties: false,
16916
- properties: {
16917
- type: {
16918
- enum: ["presence"]
16919
- },
16920
- presence: {
16921
- enum: ["away", "chat", "dnd", "xa", "offline", "online"]
16922
- },
16923
- role: {
16924
- enum: ["owner", "member", "participant", "admin"]
16925
- },
16926
- content: {
16927
- type: "string"
16928
- }
16929
- }
16930
- },
16931
- relationship: {
16932
- required: ["type", "relationship"],
16933
- additionalProperties: false,
16934
- properties: {
16935
- type: {
16936
- enum: ["relationship"]
16937
- },
16938
- relationship: {
16939
- enum: ["role"]
16940
- },
16941
- subject: {
16942
- type: "object",
16943
- oneOf: [{ $ref: "#/definitions/type/presence" }]
16944
- },
16945
- object: {
16946
- type: "object",
16947
- oneOf: validObjectRefs
16948
- }
16949
- }
16950
- },
16951
- topic: {
16952
- required: ["type"],
16953
- additionalProperties: false,
16954
- properties: {
16955
- type: {
16956
- enum: ["topic"]
16957
- },
16958
- content: {
16959
- type: "string"
16960
- }
16961
- }
16962
- },
16963
16900
  address: {
16964
16901
  required: ["type"],
16965
16902
  additionalProperties: false,
@@ -16968,18 +16905,6 @@ var ObjectTypesSchema = {
16968
16905
  enum: ["address"]
16969
16906
  }
16970
16907
  }
16971
- },
16972
- heartbeat: {
16973
- required: ["type", "timestamp"],
16974
- additionalProperties: false,
16975
- properties: {
16976
- type: {
16977
- enum: ["heartbeat"]
16978
- },
16979
- timestamp: {
16980
- type: "number"
16981
- }
16982
- }
16983
16908
  }
16984
16909
  };
16985
16910
  var ObjectTypesList = Object.keys(ObjectTypesSchema);
@@ -17006,36 +16931,8 @@ var validActorRefs = ActorTypesList.map((type) => ({
17006
16931
  var validTargetRefs = TargetTypesList.map((type) => ({
17007
16932
  $ref: `#/definitions/type/${type}`
17008
16933
  }));
17009
- for (const type of ObjectTypesList) {
17010
- if (type === "credentials") {
17011
- continue;
17012
- }
17013
- validObjectRefs.push({ $ref: `#/definitions/type/${type}` });
17014
- validObjectDefs[type] = ObjectTypesSchema[type];
17015
- }
17016
-
17017
- // ../schemas/src/schemas/activity-object.ts
17018
- var ActivityObjectSchema = {
17019
- $id: "https://sockethub.org/schemas/v/activity-object.json",
17020
- description: "Schema for Sockethub Activity Objects",
17021
- type: "object",
17022
- required: ["object"],
17023
- properties: {
17024
- object: {
17025
- type: "object",
17026
- oneOf: validObjectRefs
17027
- }
17028
- },
17029
- definitions: {
17030
- type: validObjectDefs
17031
- }
17032
- };
17033
16934
 
17034
16935
  // ../schemas/src/schemas/activity-stream.ts
17035
- var validObjectRefs2 = [];
17036
- for (const type of ObjectTypesList) {
17037
- validObjectRefs2.push({ $ref: `#/definitions/type/${type}` });
17038
- }
17039
16936
  var contextSchema = {
17040
16937
  type: "array",
17041
16938
  minItems: 3,
@@ -17064,6 +16961,7 @@ var ActivityStreamSchema = {
17064
16961
  description: "Schema for Sockethub Activity Streams",
17065
16962
  type: "object",
17066
16963
  required: ["@context", "type", "actor"],
16964
+ additionalProperties: false,
17067
16965
  properties: {
17068
16966
  "@context": contextSchema,
17069
16967
  id: {
@@ -17079,8 +16977,7 @@ var ActivityStreamSchema = {
17079
16977
  oneOf: validTargetRefs
17080
16978
  },
17081
16979
  object: {
17082
- type: "object",
17083
- oneOf: validObjectRefs2
16980
+ type: "object"
17084
16981
  },
17085
16982
  published: {
17086
16983
  type: "string",
@@ -17092,226 +16989,6 @@ var ActivityStreamSchema = {
17092
16989
  }
17093
16990
  };
17094
16991
 
17095
- // ../schemas/src/schemas/sockethub-config.ts
17096
- var connectConfigPlatforms = {
17097
- connectTimeoutMs: {
17098
- type: "number"
17099
- }
17100
- };
17101
- var SockethubConfigSchema = {
17102
- $id: "https://sockethub.org/schemas/v/sockethub-config.json",
17103
- description: "Sockethub Config Schema",
17104
- type: "object",
17105
- required: ["platforms"],
17106
- additionalProperties: false,
17107
- properties: {
17108
- $schema: {
17109
- type: "string"
17110
- },
17111
- examples: {
17112
- type: "boolean",
17113
- default: true
17114
- },
17115
- logging: {
17116
- type: "object",
17117
- additionalProperties: false,
17118
- properties: {
17119
- level: {
17120
- type: "string",
17121
- enum: ["error", "warn", "info", "debug"],
17122
- default: "info"
17123
- },
17124
- fileLevel: {
17125
- type: "string",
17126
- enum: ["error", "warn", "info", "debug"],
17127
- default: "debug"
17128
- },
17129
- file: {
17130
- type: "string",
17131
- default: "sockethub.log"
17132
- }
17133
- }
17134
- },
17135
- packageConfig: {
17136
- type: "object",
17137
- properties: {
17138
- "@sockethub/activity-streams": {
17139
- type: "object",
17140
- additionalProperties: false,
17141
- properties: {
17142
- specialObjs: {
17143
- type: "array",
17144
- items: {
17145
- type: "string"
17146
- },
17147
- default: ["credentials"]
17148
- },
17149
- failOnUnknownObjectProperties: {
17150
- type: "boolean",
17151
- default: true
17152
- }
17153
- }
17154
- },
17155
- "@sockethub/platform-dummy": {
17156
- type: "object",
17157
- additionalProperties: false,
17158
- properties: {
17159
- greeting: {
17160
- type: "string",
17161
- default: "Hello"
17162
- }
17163
- }
17164
- },
17165
- "@sockethub/platform-feeds": {
17166
- type: "object",
17167
- additionalProperties: false,
17168
- properties: {
17169
- ...connectConfigPlatforms
17170
- }
17171
- },
17172
- "@sockethub/platform-irc": {
17173
- type: "object",
17174
- additionalProperties: false,
17175
- properties: {
17176
- ...connectConfigPlatforms
17177
- }
17178
- },
17179
- "@sockethub/platform-xmpp": {
17180
- type: "object",
17181
- additionalProperties: false,
17182
- properties: {
17183
- ...connectConfigPlatforms
17184
- }
17185
- }
17186
- }
17187
- },
17188
- platforms: {
17189
- type: "array",
17190
- items: {
17191
- type: "string"
17192
- },
17193
- default: [
17194
- "@sockethub/platform-dummy",
17195
- "@sockethub/platform-feeds",
17196
- "@sockethub/platform-irc",
17197
- "@sockethub/platform-metadata",
17198
- "@sockethub/platform-xmpp"
17199
- ]
17200
- },
17201
- public: {
17202
- type: "object",
17203
- additionalProperties: false,
17204
- properties: {
17205
- protocol: {
17206
- type: "string",
17207
- default: "http"
17208
- },
17209
- host: {
17210
- type: "string",
17211
- default: "localhost"
17212
- },
17213
- port: {
17214
- type: "number",
17215
- default: 10550
17216
- },
17217
- path: {
17218
- type: "string",
17219
- default: "/"
17220
- }
17221
- }
17222
- },
17223
- rateLimiter: {
17224
- type: "object",
17225
- additionalProperties: false,
17226
- properties: {
17227
- windowMs: {
17228
- type: "number",
17229
- default: 1000
17230
- },
17231
- maxRequests: {
17232
- type: "number",
17233
- default: 100
17234
- },
17235
- blockDurationMs: {
17236
- type: "number",
17237
- default: 5000
17238
- }
17239
- }
17240
- },
17241
- redis: {
17242
- type: "object",
17243
- additionalProperties: false,
17244
- properties: {
17245
- url: {
17246
- type: "string",
17247
- default: "redis://127.0.0.1:6379"
17248
- },
17249
- connectTimeout: {
17250
- type: "number",
17251
- default: 1e4,
17252
- description: "Connection timeout in milliseconds"
17253
- },
17254
- disconnectTimeout: {
17255
- type: "number",
17256
- default: 5000,
17257
- description: "Disconnect timeout in milliseconds"
17258
- },
17259
- maxRetriesPerRequest: {
17260
- type: ["number", "null"],
17261
- default: null,
17262
- description: "Maximum number of retries per request (null for BullMQ default)"
17263
- }
17264
- }
17265
- },
17266
- sentry: {
17267
- type: "object",
17268
- additionalProperties: false,
17269
- properties: {
17270
- dsn: {
17271
- type: "string",
17272
- default: ""
17273
- },
17274
- traceSampleRate: {
17275
- type: "number",
17276
- default: 1
17277
- }
17278
- }
17279
- },
17280
- sockethub: {
17281
- type: "object",
17282
- additionalProperties: false,
17283
- properties: {
17284
- port: {
17285
- type: "number",
17286
- default: 10550
17287
- },
17288
- host: {
17289
- type: "string",
17290
- default: "localhost"
17291
- },
17292
- path: {
17293
- type: "string",
17294
- default: "/sockethub"
17295
- }
17296
- }
17297
- },
17298
- platformHeartbeat: {
17299
- type: "object",
17300
- additionalProperties: false,
17301
- properties: {
17302
- intervalMs: {
17303
- type: "number",
17304
- default: 5000
17305
- },
17306
- timeoutMs: {
17307
- type: "number",
17308
- default: 15000
17309
- }
17310
- }
17311
- }
17312
- }
17313
- };
17314
-
17315
16992
  // ../schemas/src/validator.ts
17316
16993
  var import_ajv = __toESM(require_ajv(), 1);
17317
16994
  var import_ajv_formats = __toESM(require_dist(), 1);
@@ -17323,7 +17000,6 @@ var schemaURL = "https://sockethub.org/schemas/v0";
17323
17000
  var schemas = {};
17324
17001
  var systemContextsRegistered = false;
17325
17002
  schemas[`${schemaURL}/activity-stream`] = ActivityStreamSchema;
17326
- schemas[`${schemaURL}/activity-object`] = ActivityObjectSchema;
17327
17003
  for (const uri in schemas) {
17328
17004
  ajv.addSchema(schemas[uri], uri);
17329
17005
  }
@@ -17353,7 +17029,7 @@ var import_irc_socket_sasl = __toESM(require_irc_socket(), 1);
17353
17029
  var package_default = {
17354
17030
  name: "@sockethub/platform-irc",
17355
17031
  description: "A sockethub platform module implementing IRC functionality",
17356
- version: "4.0.0-alpha.12",
17032
+ version: "4.0.0-alpha.13",
17357
17033
  private: false,
17358
17034
  author: "Nick Jennings <nick@silverbucket.net>",
17359
17035
  license: "LGPL-3.0+",
@@ -17364,17 +17040,16 @@ var package_default = {
17364
17040
  main: "dist/index.js",
17365
17041
  exports: {
17366
17042
  ".": {
17367
- bun: "./src/index.ts",
17043
+ types: "./dist/index.d.ts",
17368
17044
  import: "./dist/index.js",
17369
17045
  default: "./dist/index.js"
17370
17046
  }
17371
17047
  },
17372
17048
  files: [
17373
- "src/",
17374
17049
  "dist/"
17375
17050
  ],
17376
17051
  engines: {
17377
- bun: ">=1.2"
17052
+ node: ">=20"
17378
17053
  },
17379
17054
  keywords: [
17380
17055
  "sockethub",
@@ -17398,23 +17073,24 @@ var package_default = {
17398
17073
  doc: "typedoc --options typedoc.json"
17399
17074
  },
17400
17075
  dependencies: {
17401
- "@sockethub/irc2as": "^4.0.0-alpha.12",
17402
- "irc-socket-sasl": "^4.0.0"
17076
+ "@sockethub/irc2as": "^4.0.0-alpha.13",
17077
+ "irc-socket-sasl": "^4.1.2"
17403
17078
  },
17404
17079
  devDependencies: {
17405
- "@sockethub/schemas": "^3.0.0-alpha.12",
17080
+ "@sockethub/schemas": "^3.0.0-alpha.13",
17406
17081
  "@types/bun": "latest",
17407
17082
  typedoc: "^0.28.14"
17408
17083
  },
17409
17084
  peerDependencies: {
17410
- "@sockethub/server": "^5.0.0-alpha.12"
17085
+ "@sockethub/server": "^5.0.0-alpha.13"
17411
17086
  },
17412
17087
  peerDependenciesMeta: {
17413
17088
  "@sockethub/server": {
17414
17089
  optional: true
17415
17090
  }
17416
17091
  },
17417
- gitHead: "cc495a5fcf7ce19a8f328a34bbc8cd1439bb67ce"
17092
+ gitHead: "745e85ac71f3c027f8ef8b8edc49398be8dbaccd",
17093
+ types: "./dist/index.d.ts"
17418
17094
  };
17419
17095
 
17420
17096
  // src/schema.ts
@@ -17439,6 +17115,191 @@ var PlatformIrcSchema = {
17439
17115
  "announce",
17440
17116
  "disconnect"
17441
17117
  ]
17118
+ },
17119
+ object: {
17120
+ oneOf: [
17121
+ { $ref: "#/definitions/objectTypes/message" },
17122
+ { $ref: "#/definitions/objectTypes/topic" },
17123
+ { $ref: "#/definitions/objectTypes/address" },
17124
+ { $ref: "#/definitions/objectTypes/attendance" }
17125
+ ]
17126
+ }
17127
+ },
17128
+ definitions: {
17129
+ objectTypes: {
17130
+ message: {
17131
+ type: "object",
17132
+ required: ["type", "content"],
17133
+ additionalProperties: false,
17134
+ properties: {
17135
+ type: { enum: ["message"] },
17136
+ content: { type: "string" }
17137
+ }
17138
+ },
17139
+ topic: {
17140
+ type: "object",
17141
+ required: ["type", "content"],
17142
+ additionalProperties: false,
17143
+ properties: {
17144
+ type: { enum: ["topic"] },
17145
+ content: { type: "string" }
17146
+ }
17147
+ },
17148
+ address: {
17149
+ type: "object",
17150
+ required: ["type"],
17151
+ additionalProperties: false,
17152
+ properties: { type: { enum: ["address"] } }
17153
+ },
17154
+ attendance: {
17155
+ type: "object",
17156
+ required: ["type"],
17157
+ additionalProperties: false,
17158
+ properties: { type: { enum: ["attendance"] } }
17159
+ }
17160
+ }
17161
+ }
17162
+ },
17163
+ responses: {
17164
+ type: "object",
17165
+ required: ["type", "actor"],
17166
+ additionalProperties: false,
17167
+ properties: {
17168
+ "@context": { type: "array", items: { type: "string" } },
17169
+ id: { type: "string" },
17170
+ published: { type: "string" },
17171
+ type: {
17172
+ enum: ["update", "send", "join", "leave", "add", "remove"]
17173
+ },
17174
+ actor: {
17175
+ oneOf: [
17176
+ { $ref: "#/definitions/responses/person" },
17177
+ { $ref: "#/definitions/responses/service" }
17178
+ ]
17179
+ },
17180
+ target: {
17181
+ oneOf: [
17182
+ { $ref: "#/definitions/responses/person" },
17183
+ { $ref: "#/definitions/responses/room" },
17184
+ { $ref: "#/definitions/responses/service" }
17185
+ ]
17186
+ },
17187
+ error: { type: "string" },
17188
+ object: {
17189
+ oneOf: [
17190
+ { $ref: "#/definitions/responses/message" },
17191
+ { $ref: "#/definitions/responses/me" },
17192
+ { $ref: "#/definitions/responses/presence" },
17193
+ { $ref: "#/definitions/responses/topic" },
17194
+ { $ref: "#/definitions/responses/address" },
17195
+ { $ref: "#/definitions/responses/relationship" }
17196
+ ]
17197
+ }
17198
+ },
17199
+ definitions: {
17200
+ responses: {
17201
+ person: {
17202
+ type: "object",
17203
+ required: ["id", "type"],
17204
+ additionalProperties: false,
17205
+ properties: {
17206
+ id: { type: "string" },
17207
+ type: { enum: ["person"] },
17208
+ name: { type: "string" }
17209
+ }
17210
+ },
17211
+ service: {
17212
+ type: "object",
17213
+ required: ["id", "type"],
17214
+ additionalProperties: false,
17215
+ properties: {
17216
+ id: { type: "string" },
17217
+ type: { enum: ["service"] },
17218
+ name: { type: "string" }
17219
+ }
17220
+ },
17221
+ room: {
17222
+ type: "object",
17223
+ required: ["id", "type"],
17224
+ additionalProperties: false,
17225
+ properties: {
17226
+ id: { type: "string" },
17227
+ type: { enum: ["room"] },
17228
+ name: { type: "string" }
17229
+ }
17230
+ },
17231
+ message: {
17232
+ type: "object",
17233
+ required: ["type", "content"],
17234
+ additionalProperties: false,
17235
+ properties: {
17236
+ type: { enum: ["message"] },
17237
+ content: { type: "string" }
17238
+ }
17239
+ },
17240
+ me: {
17241
+ type: "object",
17242
+ required: ["type", "content"],
17243
+ additionalProperties: false,
17244
+ properties: {
17245
+ type: { enum: ["me"] },
17246
+ content: { type: "string" }
17247
+ }
17248
+ },
17249
+ presence: {
17250
+ type: "object",
17251
+ required: ["type"],
17252
+ additionalProperties: false,
17253
+ properties: {
17254
+ type: { enum: ["presence"] },
17255
+ role: {
17256
+ enum: ["owner", "member", "participant", "admin"]
17257
+ }
17258
+ }
17259
+ },
17260
+ topic: {
17261
+ type: "object",
17262
+ required: ["type", "content"],
17263
+ additionalProperties: false,
17264
+ properties: {
17265
+ type: { enum: ["topic"] },
17266
+ content: { type: "string" }
17267
+ }
17268
+ },
17269
+ address: {
17270
+ type: "object",
17271
+ required: ["type"],
17272
+ additionalProperties: false,
17273
+ properties: {
17274
+ type: { enum: ["address"] }
17275
+ }
17276
+ },
17277
+ relationship: {
17278
+ type: "object",
17279
+ required: ["type", "relationship"],
17280
+ additionalProperties: false,
17281
+ properties: {
17282
+ type: { enum: ["relationship"] },
17283
+ relationship: { enum: ["role"] },
17284
+ subject: {
17285
+ type: "object",
17286
+ required: ["type", "role"],
17287
+ additionalProperties: false,
17288
+ properties: {
17289
+ type: { enum: ["presence"] },
17290
+ role: {
17291
+ enum: [
17292
+ "owner",
17293
+ "member",
17294
+ "participant",
17295
+ "admin"
17296
+ ]
17297
+ }
17298
+ }
17299
+ },
17300
+ object: { $ref: "#/definitions/responses/room" }
17301
+ }
17302
+ }
17442
17303
  }
17443
17304
  }
17444
17305
  },
@@ -17453,6 +17314,38 @@ var PlatformIrcSchema = {
17453
17314
  type: "object",
17454
17315
  required: ["type", "nick", "server"],
17455
17316
  additionalProperties: false,
17317
+ not: { required: ["password", "token"] },
17318
+ allOf: [
17319
+ {
17320
+ anyOf: [
17321
+ {
17322
+ not: {
17323
+ properties: {
17324
+ saslMechanism: { const: "PLAIN" }
17325
+ },
17326
+ required: ["saslMechanism"]
17327
+ }
17328
+ },
17329
+ { required: ["password"] },
17330
+ { required: ["token"] }
17331
+ ]
17332
+ },
17333
+ {
17334
+ anyOf: [
17335
+ {
17336
+ not: {
17337
+ properties: {
17338
+ saslMechanism: {
17339
+ const: "OAUTHBEARER"
17340
+ }
17341
+ },
17342
+ required: ["saslMechanism"]
17343
+ }
17344
+ },
17345
+ { required: ["token"] }
17346
+ ]
17347
+ }
17348
+ ],
17456
17349
  properties: {
17457
17350
  type: {
17458
17351
  type: "string"
@@ -17464,7 +17357,12 @@ var PlatformIrcSchema = {
17464
17357
  type: "string"
17465
17358
  },
17466
17359
  password: {
17467
- type: "string"
17360
+ type: "string",
17361
+ minLength: 1
17362
+ },
17363
+ token: {
17364
+ type: "string",
17365
+ minLength: 1
17468
17366
  },
17469
17367
  server: {
17470
17368
  type: "string"
@@ -17477,6 +17375,13 @@ var PlatformIrcSchema = {
17477
17375
  },
17478
17376
  sasl: {
17479
17377
  type: "boolean"
17378
+ },
17379
+ saslMechanism: {
17380
+ type: "string",
17381
+ enum: ["PLAIN", "OAUTHBEARER"]
17382
+ },
17383
+ allowInvalidCert: {
17384
+ type: "boolean"
17480
17385
  }
17481
17386
  }
17482
17387
  }
@@ -17485,6 +17390,22 @@ var PlatformIrcSchema = {
17485
17390
  };
17486
17391
 
17487
17392
  // src/index.ts
17393
+ function flattenConnectOptions(options) {
17394
+ const flattened = Object.create(null);
17395
+ for (const key in options) {
17396
+ if (key === "__proto__" || key === "constructor" || key === "prototype") {
17397
+ continue;
17398
+ }
17399
+ flattened[key] = options[key];
17400
+ }
17401
+ return flattened;
17402
+ }
17403
+ var tlsTransport = {
17404
+ connect(options, ...rest) {
17405
+ return tls.connect(flattenConnectOptions(options), ...rest);
17406
+ }
17407
+ };
17408
+
17488
17409
  class IRC {
17489
17410
  log;
17490
17411
  credentialsHash;
@@ -17579,7 +17500,7 @@ class IRC {
17579
17500
  const { default: buildCommand } = await Promise.resolve().then(() => __toESM(require_octal_hack(), 1));
17580
17501
  const message = buildCommand(job.object.content);
17581
17502
  client.raw("PRIVMSG " + job.target.name + " :" + message);
17582
- return done("IRC commands temporarily disabled");
17503
+ return done();
17583
17504
  }
17584
17505
  if (job.object.type === "notice") {
17585
17506
  client.raw(`NOTICE ${job.target.name} :${job.object.content}`);
@@ -17630,8 +17551,12 @@ class IRC {
17630
17551
  return done(err);
17631
17552
  }
17632
17553
  if (job.object.type === "attendance") {
17633
- this.log.debug(`query() - sending NAMES for ${job.target.name}`);
17634
- client.raw(["NAMES", job.target.name]);
17554
+ const channel = this.resolveChannelName(job.target);
17555
+ if (!channel) {
17556
+ return done("cannot query attendance without a valid channel name");
17557
+ }
17558
+ this.log.debug(`query() - sending NAMES for ${channel}`);
17559
+ client.raw(["NAMES", channel]);
17635
17560
  done();
17636
17561
  } else {
17637
17562
  done(`unknown 'type' '${job.object.type}'`);
@@ -17654,6 +17579,19 @@ class IRC {
17654
17579
  this.client = undefined;
17655
17580
  return done();
17656
17581
  }
17582
+ resolveChannelName(target) {
17583
+ if (typeof target?.name === "string" && target.name.startsWith("#")) {
17584
+ return target.name;
17585
+ }
17586
+ if (typeof target?.id === "string") {
17587
+ const slash = target.id.indexOf("/");
17588
+ const candidate = slash >= 0 ? target.id.slice(slash + 1) : target.id;
17589
+ if (candidate.startsWith("#")) {
17590
+ return candidate;
17591
+ }
17592
+ }
17593
+ return;
17594
+ }
17657
17595
  isJoined(channel) {
17658
17596
  if (channel.indexOf("#") === 0) {
17659
17597
  return this.channels.has(channel);
@@ -17707,7 +17645,9 @@ class IRC {
17707
17645
  ircConnect(credentials, cb) {
17708
17646
  this.clientConnecting = true;
17709
17647
  const is_secure = typeof credentials.object.secure === "boolean" ? credentials.object.secure : true;
17710
- const is_sasl = typeof credentials.object.sasl === "boolean" ? credentials.object.sasl : !!credentials.object.password;
17648
+ const sasl_secret = credentials.object.token || credentials.object.password;
17649
+ const sasl_mechanism = credentials.object.saslMechanism || "PLAIN";
17650
+ const is_sasl = typeof credentials.object.sasl === "boolean" ? credentials.object.sasl : !!sasl_secret;
17711
17651
  const module_options = {
17712
17652
  username: credentials.object.username || credentials.object.nick,
17713
17653
  nicknames: [credentials.object.nick],
@@ -17717,14 +17657,17 @@ class IRC {
17717
17657
  debug: console.log
17718
17658
  };
17719
17659
  if (is_secure) {
17720
- module_options.connectOptions = { rejectUnauthorized: false };
17660
+ module_options.connectOptions = {
17661
+ rejectUnauthorized: !credentials.object.allowInvalidCert
17662
+ };
17721
17663
  }
17722
17664
  if (is_sasl) {
17723
- module_options.saslPassword = credentials.object.password;
17665
+ module_options.saslMechanism = sasl_mechanism;
17666
+ module_options.saslPassword = sasl_secret;
17724
17667
  module_options.capabilities = { requires: ["sasl"] };
17725
17668
  }
17726
- this.log.debug(`attempting to connect to ${module_options.server}:${module_options.port} transport: ${is_secure ? "secure" : "clear"} sasl: ${is_sasl}`);
17727
- const client = new import_irc_socket_sasl.default(module_options, is_secure ? tls : net);
17669
+ this.log.debug(`attempting to connect to ${module_options.server}:${module_options.port} transport: ${is_secure ? "secure" : "clear"} sasl: ${is_sasl}${is_sasl ? ` (${sasl_mechanism})` : ""}`);
17670
+ const client = new import_irc_socket_sasl.default(module_options, is_secure ? tlsTransport : net);
17728
17671
  const forceDisconnect = (err) => {
17729
17672
  this.forceDisconnect = true;
17730
17673
  this.clientConnecting = false;
@@ -17802,12 +17745,15 @@ class IRC {
17802
17745
  });
17803
17746
  this.irc2as.events.on("ping", (timestamp) => {
17804
17747
  this.log.debug(`received PING at ${timestamp}`);
17805
- this.client.raw("PONG");
17748
+ this.client?.raw("PONG");
17806
17749
  });
17807
17750
  }
17808
17751
  }
17752
+ var src_default = IRC;
17809
17753
  export {
17810
- IRC as default
17754
+ flattenConnectOptions,
17755
+ src_default as default,
17756
+ IRC
17811
17757
  };
17812
17758
 
17813
- //# debugId=D2F4C2CE472DA48C64756E2164756E21
17759
+ //# debugId=C44E30207832792D64756E2164756E21