@sockethub/activity-streams 4.4.0-alpha.3 → 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 CHANGED
@@ -1,13 +1,24 @@
1
- # @sockethub/activity-streams.js
1
+ # @sockethub/activity-streams
2
2
 
3
3
  [![License](https://img.shields.io/npm/l/activity-streams.svg?style=flat)](https://npmjs.org/package/@sockethub/activity-streams)
4
4
  [![Downloads](http://img.shields.io/npm/dm/activity-streams.svg?style=flat)](https://npmjs.org/package/@sockethub/activity-streams)
5
5
 
6
- A simple tool to facilitate handling and referencing activity streams and it's objects, cutting down on verbosity.
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
- I am learning about JSON-LD and ActivityStreams2 as I write this library, so suggestions for improvement are very welcome.
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
- failOnUnkownObjectProperties: false // default
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
- `<script src="http://example.com/activity-streams.js"></script>`
53
+ The browser bundle is available in the dist folder:
28
54
 
29
- Once included in a web-page, the `ActivityStreams` base object should be on the global scope, with the sub-properties `ActivityStreams.Object` and `ActivityStreams.Stream`.
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
- context: 'send',
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
- // '@context': 'send',
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
+ ```