node-red-contrib-friendly-id
A node for Node-RED that converts a given UUID to a URL-friendly ID(short-uuid). You can also generate secure ID using nanoid and short-uuid.
Installation
Run the following command in the root directory of your Node-RED install:
$ npm install node-red-contrib-friendly-id
Usage
from UUID / to UUID
Generate Friendly ID
v0.2.x migration [example flows]
In version 0.1.x
, the node was depend on a payload
property (msg.payload
).
In version 0.2.x
, Input / output can be specified, preventing node wiring from becoming complicated.
Okay, so let's walk through some use case scenarios...
Case 1:
How do I set a generatedshort-uuid
tomsg.myid
property while preserving the originalmsg.payload
property?
The expected values of each property are as follows:
{
_msgid: "********.*****",
payload: 1612274237107,
myid: "wGAYZWkGersMXj5KzA2vDU"
}
v0.1.x:
v0.2.x (migration)
[{"id":"a88c20f.676d3e","type":"debug","z":"f6f2187d.f17ca8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":450,"y":340,"wires":[]},{"id":"c04fc85.e6ef838","type":"friendly-id","z":"f6f2187d.f17ca8","name":"","mode":"GENERATE-SHORTID","charlen":21,"charset":"DEFAULT","customs":"","tostatus":false,"statusVal":"","statusType":"auto","inputFromVal":"","inputFromType":"auto","outputToVal":"myid","outputToType":"msg","x":300,"y":340,"wires":[["a88c20f.676d3e"]]},{"id":"68101c27.6c4f84","type":"inject","z":"f6f2187d.f17ca8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":340,"wires":[["c04fc85.e6ef838"]]}]
Case 2:
How do I directly overwrite the converted UUID to a property used for input?
v0.1.x:
v0.2.x (migration)
[{"id":"130a8293.06421d","type":"http response","z":"f6f2187d.f17ca8","name":"","statusCode":"","headers":{},"x":510,"y":380,"wires":[]},{"id":"283657c9.5e37d8","type":"friendly-id","z":"f6f2187d.f17ca8","name":"","mode":"DECODE","charlen":21,"charset":"DEFAULT","customs":"","tostatus":false,"statusVal":"","statusType":"auto","inputFromVal":"req.params.userid","inputFromType":"msg","outputToVal":"req.params.userid","outputToType":"msg","x":360,"y":380,"wires":[["19a63487.dc85bb","130a8293.06421d"]]},{"id":"92bdbc63.ac83f","type":"http in","z":"f6f2187d.f17ca8","name":"","url":"/api/v2/users/:userid","method":"get","upload":false,"swaggerDoc":"","x":150,"y":380,"wires":[["283657c9.5e37d8"]]},{"id":"19a63487.dc85bb","type":"debug","z":"f6f2187d.f17ca8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"req.params.userid","targetType":"msg","statusVal":"","statusType":"auto","x":560,"y":340,"wires":[]}]
Acknowledgements
This project uses the following open source software:
License
This project is released under the MIT License.