Modules
ZITADEL provides the following modules.
HTTP
This module provides functionality to call REST APIs.
Import
let http = require('zitadel/http')fetch() function
This function allows to call HTTP servers. The function does NOT fulfil the Fetch API specification.
Parameters
urlstringoptionsOptional, containing custom settings that you want to apply to the request.headersOverwrites the default headers. One of the following types- map[string] string
The value is split into separate values after each comma
,. - map[string] Array of string The value is a string array
- default:
Content-Type:application/jsonAccept:application/json
- map[string] string
The value is split into separate values after each comma
methodThe request method. Allowed values areGET,POST,PUT,DELETEbodyObject JSON representation
Response
If the request was invalid, an error will be thrown, otherwise a Response object will be returned.
The object has the following fields and methods:
statusnumber Status code of responsebodystring Return valuejson()Object Returns the body as JSON object, or throws an error if the body is not a json object.text()string Returns the body
Example
https://github.com/zitadel/actions/blob/main/examples/make_api_call.js#L10-L20Log
The log module provides you with the functionality to log to stdout.
Import
let logger = require("zitadel/log")log(), warn(), error() function
The logger offers three distinct log levels (info, warn, and error) to effectively communicate messages based on their severity, enhancing debugging and troubleshooting efficiency. Use the function that reflects your log level.
- log()
- warn()
- error()
Example
logger.log("This is an info log.")
logger.warn("This is a warn log.")
logger.error("This is an error log.")Parameters
msgstring The message you want to print out.
UUID
This module provides functionality to generate a UUID
Import
let uuid = require("zitadel/uuid")uuid.vX() function
This function generates a UUID using google/uuid. vX allows to define the UUID version:
uuid.v1()string Generates a UUID version 1, based on date-time and MAC addressuuid.v3(namespace, data)string Generates a UUID version 3, based on the provided namespace using MD5uuid.v4()string Generates a UUID version 4, which is randomly generateduuid.v5(namespace, data)string Generates a UUID version 5, based on the provided namespace using SHA1
Parameters
namespaceUUID/string Namespace to be used in the hashing function. Either provide one of defined 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.namespaceDNSUUID 6ba7b810-9dad-11d1-80b4-00c04fd430c8uuid.namespaceURLUUID 6ba7b811-9dad-11d1-80b4-00c04fd430c8uuid.namespaceOIDUUID 6ba7b812-9dad-11d1-80b4-00c04fd430c8uuid.namespaceX500UUID 6ba7b814-9dad-11d1-80b4-00c04fd430c8
Example
let uuid = require("zitadel/uuid")
function setUUID(ctx, api) {
if (api.metadata === undefined) {
return;
}
api.v1.user.appendMetadata('custom-id', uuid.v4());
}Was this page helpful?