-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic prep #1792
Merged
Merged
Basic prep #1792
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
21b15be
feat: PREP Notifications
CxRes f4fb5a0
feat: Add Solid-PREP Notifications
CxRes 109ce09
Bump CI and Docker to node v22
CxRes 7b23e57
Replace nyc with c8
CxRes 3d93e13
fix: Correct Parenting for Solid-PREP Notifications
CxRes fd99081
Step Down to Node 20
CxRes 8021633
fix: Relax Content-Type Checks in Integration Tests
CxRes e0ebc31
fix: Repository for Surface Tests
CxRes beaaa03
chore: Bump Express PREP
CxRes bda034a
feat: Add Tests for PREP
CxRes b0e7eb0
feat: Add Flag to disable PREP
CxRes 6a287e4
refactor: Remove Commented Code in `get.js`
CxRes a6067e3
chore: Bump PREP Dependencies
CxRes 568b58a
fix: Send Parent Notifications on Root
CxRes 3fa2be9
fix: Activity is `as:Add` on Container POST
CxRes 6f4b22b
fix: Set `target` on Container POST
CxRes 2a277ff
fix: Set `origin` when Contained Resource is Removed
CxRes d08a88f
test: Notification when Creating a Container with POST
CxRes 33997ae
chore: Bump Express PREP
CxRes 1f6c16f
fix: Do Not Overwrite `req.url` on Container PUT
CxRes c933a74
test: Notification when Creating/Deleting Container in Container
CxRes 2da77b0
refactor: Add Debugging for Failed Notifications
CxRes 44dc0bc
fix: Correctly Set Location on non-RDF Notifications
CxRes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,17 +17,30 @@ jobs: | |
|
||
strategy: | ||
matrix: | ||
node-version: [18.x] | ||
node-version: [ '>=20.17.0' ] | ||
os: [ubuntu-latest] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v4 | ||
|
||
# extract repository name | ||
- if: github.event_name == 'pull_request' | ||
run: echo "REPO_NAME=${{ github.event.pull_request.head.repo.full_name }}" >> $GITHUB_ENV | ||
|
||
- if: github.event_name != 'pull_request' | ||
run: echo "REPO_NAME=${GITHUB_REPOSITORY}" >> $GITHUB_ENV | ||
|
||
# extract branch name | ||
- if: github.event_name == 'pull_request' | ||
run: echo "BRANCH_NAME=${GITHUB_HEAD_REF}" >> $GITHUB_ENV | ||
|
||
- if: github.event_name != 'pull_request' | ||
run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV | ||
|
||
# print repository name | ||
- name: Get repository name | ||
run: echo 'The repository name is' $REPO_NAME | ||
|
||
# print branch name | ||
- name: Get branch name | ||
run: echo 'The branch name is' $BRANCH_NAME | ||
|
@@ -40,12 +53,12 @@ jobs: | |
# test code | ||
- run: npm run standard | ||
- run: npm run validate | ||
- run: npm run nyc | ||
- run: npm run c8 | ||
# Test global install of the package | ||
- run: npm pack . | ||
- run: npm install -g solid-server-*.tgz | ||
# Run the Solid test-suite | ||
- run: bash test/surface/run-solid-test-suite.sh $BRANCH_NAME | ||
- run: bash test/surface/run-solid-test-suite.sh $BRANCH_NAME $REPO_NAME | ||
|
||
# TODO: The pipeline should automate publication to npm, so that the docker build gets the correct version | ||
# This job will only dockerize solid-server@latest / solid-server@<tag-name> from npmjs.com! | ||
|
@@ -56,7 +69,7 @@ jobs: | |
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: olegtarasov/[email protected] | ||
id: tagName | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/usr/bin/env node | ||
#!/usr/bin/env -S node --experimental-require-module | ||
const startCli = require('./lib/cli') | ||
startCli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/usr/bin/env node | ||
#!/usr/bin/env -S node --experimental-require-module | ||
const startCli = require('./lib/cli') | ||
startCli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM node:16-alpine | ||
FROM node:20-alpine | ||
|
||
# hadolint ignore=DL3018 | ||
RUN apk add --no-cache openssl | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
module.exports = handler | ||
|
||
const libPath = require('path/posix') | ||
|
||
const headerTemplate = require('express-prep/templates').header | ||
const solidRDFTemplate = require('../rdf-notification-template') | ||
|
||
const ALLOWED_RDF_MIME_TYPES = [ | ||
'application/ld+json', | ||
'application/activity+json', | ||
'text/turtle' | ||
] | ||
|
||
function getParent (path) { | ||
if (path === '' || path === '/') return | ||
const parent = libPath.dirname(path) | ||
if (parent === '/') return | ||
return `${parent}/` | ||
} | ||
|
||
function getActivity (method) { | ||
if (method === 'DELETE') { | ||
return 'Delete' | ||
} | ||
return 'Update' | ||
} | ||
|
||
function getParentActivity (method, status) { | ||
if (method === 'DELETE') { | ||
return 'Remove' | ||
} | ||
if (status === 201) { | ||
return 'Add' | ||
} | ||
return 'Update' | ||
} | ||
|
||
function handler (req, res, next) { | ||
const { trigger, defaultNotification } = res.events.prep | ||
|
||
const { method } = req | ||
const { statusCode } = res | ||
const eventID = res.getHeader('event-id') | ||
const fullUrl = new URL(req.path, `${req.protocol}://${req.hostname}/`) | ||
|
||
// Date is a hack since node does not seem to provide access to send date. | ||
// Date needs to be shared with parent notification | ||
const eventDate = res._header.match(/^Date: (.*?)$/m)?.[1] || | ||
new Date().toUTCString() | ||
|
||
// If the resource itself newly created, | ||
// it could not have been subscribed for notifications already | ||
if (!((method === 'PUT' || method === 'PATCH') && statusCode === 201)) { | ||
try { | ||
trigger({ | ||
generateNotification ( | ||
negotiatedFields | ||
) { | ||
const mediaType = negotiatedFields['content-type'] | ||
|
||
if (ALLOWED_RDF_MIME_TYPES.includes(mediaType?.[0])) { | ||
return `${headerTemplate(negotiatedFields)}\r\n${solidRDFTemplate({ | ||
activity: getActivity(method), | ||
eventID, | ||
object: String(fullUrl), | ||
date: eventDate, | ||
// We use eTag as a proxy for state for now | ||
state: res.getHeader('ETag'), | ||
mediaType | ||
})}` | ||
} else { | ||
return defaultNotification({ | ||
...(res.method === 'POST') && { location: res.getHeader('Content-Location') } | ||
}) | ||
} | ||
} | ||
}) | ||
} catch (error) { | ||
// Failed notification message | ||
CxRes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
// Write a notification to parent container | ||
// POST in Solid creates a child resource | ||
const parent = getParent(req.path) | ||
if (parent && method !== 'POST') { | ||
try { | ||
const parentID = res.setEventID(parent) | ||
const parentUrl = new URL(parent, fullUrl) | ||
trigger({ | ||
path: parent, | ||
generateNotification ( | ||
negotiatedFields | ||
) { | ||
const mediaType = negotiatedFields['content-type'] | ||
if (ALLOWED_RDF_MIME_TYPES.includes(mediaType?.[0])) { | ||
return `${headerTemplate(negotiatedFields)}\r\n${solidRDFTemplate({ | ||
activity: getParentActivity(method, statusCode), | ||
eventID: parentID, | ||
date: eventDate, | ||
object: String(parentUrl), | ||
target: statusCode === 201 ? String(fullUrl) : undefined, | ||
eTag: undefined, | ||
mediaType | ||
})}` | ||
} | ||
} | ||
}) | ||
} catch (error) { | ||
// Failed notification message | ||
} | ||
} | ||
|
||
next() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed because the middlewares for PREP use ESM syntax and NSS is CJS. This magic flag allows importing ESM code in CJS code.
This will also prove generally useful, since it creates a path to migrate NSS to ESM one file at a time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For context:
https://joyeecheung.github.io/blog/2024/03/18/require-esm-in-node-js/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the need to support your ESM middleware, but adding --experimental-require-module project-wide isn’t the best approach. Since it’s still experimental, it could introduce unpredictable behavior in different environments or future Node.js versions.
To ensure long-term stability and compatibility with the existing CJS modules, it’s better to bundle your libraries with a transpiler. This will let you use ESM without requiring the entire project to rely on an experimental flag