Skip to content

Commit c33bc32

Browse files
committed
fix: Notification Templates
+ Notifications are identified by UUIDs. + Turtle notification template has the same fields as JSON-LD. + `notify:state` transmits Event-ID (which uniquely identifies a resource's state) and not E-Tag (which identify representations of the resource). + Parent reuses the generated Event-ID.
1 parent ad7073b commit c33bc32

File tree

5 files changed

+166
-30
lines changed

5 files changed

+166
-30
lines changed

lib/handlers/notify.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ function handler (req, res, next) {
8888
object,
8989
target,
9090
date: eventDate,
91-
// We use eTag as a proxy for state for now
92-
state: res.getHeader('ETag'),
9391
mediaType
9492
})}`
9593
} else {
@@ -110,7 +108,10 @@ function handler (req, res, next) {
110108
// POST in Solid creates a child resource
111109
const parent = getParent(path)
112110
if (parent && method !== 'POST') {
113-
const parentID = res.setEventID(parent)
111+
res.setEventID({
112+
path: parent,
113+
id: eventID
114+
})
114115
const parentUrl = new URL(parent, fullUrl)
115116
try {
116117
trigger({
@@ -125,11 +126,10 @@ function handler (req, res, next) {
125126
if (ALLOWED_RDF_MIME_TYPES.includes(mediaType?.[0])) {
126127
return `${headerTemplate(negotiatedFields)}\r\n${solidRDFTemplate({
127128
activity,
128-
eventID: parentID,
129+
eventID,
129130
date: eventDate,
130131
object,
131132
target,
132-
eTag: undefined,
133133
mediaType
134134
})}`
135135
}

lib/rdf-notification-template.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
const uuid = require('uuid')
2+
13
const CONTEXT_ACTIVITYSTREAMS = 'https://www.w3.org/ns/activitystreams'
24
const CONTEXT_NOTIFICATION = 'https://www.w3.org/ns/solid/notification/v1'
35
const CONTEXT_XML_SCHEMA = 'http://www.w3.org/2001/XMLSchema'
46

57
function generateJSONNotification ({
68
activity: type,
7-
eventId: id,
9+
eventID,
810
date: published,
911
object,
1012
target,
@@ -13,30 +15,40 @@ function generateJSONNotification ({
1315
return {
1416
published,
1517
type,
16-
id,
18+
id: `urn:uuid:${uuid.v4()}`,
19+
...(eventID) && { state: eventID },
1720
object,
1821
...(type === 'Add') && { target },
19-
...(type === 'Remove') && { origin: target },
20-
...(state) && { state }
22+
...(type === 'Remove') && { origin: target }
2123
}
2224
}
2325

2426
function generateTurtleNotification ({
2527
activity,
26-
eventId,
28+
eventID,
2729
date,
2830
object,
29-
target,
30-
state = undefined
31+
target
3132
}) {
32-
const stateLine = `\n notify:state "${state}" ;`
33+
let targetLine = ''
34+
let stateLine = ''
35+
36+
if (activity === 'Add') {
37+
targetLine = `\n as:target ${target} ;`
38+
}
39+
if (activity === 'Remove') {
40+
targetLine = `\n as:origin ${target} ;`
41+
}
42+
if (eventID) {
43+
stateLine = `\n notify:state "${eventID}" ;`
44+
}
3345

3446
return `@prefix as: <${CONTEXT_ACTIVITYSTREAMS}#> .
3547
@prefix notify: <${CONTEXT_NOTIFICATION}#> .
3648
@prefix xsd: <${CONTEXT_XML_SCHEMA}#> .
3749
38-
<${eventId}> a as:${activity} ;${state && stateLine}
39-
as:object ${object} ;
50+
<urn:uuid:${uuid.v4()}> a as:${activity} ;
51+
as:object ${object} ;${targetLine}${stateLine}
4052
as:published "${date}"^^xsd:dateTime .`.replaceAll('\n', '\r\n')
4153
}
4254

0 commit comments

Comments
 (0)