@sockethub/activity-streams 4.4.0-alpha.4 → 4.4.0-alpha.5
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/README.md +109 -9
- package/dist/activity-streams.js +462 -0
- package/dist/activity-streams.min.js +19 -2
- package/package.json +27 -31
- package/coverage/tmp/coverage-39176-1663949475687-0.json +0 -1
- package/dist/activity-streams.min.js.LICENSE.txt +0 -16
- package/karma.config.js +0 -22
- package/src/activity-streams.d.ts +0 -1
- package/src/activity-streams.js +0 -224
- package/src/activity-streams.test.js +0 -192
- package/webpack.config.js +0 -10
package/README.md
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
|
-
# @sockethub/activity-streams
|
|
1
|
+
# @sockethub/activity-streams
|
|
2
2
|
|
|
3
3
|
[](https://npmjs.org/package/@sockethub/activity-streams)
|
|
4
4
|
[](https://npmjs.org/package/@sockethub/activity-streams)
|
|
5
5
|
|
|
6
|
-
A simple tool to facilitate handling and referencing activity streams and
|
|
6
|
+
A simple tool to facilitate handling and referencing activity streams and its objects, cutting
|
|
7
|
+
down on verbosity.
|
|
7
8
|
|
|
8
|
-
Designed to run in both `node.js` and the `browser`.
|
|
9
|
+
Designed to run in both `node.js`, `bun` and the `browser`.
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
This is a WIP and not fully JSON-LD or ActivityStreams2 compliant, suggestions for improvement
|
|
12
|
+
are very welcome.
|
|
13
|
+
|
|
14
|
+
## What it does
|
|
15
|
+
|
|
16
|
+
This library helps you:
|
|
17
|
+
|
|
18
|
+
- **Create and store** ActivityStream objects with validation
|
|
19
|
+
- **Auto-expand** string references into full objects (e.g., `"user@example.com"` becomes `{id: "user@example.com"}`)
|
|
20
|
+
- **Build Activity Streams** that automatically link to stored objects
|
|
21
|
+
- **Listen for events** when objects are created or deleted
|
|
11
22
|
|
|
12
23
|
## Install
|
|
13
24
|
|
|
@@ -15,19 +26,93 @@ I am learning about JSON-LD and ActivityStreams2 as I write this library, so sug
|
|
|
15
26
|
|
|
16
27
|
`$ npm install @sockethub/activity-streams`
|
|
17
28
|
|
|
29
|
+
### Bun
|
|
30
|
+
|
|
31
|
+
`$ bun install @sockethub/activity-streams`
|
|
32
|
+
|
|
33
|
+
#### CommonJS
|
|
34
|
+
|
|
18
35
|
```javascript
|
|
19
36
|
const ASFactory = require('@sockethub/activity-streams');
|
|
20
37
|
const ActivityStreams = ASFactory({
|
|
21
|
-
|
|
38
|
+
failOnUnknownObjectProperties: false // default
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
#### ESM
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
import { ASFactory } from '@sockethub/activity-streams';
|
|
46
|
+
const ActivityStreams = ASFactory({
|
|
47
|
+
failOnUnknownObjectProperties: false // default
|
|
22
48
|
});
|
|
23
49
|
```
|
|
24
50
|
|
|
25
51
|
### Browser
|
|
26
52
|
|
|
27
|
-
|
|
53
|
+
The browser bundle is available in the dist folder:
|
|
28
54
|
|
|
29
|
-
|
|
55
|
+
```javascript
|
|
56
|
+
import '@sockethub/activity-streams/dist/activity-streams.js';
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
You can place it somewhere accessible from the web and include it via a `script` tag.
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
<script src="http://example.com/activity-streams.js" type="module"></script>
|
|
63
|
+
```
|
|
30
64
|
|
|
65
|
+
Once included in a web-page, the `ActivityStreams` base object should be on the global scope, with
|
|
66
|
+
the sub-properties `ActivityStreams.Object` and `ActivityStreams.Stream`.
|
|
67
|
+
|
|
68
|
+
## Quick Start
|
|
69
|
+
|
|
70
|
+
### Standalone Usage
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
import { ASFactory } from '@sockethub/activity-streams';
|
|
74
|
+
const ActivityStreams = ASFactory();
|
|
75
|
+
|
|
76
|
+
// Create an object
|
|
77
|
+
const user = ActivityStreams.Object.create({
|
|
78
|
+
id: "user@example.com",
|
|
79
|
+
type: "person",
|
|
80
|
+
name: "John Doe"
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Create an activity that references it
|
|
84
|
+
const activity = ActivityStreams.Stream({
|
|
85
|
+
type: "send",
|
|
86
|
+
context: "irc",
|
|
87
|
+
actor: "user@example.com", // automatically expands to full object
|
|
88
|
+
object: { type: "message", content: "Hello!" }
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### With Sockethub Client
|
|
93
|
+
|
|
94
|
+
If you're using the Sockethub client, this library is already bundled and available:
|
|
95
|
+
|
|
96
|
+
```javascript
|
|
97
|
+
import SockethubClient from '@sockethub/client';
|
|
98
|
+
|
|
99
|
+
const socket = io('http://localhost:10550');
|
|
100
|
+
const sockethubClient = new SockethubClient(socket);
|
|
101
|
+
|
|
102
|
+
// Access ActivityStreams through the client
|
|
103
|
+
const user = sockethubClient.ActivityStreams.Object.create({
|
|
104
|
+
id: "user@example.com",
|
|
105
|
+
type: "person",
|
|
106
|
+
name: "John Doe"
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const activity = sockethubClient.ActivityStreams.Stream({
|
|
110
|
+
type: "send",
|
|
111
|
+
context: "irc",
|
|
112
|
+
actor: "user@example.com",
|
|
113
|
+
object: { type: "message", content: "Hello!" }
|
|
114
|
+
});
|
|
115
|
+
```
|
|
31
116
|
|
|
32
117
|
## Example
|
|
33
118
|
|
|
@@ -74,7 +159,7 @@ const exampleUser = ActivityStreams.Object.get('irc://exampleUser@irc.freenode.n
|
|
|
74
159
|
// }
|
|
75
160
|
|
|
76
161
|
ActivityStreams.Stream({
|
|
77
|
-
|
|
162
|
+
type: 'send',
|
|
78
163
|
actor: 'irc://exampleUser@irc.freenode.net',
|
|
79
164
|
object: {
|
|
80
165
|
type: "message",
|
|
@@ -84,7 +169,7 @@ ActivityStreams.Stream({
|
|
|
84
169
|
});
|
|
85
170
|
// ... returns:
|
|
86
171
|
// {
|
|
87
|
-
//
|
|
172
|
+
// type: 'send',
|
|
88
173
|
// actor: {
|
|
89
174
|
// id: 'irc://exampleUser@irc.freenode.net',
|
|
90
175
|
// type: "person",
|
|
@@ -108,3 +193,18 @@ ActivityStreams.Stream({
|
|
|
108
193
|
// }
|
|
109
194
|
// }
|
|
110
195
|
```
|
|
196
|
+
|
|
197
|
+
## Error Handling
|
|
198
|
+
|
|
199
|
+
The library provides clear error messages when validation fails:
|
|
200
|
+
|
|
201
|
+
```javascript
|
|
202
|
+
// This will throw: "ActivityStreams validation failed: the 'object' property is null"
|
|
203
|
+
ActivityStreams.Object.create(null);
|
|
204
|
+
|
|
205
|
+
// This will throw: "ActivityStreams validation failed: the 'object' property received string..."
|
|
206
|
+
ActivityStreams.Object.create("just-a-string");
|
|
207
|
+
|
|
208
|
+
// This will throw: "ActivityStreams validation failed: property 'foo' with value 'bar' is not allowed..."
|
|
209
|
+
ActivityStreams.Object.create({ id: "test", foo: "bar" });
|
|
210
|
+
```
|