Constants & Types
This section provides an overview of the fundamental constants and type definitions used throughout the Blocklet SDK and the broader Blocklet Server ecosystem. Understanding these shared definitions is crucial for ensuring data consistency, enabling robust interactions, and developing applications that seamlessly integrate with the Blocklet platform. These definitions serve as the backbone for various SDK functionalities, including data structures for Blocklets, users, notifications, and server configurations.
Core Constants#
Constants define fixed values used across the Blocklet ecosystem, ensuring predictable behavior and clear communication. These often represent status codes, types, or prefixes.
Service Prefix#
The SERVICE_PREFIX
defines a standard URL path prefix used for well-known services within the Blocklet Server. This ensures consistent routing and access to core functionalities.
Name | Type | Description |
---|---|---|
|
| The base path for well-known Blocklet services, typically |
Enumerated Maps#
The Blocklet Server utilizes several enumerated maps to represent predefined sets of integer values for various statuses, types, and match conditions. These maps provide clear, symbolic names for numerical codes, improving readability and maintainability.
StatusCodeMap
Defines standard HTTP-like status codes for RPC responses.
Name | Value |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
BlockletStatusMap
Describes the various lifecycle statuses a Blocklet can be in on the Blocklet Server.
Name | Value |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BackendServiceTypeMap
Defines the types of backend services that can be configured for routing within the Blocklet Server.
Name | Value |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NotificationAttachmentTypeMap
Specifies the different types of content that can be included as attachments in Blocklet notifications.
Name | Value |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HeaderMatchTypeMap
Defines how HTTP header values are matched in routing rules.
Name | Value |
---|---|
|
|
|
|
|
|
PublishTypeMap
Indicates the type of project being published (e.g., a resource or a complete Blocklet package).
Name | Value |
---|---|
|
|
|
|
ReleaseStatusMap
Describes the status of a Blocklet release within the publishing workflow.
Name | Value |
---|---|
|
|
|
|
Key Data Types#
These types define the structure of data objects exchanged between the Blocklet SDK and the Blocklet Server, ensuring type safety and clarity in application development.
TNodeState#
Represents the overall state and configuration of a Blocklet Server instance.
Property | Type | Description |
---|---|---|
|
| The Decentralized Identifier of the Blocklet Server. |
|
| The public key of the Blocklet Server. |
|
| The current software version of the Blocklet Server. |
|
| The user-friendly name of the Blocklet Server. |
|
| A description of the Blocklet Server. |
|
| The port on which the Blocklet Server is running. |
|
| Indicates if the Blocklet Server has completed its initial setup. |
|
| Information about the owner's wallet, if set. |
|
| Timestamp of when the Blocklet Server was created. |
|
| Timestamp of when the Blocklet Server was last started. |
|
| Timestamp of when the Blocklet Server was initialized. |
|
| The operational mode of the Blocklet Server (e.g., 'production', 'development'). |
|
| Details about the server's routing configuration. |
|
| List of environment variables configured for the server. |
|
| The uptime of the Blocklet Server in seconds. |
|
| Indicates if automatic upgrades are enabled. |
|
| The next version available for upgrade. |
|
| Session ID for ongoing upgrades. |
|
| URL for registering the Blocklet Server. |
|
| Indicates if the welcome page is enabled. |
|
| URL for the web-based DID Wallet. |
|
| List of Blocklet Stores connected to the server. |
|
| Information about the owner's NFT. |
|
| Disk space usage threshold for alerts. |
|
| List of trusted DID Passport issuers. |
|
| Information about the Blocklet Launcher. |
|
| Indicates if DID Passport issuance is enabled. |
|
| The DID registry used by the server. |
|
| The DID Domain associated with the server. |
|
| Numeric status code of the server. |
|
| List of trusted NFT factories. |
|
| Indicates if beta releases are enabled. |
|
| Runtime configuration settings for the node. |
|
| URL for NFT domains. |
|
| Indicates if file system isolation is enabled. |
|
| Indicates if Docker integration is enabled. |
|
| Indicates if Docker is installed. |
|
| Indicates if Docker network is enabled. |
|
| Indicates if session hardening is enabled. |
|
| Salt used for session hardening. |
TBlockletMeta#
Contains the static metadata and descriptive information about a Blocklet, typically found in its blocklet.json
file.
Property | Type | Description |
---|---|---|
|
| The DID of the Blocklet. |
|
| The internal name of the Blocklet. |
|
| The version of the Blocklet. |
|
| A brief description of the Blocklet. |
|
| Definitions of interfaces exposed by the Blocklet. |
|
| Information about the Blocklet's author. |
|
| The main entry point file for the Blocklet. |
|
| Download, star, and purchase statistics for the Blocklet. |
|
| The homepage URL of the Blocklet. |
|
| The file path to the Blocklet. |
|
| URL for the Blocklet's community support. |
|
| URL for the Blocklet's documentation. |
|
| URL for the Blocklet's support page. |
|
| URLs to screenshots of the Blocklet. |
|
| Keywords associated with the Blocklet. |
|
| The group the Blocklet belongs to. |
|
| URL to the Blocklet's logo. |
|
| The display title of the Blocklet. |
|
| Distribution information (tarball URL, integrity hash). |
|
| List of Blocklet maintainers. |
|
| List of Blocklet contributors. |
|
| Repository information for the Blocklet. |
|
| Payment configuration for the Blocklet. |
|
| The NFT factory associated with the Blocklet. |
|
| Timestamp of the last publication. |
|
| Capabilities supported by the Blocklet. |
|
| Child components required by this Blocklet. |
|
| Environment variables required by the Blocklet. |
|
| System requirements for the Blocklet. |
|
| DID of the bundle this Blocklet belongs to. |
|
| Name of the bundle this Blocklet belongs to. |
|
| Navigation items for the Blocklet. |
|
| List of resources provided by the Blocklet. |
|
| Detailed resource export configuration. |
|
| Engine specific configuration. |
|
| Owner information. |
|
| Docker specific metadata. |
|
| Events emitted by the Blocklet. |
TBlockletState#
Represents the dynamic runtime state of a deployed Blocklet on the Blocklet Server, including its status, configurations, and resource usage.
Property | Type | Description |
---|---|---|
|
| The static metadata of the Blocklet. |
|
| The current operational status (e.g., |
|
| Timestamp when the Blocklet was added to the server. |
|
| Timestamp when the Blocklet was installed. |
|
| Timestamp when the Blocklet was last started. |
|
| Timestamp when the Blocklet was last paused. |
|
| Timestamp when the Blocklet was last stopped. |
|
| Timestamp when the Blocklet was last updated. |
|
| Runtime environment variables. |
|
| Runtime configuration entries. |
|
| Disk usage information. |
|
| Runtime process information (PID, memory, CPU). |
|
| Runtime information specific to the Blocklet application. |
|
| The source from which the Blocklet was deployed. |
|
| Origin of the deployment. |
|
| Source of the Blocklet bundle. |
|
| The network port the Blocklet is exposed on. |
|
| Information about the Blocklet's runtime engine. |
|
| Operational mode of the Blocklet. |
|
| Mapped ports for the Blocklet. |
|
| State of child components. |
|
| State of optional components. |
|
| Trusted DID Passports for the Blocklet. |
|
| Trusted NFT factories for the Blocklet. |
|
| Indicates if DID Passport issuance is enabled for this Blocklet. |
|
| Indicates if the Blocklet is dynamically deployed. |
|
| The URL mount point for the Blocklet. |
|
| Blocklet-specific settings. |
|
| The application DID of the Blocklet. |
|
| Routing site configuration for the Blocklet. |
|
| Controller information for the Blocklet. |
|
| Records of migrations. |
|
| Permanent ID of the Blocklet application. |
|
| Indicates if an external secret key is used. |
|
| Source of the external secret key. |
|
| Structure version of the Blocklet. |
|
| Indicates if Docker is enabled for the Blocklet. |
|
| Indicates if Docker network is enabled for the Blocklet. |
|
| Vault records associated with the Blocklet. |
Here's a diagram illustrating the composition of TBlockletState
:
TNotification#
Defines the structure of a notification message, including sender, receiver, content, and associated actions or attachments, used by the Notifications Service.
Property | Type | Description |
---|---|---|
|
| The DID of the entity sending the notification. |
|
| The DID of the intended recipient. |
|
| The title of the notification. |
|
| A detailed description or body of the notification. |
|
| A primary action associated with the notification (deprecated, use |
|
| The type of entity the notification is about. |
|
| The ID of the entity the notification is about. |
|
| Indicates if the notification has been read. |
|
| Timestamp when the notification was created. |
|
| Unique identifier for the notification. |
|
| The severity level of the notification (e.g., |
|
| The source of the notification (e.g., |
|
| List of rich content attachments (deprecated, use |
|
| Structured content blocks for rich notifications. |
|
| List of actionable buttons or links within the notification. |
|
| The DID of the Blocklet component that generated the notification. |
|
| The type of notification (e.g., |
|
| Detailed information about each receiver and their send status. |
|
| Additional arbitrary data associated with the notification. |
|
| Specific type for feed-style notifications. |
|
| Statistics related to sending the notification across channels. |
|
| Activity details for activity-type notifications. |
|
| Information about the actor involved in the notification activity. |
Here's a diagram illustrating the composition of TNotification
:
TUserInfo#
Defines the comprehensive profile information for a user within the Blocklet Server, including DID, roles, and connected accounts.
Property | Type | Description |
---|---|---|
|
| The user's DID. |
|
| The user's public key. |
|
| The user's assigned role. |
|
| URL to the user's avatar image. |
|
| The user's full name. |
|
| The user's email address. |
|
| Indicates if the user is approved. |
|
| Timestamp when the user account was created. |
|
| Timestamp when the user account was last updated. |
|
| The user's preferred locale. |
|
| List of DID Passports associated with the user. |
|
| Timestamp of the user's first login. |
|
| Timestamp of the user's last login. |
|
| Any remarks about the user. |
|
| The IP address from which the user last logged in. |
|
| The identity provider used for the user's last login. |
|
| The permanent application ID from which the user originated. |
|
| List of connected external accounts (e.g., social logins). |
|
| Additional custom data. |
|
| Tags associated with the user. |
|
| Information about the user's DID Space. |
|
| List of active user sessions. |
|
| The user's profile URL. |
|
| The user's phone number. |
|
| The DID of the user who invited this user. |
|
| The generation level of the user (e.g., in a referral hierarchy). |
|
| Indicates if the user's email is verified. |
|
| Indicates if the user's phone number is verified. |
|
| Additional metadata about the user (bio, location, links, etc.). |
|
| The user's physical address information. |
|
| The total count of user sessions. |
TRoutingRule#
Defines a single routing rule used by the Blocklet Server's routing engine to direct incoming requests.
Property | Type | Description |
---|---|---|
|
| Unique identifier for the routing rule. |
|
| Specifies the conditions for matching incoming requests (path, headers). |
|
| Defines where the matched request should be routed (port, type, DID, URL, etc.). |
|
| Indicates if the rule is protected and cannot be easily modified or deleted. |
TPaging#
A standard type used for pagination metadata in API responses, providing information about the total number of items, page size, and current page.
Property | Type | Description |
---|---|---|
|
| The total number of items available. |
|
| The maximum number of items per page. |
|
| The total number of pages. |
|
| The current page number. |
Validation Schemas as Type Definitions#
Beyond explicit TypeScript interfaces, the Blocklet SDK utilizes Joi validation schemas (found in src/validators
) to define the expected structure and constraints of data. These schemas effectively act as runtime type definitions for inputs to various API methods, ensuring data integrity.
Notification Validation Constants#
The notification.ts
validator defines several constant objects that mirror the enumerated maps, providing string representations for notification-related types, severities, and attachment types. These are used for validation and consistency.
NOTIFICATION_TYPES
Name | Value |
---|---|
|
|
|
|
|
|
|
|
|
|
SEVERITIES
Name | Value |
---|---|
|
|
|
|
|
|
|
|
ATTACHMENT_TYPES
Name | Value |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ACTIVITY_TYPES
Name | Value |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ACTIVITY_TARGET_TYPES
Name | Value |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Schema Examples#
Validators like notificationSchema
and eventSchema
define the detailed structure for TNotification
and TEvent
objects, respectively. They ensure that data conforms to the expected format before being processed by the SDK or Blocklet Server.
For instance, notificationSchema
validates the comprehensive structure of a TNotification
object:
const notificationSchema = Joi.object({
type: Joi.string().valid(...Object.values(TYPES)),
id: Joi.string().optional(),
feedType: Joi.string(),
passthroughType: Joi.string(),
data: Joi.object(),
url: Joi.string().uri(),
checkUrl: Joi.string(),
source: Joi.string(),
title: Joi.string().allow(''),
body: Joi.string(),
severity: Joi.string().valid(...Object.values(SEVERITIES)),
blocks: Joi.array().items(attachmentSchema).default([]),
attachments: Joi.array().items(attachmentSchema).default([]),
actions: Joi.array().items(actionSchema).default([]),
appInfo: Joi.object().optional(),
poweredBy: Joi.object().optional(),
activity: notificationActivitySchema.optional(),
}).required().meta({ className: 'TNotification' });
This schema, along with others, defines the precise properties and their validation rules, acting as a definitive guide for developers on the expected data structures.
By leveraging these shared constants and type definitions, Blocklet applications can maintain high levels of data consistency and interoperability within the Blocklet Server ecosystem. These foundational elements are critical for building reliable and scalable decentralized applications.
To see how these types are put into practice, explore the Notifications and Auth Service documentation.