Coder Social home page Coder Social logo

vandie / webmention-handler Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 2.0 192 KB

A handler for web mentions

Home Page: https://www.npmjs.com/package/webmention-handler

License: MIT License

JavaScript 0.91% TypeScript 85.64% HTML 13.29% Shell 0.16%
indieweb javascript nodejs nodejs-modules typescript typescript-definitions webmention webmentions

webmention-handler's Introduction

M W Van Der Velden - Lead Backend Developer

Hi All, I'm Michael Walter Van Der Velden! (He/Him)

I work on various JS, TS, C and Rust Projects. Some even go somewhere. I'm currently working as a senior developer at Pretty Little Thing. Most of my personal projects get documented on my blog. Below you can find a dynamic image and link to the latest post on my blog as well as some other key links about myself. Feel free to reach out, I try to help people out where I can. For the sake of being open, I also list the full stack of my portfolio.

latest blog post

Key Links

mikevdv.dev mikevdv.dev/blog Rss @mvd_vandie on Twitter


Portfolio Tech

Svelte TypeScript DigitalOcean MongoDB Google Cloud Cloudflare

webmention-handler's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar paulrobertlloyd avatar vandie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

webmention-handler's Issues

Create Mongo DB Storage Implementation

There is a working mongoDB Storage implementation in use on mikevdv.dev but it needs to cleaned up before general release. For a 0.1.0 release of the library, at least one real database implementation should exist.

`type` property in normalised JF2 objects shouldn’t start with `h-*`

I’m using node-webmention-testpinger to test receiving different webmentions. Using getMentionsForPage function, normalised JF2 objects are returned, however the type properties are not updated. For example:

  {
    "_id": "654e84d696b0ce7d163081bb",
    "source": "http://127.0.0.1:8080/template?name=checkmention-hcardxss&target=https%3A%2F%2Findiekit-sandbox.netlify.app%2Fnotes%2F2023%2F11%2F10%2Fvdwqk",
    "target": "https://indiekit-sandbox.netlify.app/notes/2023/11/10/vdwqk",
    "parsed": "2023-11-10T19:30:30.045Z",
    "type": "reply",
    "in-reply-to": {
-     "type": "h-cite",
+     "type": "cite",
      "value": "https://indiekit-sandbox.netlify.app/notes/2023/11/10/vdwqk",
      "name": "this page",
      "url": "https://indiekit-sandbox.netlify.app/notes/2023/11/10/vdwqk"
    },
    "author": {
-     "type": "h-card",
+     "type": "card",
      "value": "Does clicking me alert?",
      "photo": "http://127.0.0.1:8080/static/img/q.jpg",
      "name": "Does clicking me alert?",
      "url": "javascript:alert('hcard')"
    },
    "name": "This test embeds XSS within the hcard name and time field. Clicking on\nthe name or title should not raise an alert.",
    "content": {
      "value": "This test embeds XSS within the hcard name and time field. Clicking on\nthe name or title should not raise an alert.",
      "html": "This test embeds XSS within the hcard name and time field. Clicking on\nthe name or title should not raise an alert."
    },
    "published": "%%time"
  }

I think this is right, am going by: https://jf2.spec.indieweb.org/#post-objects

Increase Test Coverage

A lot of the smaller functions have tests already. The two main classes however are missing some much needed tests.

`LocalWebMentionStorage` is not exported from package

Describe the bug

In the readme, under the Setup heading it is suggested that example storage adapter can be imported as follows:

import { localWebMentionStorage } from 'webmention-handler';

const storage = new LocalWebMentionStorage();

I’ve corrected a typo in #17 to update the import to reference LocalWebMentionStorage (capital ‘L’ as it is named in the module), but this function is not exported. It’s unclear from the documentation if this is intended to be exported or not, as later in the readme this function is linked to instead:

An example storage handler can be found in the [local storage class](https://github.com/vandie/webmention-handler/blob/main/src/classes/local-web-mention-storage.class.ts).

Store webmentions using a known serialisation format

Using getMentionsForPage, normalised objects are returned, but not in a specified or common format.

Mention data is currently normalised in a format that approximates JF2, but not for deeply nested properties, and uses non-standard values for type. This means it is not possible to query processed mentions, return mention data and convert it to a different format.

The use case for being able to covert mention data to different formats can be seen in indieweb/webmention-ecosystem#2, where there is a desire to return mentions with either mf2, JF2 or JSON Feed serialisations. I’d like to return mentions as JF2, at least initially, and potentially other formats in the future.

Unfortunately, the object normalisation takes place when mentions are processed, with the original mf2 parsing discarded. This means it's not possible to convert the mention data to JF2 (or mf2) with libraries that parse mf2, or without employing additional processing to convert the current serialisation to adhere to JF2.

Potential options

  • Store mf2 when processing mentions, and only do the conversion when using getMentionsForPage.
  • Use JF2 when processing mentions, and ensure the normalisation follows that specification.
  • Provide an option at the handler level to determine which serialisation format mentions are stored to the database with OR provide an option on the getMentionsForPage function to return a desired format (mf2 or JF2).

It would be useful to have a function to return all processed mentions, not just those for a given target, but I will create a separate PR for that.

Improve webmention types

At the moment all mentions are stored as the type Mention, it would be nice to have Types for the different mention structures (Reply, Like etc.) with the regular Mention acting as a fallback. This might require a lot of optional fields but I think it would help people implementing the library for the first time.

Like duplication

Currently, it is possible for the same domain to send multiple likes to the handler and them both be processed. While this is perfectly acceptable, they can also be from the same author which can lead to multiple likes from the same user appearing next to one another.

This is especially an issue when using Bridgy to handle social media likes where a user can like the page using multiple sites that link back to their primary web domain. That web domain then provides an author object which is the same for both likes. This can happen (in an even more troubling manner) when receiving likes from Twitter as these can be duplicated due to the same user liking multiple tweets that act as substitutes for the same web page. In this case the likes are almost identical but still have a different source and therefore cannot be de-duplicated.

While the official web mention spec doesn't offer a solution to this issue, and therfore it may be out of scope. It seems like this should be handled or at very least, documentation should be added that explains the limitation and offers suggestions on how to solve it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.