mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-13 02:58:11 +00:00
feat(actions): add "zitadel/uuid" module (#6135)
* feat: add "zitadel/uuid" module * feat(actions/uuid): add v1, v3, and v4 UUIDs * add namespaces and improve hash based functions * add docs --------- Co-authored-by: Florian Forster <florian@zitadel.com> Co-authored-by: Livio Spring <livio.a@gmail.com>
This commit is contained in:
@@ -51,3 +51,58 @@ The object has the following fields and methods:
|
||||
Returns the body as JSON object, or throws an error if the body is not a json object.
|
||||
- `text()` *string*
|
||||
Returns the body
|
||||
|
||||
## UUID
|
||||
|
||||
This module provides functionality to generate a UUID
|
||||
|
||||
### Import
|
||||
|
||||
```js
|
||||
let uuid = require("zitadel/uuid")
|
||||
```
|
||||
|
||||
### `uuid.vX()` function
|
||||
|
||||
This function generates a UUID using [google/uuid](https://github.com/google/uuid). `vX` allows to define the UUID version:
|
||||
|
||||
- `uuid.v1()` *string*
|
||||
Generates a UUID version 1, based on date-time and MAC address
|
||||
- `uuid.v3(namespace, data)` *string*
|
||||
Generates a UUID version 3, based on the provided namespace using MD5
|
||||
- `uuid.v4()` *string*
|
||||
Generates a UUID version 4, which is randomly generated
|
||||
- `uuid.v5(namespace, data)` *string*
|
||||
Generates a UUID version 5, based on the provided namespace using SHA1
|
||||
|
||||
#### Parameters
|
||||
|
||||
- `namespace` *UUID*/*string*
|
||||
Namespace to be used in the hashing function. Either provide one of defined [namespaces](#namespaces) or a string representing a UUID.
|
||||
- `data` *[]byte*/*string*
|
||||
data to be used in the hashing function. Possible types are []byte or string.
|
||||
|
||||
### Namespaces
|
||||
|
||||
The following predefined namespaces can be used for `uuid.v3` and `uuid.v5`:
|
||||
|
||||
- `uuid.namespaceDNS` *UUID*
|
||||
6ba7b810-9dad-11d1-80b4-00c04fd430c8
|
||||
- `uuid.namespaceURL` *UUID*
|
||||
6ba7b811-9dad-11d1-80b4-00c04fd430c8
|
||||
- `uuid.namespaceOID` *UUID*
|
||||
6ba7b812-9dad-11d1-80b4-00c04fd430c8
|
||||
- `uuid.namespaceX500` *UUID*
|
||||
6ba7b814-9dad-11d1-80b4-00c04fd430c8
|
||||
|
||||
### Example
|
||||
```js
|
||||
let uuid = require("zitadel/uuid")
|
||||
function setUUID(ctx, api) {
|
||||
if (api.metadata === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
api.v1.user.appendMetadata('custom-id', uuid.v4());
|
||||
}
|
||||
```
|
Reference in New Issue
Block a user