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

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sockethub/platform-irc",
3
3
  "description": "A sockethub platform module implementing IRC functionality",
4
- "version": "4.0.0-alpha.11",
4
+ "version": "4.0.0-alpha.12",
5
5
  "private": false,
6
6
  "author": "Nick Jennings <nick@silverbucket.net>",
7
7
  "license": "LGPL-3.0+",
@@ -46,21 +46,21 @@
46
46
  "doc": "typedoc --options typedoc.json"
47
47
  },
48
48
  "dependencies": {
49
- "@sockethub/irc2as": "^4.0.0-alpha.11",
49
+ "@sockethub/irc2as": "^4.0.0-alpha.12",
50
50
  "irc-socket-sasl": "^4.0.0"
51
51
  },
52
52
  "devDependencies": {
53
- "@sockethub/schemas": "^3.0.0-alpha.11",
53
+ "@sockethub/schemas": "^3.0.0-alpha.12",
54
54
  "@types/bun": "latest",
55
55
  "typedoc": "^0.28.14"
56
56
  },
57
57
  "peerDependencies": {
58
- "@sockethub/server": "^5.0.0-alpha.11"
58
+ "@sockethub/server": "^5.0.0-alpha.12"
59
59
  },
60
60
  "peerDependenciesMeta": {
61
61
  "@sockethub/server": {
62
62
  "optional": true
63
63
  }
64
64
  },
65
- "gitHead": "c243fa9e76c688ce5ffcf524400b1dd27dcce615"
65
+ "gitHead": "f039dab3c3f67cbbf204476fc397532e973f82a8"
66
66
  }
@@ -0,0 +1,35 @@
1
+ declare module "irc-socket-sasl" {
2
+ export interface IrcSocketInstance {
3
+ end?: () => void;
4
+ raw: (message: string) => void;
5
+ once: (
6
+ event: string,
7
+ handler: (...args: Array<unknown>) => void,
8
+ ) => void;
9
+ on: (event: string, handler: (...args: Array<unknown>) => void) => void;
10
+ connect: () => Promise<unknown>;
11
+ }
12
+ const IrcSocket: new (...args: Array<unknown>) => IrcSocketInstance;
13
+ export default IrcSocket;
14
+ }
15
+
16
+ declare module "@sockethub/irc2as" {
17
+ interface IrcToActivityStreamsOptions {
18
+ server: string;
19
+ contexts?: Array<string>;
20
+ context?: string;
21
+ }
22
+
23
+ export class IrcToActivityStreams {
24
+ constructor(options: IrcToActivityStreamsOptions);
25
+ input(data: unknown): void;
26
+ events: {
27
+ on(event: string, handler: (...args: Array<unknown>) => void): void;
28
+ };
29
+ }
30
+ }
31
+
32
+ declare module "./octal-hack.js" {
33
+ const buildCommand: (input: string) => string;
34
+ export default buildCommand;
35
+ }
@@ -4,7 +4,11 @@ export default [
4
4
  valid: true,
5
5
  type: "credentials",
6
6
  input: {
7
- context: "irc",
7
+ "@context": [
8
+ "https://www.w3.org/ns/activitystreams",
9
+ "https://sockethub.org/ns/context/v1.jsonld",
10
+ "https://sockethub.org/ns/context/platform/irc/v1.jsonld",
11
+ ],
8
12
  type: "credentials",
9
13
  actor: {
10
14
  id: "sh-9K3Vk@irc.freenode.net",
@@ -33,7 +37,11 @@ export default [
33
37
  valid: false,
34
38
  type: "credentials",
35
39
  input: {
36
- context: "irc",
40
+ "@context": [
41
+ "https://www.w3.org/ns/activitystreams",
42
+ "https://sockethub.org/ns/context/v1.jsonld",
43
+ "https://sockethub.org/ns/context/platform/irc/v1.jsonld",
44
+ ],
37
45
  type: "credentials",
38
46
  actor: {
39
47
  id: "sh-9K3Vk@irc.freenode.net",
package/src/index.test.ts CHANGED
@@ -3,7 +3,9 @@ import { beforeEach, describe, expect, it } from "bun:test";
3
3
  import {
4
4
  type ActivityStream,
5
5
  type CredentialsObject,
6
+ addPlatformContext,
6
7
  addPlatformSchema,
8
+ buildCanonicalContext,
7
9
  getPlatformSchema,
8
10
  validateCredentials,
9
11
  validatePlatformSchema,
@@ -30,8 +32,12 @@ const targetRoom = {
30
32
  name: "#a-room",
31
33
  };
32
34
 
35
+ const IRC_CONTEXT = buildCanonicalContext(
36
+ "https://sockethub.org/ns/context/platform/irc/v1.jsonld",
37
+ );
38
+
33
39
  const validCredentials = {
34
- context: "irc",
40
+ "@context": IRC_CONTEXT,
35
41
  type: "credentials",
36
42
  actor: actor,
37
43
  object: {
@@ -69,6 +75,7 @@ describe("Initialize IRC Platform", () => {
69
75
  if (!getPlatformSchema("irc/credentials")) {
70
76
  addPlatformSchema(platform.schema.credentials, `irc/credentials`);
71
77
  }
78
+ addPlatformContext("irc", platform.schema.contextUrl);
72
79
  });
73
80
 
74
81
  it("lists required types enum", () => {
@@ -102,25 +109,30 @@ describe("Initialize IRC Platform", () => {
102
109
  });
103
110
 
104
111
  it("invalid credentials type", () => {
105
- expect(
106
- validateCredentials({
107
- context: "irc",
108
- type: "credentials",
109
- // @ts-expect-error test invalid params
110
- object: {
111
- host: "example.com",
112
- port: "6667",
113
- },
114
- }),
115
- ).toEqual("[irc] /object: must have required property 'type'");
112
+ const result = validateCredentials({
113
+ "@context": IRC_CONTEXT,
114
+ type: "credentials",
115
+ actor,
116
+ // @ts-expect-error test invalid params
117
+ object: {
118
+ host: "example.com",
119
+ port: "6667",
120
+ },
121
+ });
122
+ expect([
123
+ "[irc] /object: must have required property 'type'",
124
+ "[irc] /object/port: must be number",
125
+ "[irc] /object: must match exactly one schema in oneOf: credentials, feed, message, me, person, room, service, platform, website, attendance, presence, relationship, topic, address, heartbeat",
126
+ ]).toContain(result);
116
127
  });
117
128
 
118
129
  it("invalid credentials port", () => {
119
130
  expect(
120
131
  // @ts-expect-error test invalid params
121
132
  validateCredentials({
122
- context: "irc",
133
+ "@context": IRC_CONTEXT,
123
134
  type: "credentials",
135
+ actor,
124
136
  object: {
125
137
  type: "credentials",
126
138
  host: "example.com",
@@ -134,8 +146,9 @@ describe("Initialize IRC Platform", () => {
134
146
  expect(
135
147
  // @ts-expect-error test invalid params
136
148
  validateCredentials({
137
- context: "irc",
149
+ "@context": IRC_CONTEXT,
138
150
  type: "credentials",
151
+ actor,
139
152
  object: {
140
153
  type: "credentials",
141
154
  host: "example.com",
@@ -152,7 +165,7 @@ describe("Initialize IRC Platform", () => {
152
165
  beforeEach((done) => {
153
166
  platform.connect(
154
167
  {
155
- context: "irc",
168
+ "@context": IRC_CONTEXT,
156
169
  type: "connect",
157
170
  actor: actor,
158
171
  },
@@ -165,7 +178,7 @@ describe("Initialize IRC Platform", () => {
165
178
  beforeEach((done) => {
166
179
  platform.join(
167
180
  {
168
- context: "irc",
181
+ "@context": IRC_CONTEXT,
169
182
  type: "join",
170
183
  actor: actor,
171
184
  target: targetRoom,
@@ -182,7 +195,7 @@ describe("Initialize IRC Platform", () => {
182
195
  it("leave()", (done) => {
183
196
  platform.leave(
184
197
  {
185
- context: "irc",
198
+ "@context": IRC_CONTEXT,
186
199
  type: "leave",
187
200
  actor: actor,
188
201
  target: targetRoom,
@@ -195,7 +208,7 @@ describe("Initialize IRC Platform", () => {
195
208
  it("send()", (done) => {
196
209
  platform.send(
197
210
  {
198
- context: "irc",
211
+ "@context": IRC_CONTEXT,
199
212
  type: "send",
200
213
  actor: actor,
201
214
  object: { content: "har dee dar" },
@@ -209,7 +222,7 @@ describe("Initialize IRC Platform", () => {
209
222
  it("update() topic", (done) => {
210
223
  platform.update(
211
224
  {
212
- context: "irc",
225
+ "@context": IRC_CONTEXT,
213
226
  type: "update",
214
227
  actor: actor,
215
228
  object: { type: "topic", content: "important details" },
@@ -224,7 +237,7 @@ describe("Initialize IRC Platform", () => {
224
237
  it("update() nick change", (done) => {
225
238
  platform.update(
226
239
  {
227
- context: "irc",
240
+ "@context": IRC_CONTEXT,
228
241
  type: "update",
229
242
  actor: actor,
230
243
  object: { type: "address" },
@@ -239,7 +252,7 @@ describe("Initialize IRC Platform", () => {
239
252
  it("query()", (done) => {
240
253
  platform.query(
241
254
  {
242
- context: "irc",
255
+ "@context": IRC_CONTEXT,
243
256
  type: "query",
244
257
  actor: actor,
245
258
  target: targetRoom,
@@ -258,7 +271,7 @@ describe("Initialize IRC Platform", () => {
258
271
  cb();
259
272
  }
260
273
  platform.disconnect({
261
- context: "irc",
274
+ "@context": IRC_CONTEXT,
262
275
  type: "disconnect",
263
276
  actor: actor,
264
277
  },
package/src/index.ts CHANGED
@@ -18,8 +18,6 @@
18
18
 
19
19
  import net from "node:net";
20
20
  import tls from "node:tls";
21
- import IrcSocket from "irc-socket-sasl";
22
-
23
21
  import { IrcToActivityStreams } from "@sockethub/irc2as";
24
22
  import type {
25
23
  ActivityStream,
@@ -32,15 +30,19 @@ import type {
32
30
  PlatformSession,
33
31
  PlatformUpdateActor,
34
32
  } from "@sockethub/schemas";
33
+ import { buildCanonicalContext } from "@sockethub/schemas";
34
+ import IrcSocket, { type IrcSocketInstance } from "irc-socket-sasl";
35
35
 
36
36
  import { PlatformIrcSchema } from "./schema.js";
37
37
  import type { PlatformIrcCredentialsObject } from "./types.js";
38
38
 
39
39
  export type GetClientCallback = (
40
40
  err: string | null,
41
- client?: typeof IrcSocket,
41
+ client?: IrcSocketInstance,
42
42
  ) => void;
43
43
 
44
+ type JobQueueHandler = (err?: Error | string) => void | Promise<void>;
45
+
44
46
  interface IrcSocketOptionsCapabilities {
45
47
  requires: string[];
46
48
  }
@@ -86,12 +88,12 @@ export default class IRC implements PersistentPlatformInterface {
86
88
  };
87
89
  private readonly updateActor: PlatformUpdateActor;
88
90
  private readonly sendToClient: PlatformSendToClient;
89
- private irc2as: typeof IrcToActivityStreams;
91
+ private irc2as!: IrcToActivityStreams;
90
92
  private forceDisconnect = false;
91
93
  private clientConnecting = false;
92
94
  private initialized = false;
93
- private client: typeof IrcSocket;
94
- private jobQueue = []; // list of handlers to confirm when message delivery confirmed
95
+ private client?: IrcSocketInstance;
96
+ private jobQueue: Array<JobQueueHandler> = []; // list of handlers to confirm when message delivery confirmed
95
97
  private channels = new Set();
96
98
  private handledActors = new Set();
97
99
 
@@ -330,9 +332,11 @@ export default class IRC implements PersistentPlatformInterface {
330
332
  // so the following line needs to be commented out when the API doc is built.
331
333
  // investigate:
332
334
  // https://github.com/jsdoc2md/jsdoc-to-markdown/issues/197#issuecomment-976851915
333
- const buildCommand = await import("./octal-hack.js");
335
+ const { default: buildCommand } = await import(
336
+ "./octal-hack.js"
337
+ );
334
338
  const message = buildCommand(job.object.content);
335
- // biome-ignore lint/style/useTemplate: <explanation>
339
+ // biome-ignore lint/style/useTemplate: IRC raw command formatting
336
340
  client.raw("PRIVMSG " + job.target.name + " :" + message);
337
341
  return done("IRC commands temporarily disabled");
338
342
  }
@@ -665,10 +669,7 @@ export default class IRC implements PersistentPlatformInterface {
665
669
  } sasl: ${is_sasl}`,
666
670
  );
667
671
 
668
- const client: IrcSocket = new IrcSocket(
669
- module_options,
670
- is_secure ? tls : net,
671
- );
672
+ const client = new IrcSocket(module_options, is_secure ? tls : net);
672
673
 
673
674
  const forceDisconnect = (err: string) => {
674
675
  this.forceDisconnect = true;
@@ -683,7 +684,7 @@ export default class IRC implements PersistentPlatformInterface {
683
684
  };
684
685
 
685
686
  client.once("error", (err: string) => {
686
- this.log.debug(`irc client 'error' occurred. `, err);
687
+ this.log.debug(`irc client 'error' occurred.`, { err });
687
688
  forceDisconnect("error connecting to server.");
688
689
  });
689
690
 
@@ -710,7 +711,7 @@ export default class IRC implements PersistentPlatformInterface {
710
711
 
711
712
  this.log.debug(
712
713
  `connected to ${module_options.server} capabilities: `,
713
- capabilities,
714
+ { capabilities },
714
715
  );
715
716
  return cb(null, client);
716
717
  });
@@ -733,8 +734,11 @@ export default class IRC implements PersistentPlatformInterface {
733
734
  }
734
735
 
735
736
  private registerListeners(server: string) {
736
- this.irc2as = new IrcToActivityStreams({ server: server });
737
- this.client.on("data", (data: never) => {
737
+ this.irc2as = new IrcToActivityStreams({
738
+ server: server,
739
+ contexts: buildCanonicalContext(this.schema.contextUrl),
740
+ });
741
+ this.client.on("data", (data: unknown) => {
738
742
  this.irc2as.input(data);
739
743
  });
740
744
 
@@ -0,0 +1,2 @@
1
+ declare const buildCommand: (input: string) => string;
2
+ export default buildCommand;
package/src/octal-hack.js CHANGED
@@ -1,4 +1,4 @@
1
1
  module.exports = (content) => {
2
- // biome-ignore lint/style/useTemplate: <explanation>
3
- return "\001ACTION " + content + "\001";
2
+ // biome-ignore lint/style/useTemplate: IRC ACTION wrapper expects raw concatenation
3
+ return "\x01ACTION " + content + "\x01";
4
4
  };
package/src/schema.ts CHANGED
@@ -1,9 +1,13 @@
1
1
  import packageJson from "../package.json" with { type: "json" };
2
+
2
3
  const version = packageJson.version;
3
4
 
4
5
  export const PlatformIrcSchema = {
5
6
  name: "irc",
6
7
  version: version,
8
+ contextUrl: "https://sockethub.org/ns/context/platform/irc/v1.jsonld",
9
+ contextVersion: "1",
10
+ schemaVersion: "1",
7
11
  messages: {
8
12
  required: ["type"],
9
13
  properties: {
package/src/types.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { ActivityActor, CredentialsObject } from "@sockethub/schemas";
2
2
 
3
3
  export interface PlatformIrcCredentialsObject extends CredentialsObject {
4
- context: "irc";
4
+ "@context": Array<string>;
5
5
  type: "credentials";
6
6
  actor: ActivityActor;
7
7
  target?: ActivityActor;