@sockethub/platform-irc 4.0.0-alpha.3
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/API.md +375 -0
- package/LICENSE +165 -0
- package/README.md +96 -0
- package/index.js +701 -0
- package/index.test.data.js +61 -0
- package/index.test.js +204 -0
- package/package.json +57 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
modules.exports = [
|
|
2
|
+
{
|
|
3
|
+
"name":"irc credentials",
|
|
4
|
+
"valid":true,
|
|
5
|
+
"type":"credentials",
|
|
6
|
+
"input":{
|
|
7
|
+
"context":"irc",
|
|
8
|
+
"type":"credentials",
|
|
9
|
+
"actor":{
|
|
10
|
+
"id":"sh-9K3Vk@irc.freenode.net",
|
|
11
|
+
"type":"person",
|
|
12
|
+
"name":"sh-9K3Vk",
|
|
13
|
+
"image":{
|
|
14
|
+
"height":250,
|
|
15
|
+
"mediaType":"image/jpeg",
|
|
16
|
+
"url":"http://example.org/image.jpg",
|
|
17
|
+
"width":250
|
|
18
|
+
},
|
|
19
|
+
"url":"http://sockethub.org"
|
|
20
|
+
},
|
|
21
|
+
"object":{
|
|
22
|
+
"type":"credentials",
|
|
23
|
+
"nick":"sh-9K3Vk",
|
|
24
|
+
"port":6667,
|
|
25
|
+
"secure":false,
|
|
26
|
+
"server":"irc.freenode.net"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"output":"same"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"name":"bad irc credentials: user/nick host/server",
|
|
33
|
+
"valid":false,
|
|
34
|
+
"type":"credentials",
|
|
35
|
+
"input":{
|
|
36
|
+
"context":"irc",
|
|
37
|
+
"type":"credentials",
|
|
38
|
+
"actor":{
|
|
39
|
+
"id":"sh-9K3Vk@irc.freenode.net",
|
|
40
|
+
"type":"person",
|
|
41
|
+
"name":"sh-9K3Vk",
|
|
42
|
+
"image":{
|
|
43
|
+
"height":250,
|
|
44
|
+
"mediaType":"image/jpeg",
|
|
45
|
+
"url":"http://example.org/image.jpg",
|
|
46
|
+
"width":250
|
|
47
|
+
},
|
|
48
|
+
"url":"http://sockethub.org"
|
|
49
|
+
},
|
|
50
|
+
"object":{
|
|
51
|
+
"type":"credentials",
|
|
52
|
+
"user":"sh-9K3Vk",
|
|
53
|
+
"port":6667,
|
|
54
|
+
"secure":false,
|
|
55
|
+
"host":"irc.freenode.net"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"error":
|
|
59
|
+
"Error: /object: must NOT have additional properties"
|
|
60
|
+
},
|
|
61
|
+
]
|
package/index.test.js
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
const proxyquire = require('proxyquire');
|
|
2
|
+
const chai = require('chai');
|
|
3
|
+
const schemas = require('@sockethub/schemas').default;
|
|
4
|
+
const expect = chai.expect;
|
|
5
|
+
|
|
6
|
+
const IRCPlatform = require('./index');
|
|
7
|
+
|
|
8
|
+
proxyquire.noPreserveCache();
|
|
9
|
+
proxyquire.noCallThru();
|
|
10
|
+
|
|
11
|
+
const actor = {
|
|
12
|
+
type: 'person',
|
|
13
|
+
id: 'testingham@irc.example.com',
|
|
14
|
+
name:'testingham'
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const newActor = {
|
|
18
|
+
type: 'person',
|
|
19
|
+
id: 'testler@irc.example.com',
|
|
20
|
+
name:'testler'
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const targetRoom = {
|
|
24
|
+
type: 'room',
|
|
25
|
+
id: 'irc.example.com/a-room',
|
|
26
|
+
name: '#a-room'
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const validCredentials = {
|
|
30
|
+
context: 'irc',
|
|
31
|
+
type: 'credentials',
|
|
32
|
+
actor: actor,
|
|
33
|
+
object: {
|
|
34
|
+
type: 'credentials',
|
|
35
|
+
nick: 'testingham',
|
|
36
|
+
server: 'irc.example.com'
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
let loadedSchema = false;
|
|
41
|
+
|
|
42
|
+
describe('Initialize IRC Platform', () => {
|
|
43
|
+
let platform;
|
|
44
|
+
beforeEach(() => {
|
|
45
|
+
platform = new IRCPlatform({
|
|
46
|
+
debug: function () {},
|
|
47
|
+
updateActor: function (obj) {}
|
|
48
|
+
});
|
|
49
|
+
platform.__connect = function (key, credentials, cb) {
|
|
50
|
+
cb(null, {
|
|
51
|
+
end: () => {},
|
|
52
|
+
on: function () {},
|
|
53
|
+
raw: () => {}
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
if (!loadedSchema) {
|
|
57
|
+
schemas.addPlatformSchema(platform.schema.credentials, `irc/credentials`);
|
|
58
|
+
loadedSchema = true;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('lists required types enum', () => {
|
|
63
|
+
expect(platform.schema.messages.properties.type.enum).to.eql([
|
|
64
|
+
'connect', 'update', 'join', 'leave', 'send', 'query', 'announce'
|
|
65
|
+
]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('returns a config object', () => {
|
|
69
|
+
expect(platform.config).to.eql({
|
|
70
|
+
persist: true,
|
|
71
|
+
requireCredentials: ['connect', 'update'],
|
|
72
|
+
initialized: false
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('schema format validation', () => {
|
|
77
|
+
expect(schemas.validatePlatformSchema(platform.schema)).to.equal("");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('credential schema', () => {
|
|
81
|
+
it('valid credentials', () => {
|
|
82
|
+
expect(schemas.validateCredentials(validCredentials)).to.equal("");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('invalid credentials type', () => {
|
|
86
|
+
expect(schemas.validateCredentials({
|
|
87
|
+
context: 'irc',
|
|
88
|
+
type: 'credentials',
|
|
89
|
+
object: {
|
|
90
|
+
host: 'example.com',
|
|
91
|
+
port: '6667'
|
|
92
|
+
}})).to.equal("/object: must have required property 'type'");
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('invalid credentials port', () => {
|
|
96
|
+
expect(schemas.validateCredentials({
|
|
97
|
+
context: 'irc',
|
|
98
|
+
type: 'credentials',
|
|
99
|
+
object: {
|
|
100
|
+
type: 'credentials',
|
|
101
|
+
host: 'example.com',
|
|
102
|
+
port: '6667'
|
|
103
|
+
}})).to.equal("/object/port: must be number");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('invalid credentials additional prop', () => {
|
|
107
|
+
expect(schemas.validateCredentials({
|
|
108
|
+
context: 'irc',
|
|
109
|
+
type: 'credentials',
|
|
110
|
+
object: {
|
|
111
|
+
type: 'credentials',
|
|
112
|
+
host: 'example.com',
|
|
113
|
+
port: 6667
|
|
114
|
+
}})).to.equal("/object: must NOT have additional properties");
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe('platform type methods', () => {
|
|
119
|
+
beforeEach((done) => {
|
|
120
|
+
platform.connect({
|
|
121
|
+
context: 'irc',
|
|
122
|
+
type: 'connect',
|
|
123
|
+
actor: actor
|
|
124
|
+
}, { object: { server: 'a server address' } }, done);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('after join', () => {
|
|
128
|
+
beforeEach((done) => {
|
|
129
|
+
platform.join({
|
|
130
|
+
context: 'irc',
|
|
131
|
+
type: 'join',
|
|
132
|
+
actor: actor,
|
|
133
|
+
target: targetRoom
|
|
134
|
+
}, done);
|
|
135
|
+
platform.__completeJob();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('has join channel registered', () => {
|
|
139
|
+
expect(platform.__channels.has('#a-room')).to.equal(true);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('leave()', (done) => {
|
|
143
|
+
platform.leave({
|
|
144
|
+
context: 'irc',
|
|
145
|
+
type: 'leave',
|
|
146
|
+
actor: actor,
|
|
147
|
+
target: targetRoom
|
|
148
|
+
}, done);
|
|
149
|
+
platform.__completeJob();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('send()', (done) => {
|
|
153
|
+
platform.send({
|
|
154
|
+
context: 'irc',
|
|
155
|
+
type: 'send',
|
|
156
|
+
actor: actor,
|
|
157
|
+
object: { content: 'har dee dar' },
|
|
158
|
+
target: targetRoom
|
|
159
|
+
}, done);
|
|
160
|
+
platform.__completeJob();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('update() topic', (done) => {
|
|
164
|
+
platform.update({
|
|
165
|
+
context: 'irc',
|
|
166
|
+
type: 'update',
|
|
167
|
+
actor: actor,
|
|
168
|
+
object: { type: 'topic', content: 'important details' },
|
|
169
|
+
target: targetRoom
|
|
170
|
+
}, validCredentials, done);
|
|
171
|
+
platform.__completeJob();
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('update() nick change', (done) => {
|
|
175
|
+
platform.update({
|
|
176
|
+
context: 'irc',
|
|
177
|
+
type: 'update',
|
|
178
|
+
actor: actor,
|
|
179
|
+
object: { type: 'address' },
|
|
180
|
+
target: newActor
|
|
181
|
+
}, validCredentials, done);
|
|
182
|
+
platform.__completeJob();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('query()', (done) => {
|
|
186
|
+
platform.query({
|
|
187
|
+
context: 'irc',
|
|
188
|
+
type: 'query',
|
|
189
|
+
actor: actor,
|
|
190
|
+
target: targetRoom,
|
|
191
|
+
object: { type: 'attendance' },
|
|
192
|
+
}, done);
|
|
193
|
+
platform.__completeJob();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('cleanup()', (done) => {
|
|
197
|
+
platform.cleanup(() => {
|
|
198
|
+
expect(platform.initialized).to.eql(false);
|
|
199
|
+
done();
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sockethub/platform-irc",
|
|
3
|
+
"description": "A sockethub platform module implementing IRC functionality",
|
|
4
|
+
"version": "4.0.0-alpha.3",
|
|
5
|
+
"private": false,
|
|
6
|
+
"author": "Nick Jennings <nick@silverbucket.net>",
|
|
7
|
+
"license": "LGPL-3.0+",
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"sockethub",
|
|
11
|
+
"messaging",
|
|
12
|
+
"activitystreams",
|
|
13
|
+
"activity",
|
|
14
|
+
"streams",
|
|
15
|
+
"protocol",
|
|
16
|
+
"irc"
|
|
17
|
+
],
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/sockethub/sockethub.git",
|
|
21
|
+
"directory": "packages/platform-irc"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/sockethub/sockethub/tree/master/packages/platform-irc",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@sockethub/irc2as": "^4.0.0-alpha.3",
|
|
26
|
+
"irc-socket-sasl": "4.0.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@sockethub/schemas": "^3.0.0-alpha.3",
|
|
30
|
+
"c8": "7.11.0",
|
|
31
|
+
"chai": "4.3.6",
|
|
32
|
+
"eslint": "8.9.0",
|
|
33
|
+
"jsdoc-to-markdown": "7.1.1",
|
|
34
|
+
"proxyquire": "2.1.3",
|
|
35
|
+
"sinon": "13.0.1"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@sockethub/server": ">=5.0.0-alpha.2"
|
|
39
|
+
},
|
|
40
|
+
"peerDependenciesMeta": {
|
|
41
|
+
"@sockethub/server": {
|
|
42
|
+
"optional": true
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "true",
|
|
47
|
+
"clean": "npx rimraf coverage",
|
|
48
|
+
"clean:deps": "npx rimraf coverage node_modules",
|
|
49
|
+
"compliance": "yarn run lint && yarn run test && yarn run coverage",
|
|
50
|
+
"test": "c8 mocha *.test.js",
|
|
51
|
+
"coverage": "c8 check-coverage --statements 80 --branches 55 --functions 85 --lines 80",
|
|
52
|
+
"doc": "jsdoc2md --no-gfm --heading-depth 1 index.js > API.md",
|
|
53
|
+
"lint": "eslint \"**/*.js\"",
|
|
54
|
+
"lint:fix": "eslint --fix \"**/*.js\""
|
|
55
|
+
},
|
|
56
|
+
"gitHead": "f02238a478b7ffd3f31d8deea292eb67e630a86b"
|
|
57
|
+
}
|