本節提供 Blocklet Server 上所有與網路和服務相關的 GraphQL 查詢的詳細參考資料。這些方法可讓您擷取路由、網域、憑證、webhook 和通知的資料與設定。若需修改這些設定的操作,請參閱 網路與服務 Mutations 章節。
通知
用於管理和擷取通知的查詢。
getNotifications
根據指定的篩選條件擷取通知列表。
參數
- input
RequestGetNotificationsInput(required) — 一個包含篩選條件的物件。- receiver
string— 依通知接收者的 DID 篩選。 - sender
string— 依通知發送者的 DID 篩選。 - read
boolean— 依讀取狀態篩選。 - paging
PagingInput— 分頁選項。 - teamDid
string— 團隊/blocklet 的 DID。 - severity
string[]— 依嚴重性級別篩選(例如 'info'、'error')。 - componentDid
string[]— 依元件 DID 篩選。 - entityId
string[]— 依實體 ID 篩選。 - source
string[]— 依來源篩選(例如 'system'、'component')。
- receiver
返回
返回一個 Promise,其會解析為一個 ResponseGetNotifications 物件,其中包含通知列表和分頁詳細資訊。
請求範例
getNotifications Example
import BlockletServerClient from '@blocklet/server-js';
const client = new BlockletServerClient();
async function fetchUnreadNotifications() {
try {
const response = await client.getNotifications({
input: {
read: false,
paging: { pageSize: 10, page: 1 },
},
});
console.log('未讀通知:', response.list);
console.log('未讀計數:', response.unreadCount);
} catch (error) {
console.error('擷取通知時發生錯誤:', error);
}
}
fetchUnreadNotifications();回應範例
Response
{
"code": "ok",
"list": [
{
"id": "...",
"title": "有新的更新可用",
"description": "您的 blocklet 有新版本可供安裝。",
"read": false,
"createdAt": 1678886400
}
],
"paging": {
"total": 5,
"pageSize": 10,
"pageCount": 1,
"page": 1
},
"unreadCount": 5
}makeAllNotificationsAsRead
將所有符合指定條件的通知標記為已讀。
參數
- input
RequestMakeAllNotificationsAsReadInput(required) — 一個包含篩選條件的物件,用於指定要標記為已讀的通知。- receiver
string(required) — 通知接收者的 DID。 - teamDid
string— 團隊/blocklet 的 DID。 - severity
string— (可選)依特定嚴重性級別篩選。 - componentDid
string— (可選)依特定元件 DID 篩選。 - entityId
string— (可選)依特定實體 ID 篩選。 - source
string— (可選)依特定來源篩選。
- receiver
返回
返回一個 Promise,其會解析為一個 ResponseMakeAllNotificationsAsRead 物件,表示受影響的通知數量。
請求範例
makeAllNotificationsAsRead Example
import BlockletServerClient from '@blocklet/server-js';
const client = new BlockletServerClient();
async function markAllAsRead() {
try {
const response = await client.makeAllNotificationsAsRead({
input: { receiver: 'z8iZ...aYp' },
});
console.log(`已將 ${response.data.numAffected} 則通知標記為已讀。`);
} catch (error) {
console.error('將通知標記為已讀時發生錯誤:', error);
}
}
markAllAsRead();回應範例
Response
{
"code": "ok",
"data": {
"numAffected": 5,
"notificationIds": ["...", "..."]
}
}getNotificationSendLog
擷取通知的發送日誌,讓您可以追蹤不同管道的傳送狀態。
參數
- input
RequestNotificationSendLogInput(required) — 一個包含發送日誌篩選條件的物件。- teamDid
string(required) — 團隊/blocklet 的 DID。 - dateRange
string[]— 在特定日期範圍內篩選日誌(例如 ['2023-01-01', '2023-01-31'])。 - paging
PagingInput— 分頁選項。 - source
string— 依通知來源篩選。 - componentDids
string[]— 依元件 DID 陣列篩選。 - severities
string[]— 依嚴重性級別陣列篩選。
- teamDid
返回
返回一個 Promise,其會解析為一個 ResponseNotificationSendLog 物件,其中包含通知日誌列表和分頁詳細資訊。
getReceivers
根據各種篩選條件擷取通知接收者列表,例如他們在不同管道的發送狀態。
參數
- input
RequestReceiversInput(required) — 一個包含接收者篩選條件的物件。- teamDid
string(required) — 團隊/blocklet 的 DID。 - notificationId
string— 篩選特定通知的接收者。 - userName
string— 依接收者名稱搜尋。 - userDid
string— 依特定使用者 DID 篩選。 - walletSendStatus
number[]— 依錢包發送狀態碼篩選。 - pushKitSendStatus
number[]— 依推播通知發送狀態碼篩選。 - emailSendStatus
number[]— 依電子郵件發送狀態碼篩選。 - dateRange
string[]— 在特定日期範圍內篩選接收者。 - paging
PagingInput— 分頁選項。
- teamDid
返回
返回一個 Promise,其會解析為一個 ResponseReceivers 物件,其中包含接收者列表和分頁詳細資訊。
getNotificationComponents
擷取已發送通知的元件 DID 列表。
參數
- input
RequestNotificationComponentsInput(required) — 一個包含篩選條件的物件。- teamDid
string(required) — 團隊/blocklet 的 DID。 - receiver
string— 依通知接收者的 DID 篩選。
- teamDid
返回
返回一個 Promise,其會解析為一個 ResponseNotificationComponents 物件,其中包含一個元件 DID 陣列。
resendNotification
觸發將特定通知重新發送給指定的接收者和管道。
參數
- input
RequestResendNotificationInput(required) — 一個包含重新發送操作詳細資訊的物件。- teamDid
string(required) — 團隊/blocklet 的 DID。 - notificationId
string(required) — 要重新發送的通知 ID。 - receivers
string[]— 要重新發送通知的使用者 DID 列表。 - channels
string[]— 用於重新發送的管道列表(例如 'wallet'、'email')。 - webhookUrls
string[]— 要重新發送到的特定 webhook URL 列表。 - resendFailedOnly
boolean— 若為 true,則僅重新發送給先前接收通知失敗的接收者。
- teamDid
返回
返回一個 Promise,其會解析為一個 ResponseResendNotification 物件。
路由與網域
用於管理路由規則和網域設定的查詢。
getRoutingSites
擷取所有已設定的路由站點列表。
參數
- input
RequestGetRoutingSitesInput— 一個包含篩選條件的物件。- snapshotHash
string— (可選)如果提供,則從特定的歷史快照中擷取路由站點。
- snapshotHash
返回
返回一個 Promise,其會解析為一個 ResponseGetRoutingSites 物件,其中包含一個 RoutingSite 物件陣列。
請求範例
getRoutingSites Example
import BlockletServerClient from '@blocklet/server-js';
const client = new BlockletServerClient();
async function fetchRoutingSites() {
try {
const response = await client.getRoutingSites();
console.log('路由站點:', response.sites);
} catch (error) {
console.error('擷取路由站點時發生錯誤:', error);
}
}
fetchRoutingSites();回應範例
Response
{
"code": "ok",
"sites": [
{
"id": "...",
"domain": "example.com",
"domainAliases": [{"value": "www.example.com"}],
"rules": [/* ... */]
}
]
}getRoutingSnapshots
擷取路由設定的歷史快照列表。
參數
- input
RequestGetRoutingSnapshotsInput— 一個包含篩選條件的物件。- limit
number— 要返回的最大快照數量。
- limit
返回
返回一個 Promise,其會解析為一個 ResponseGetRoutingSnapshots 物件,其中包含一個 RoutingSnapshot 物件陣列。
getSnapshotSites
從指定的快照雜湊值中擷取路由站點。
參數
- input
RequestGetSnapshotSitesInput(required) — 一個包含快照雜湊值的物件。- hash
string(required) — 要擷取的快照雜湊值。
- hash
返回
返回一個 Promise,其會解析為一個 ResponseGetSnapshotSites 物件,其中包含來自該快照的 RoutingSite 物件陣列。
getRoutingProviders
擷取可用的路由提供者(例如 Nginx)及其目前狀態的列表。
返回
返回一個 Promise,其會解析為一個 ResponseGetRoutingProviders 物件,其中包含一個 RoutingProvider 物件陣列。
isDidDomain
檢查給定的網域是否為基於 DID 的網域。
參數
- input
RequestIsDidDomainInput(required)- domain
string(required) — 要檢查的網域。
- domain
返回
返回一個 Promise,其會解析為一個 ResponseIsDidDomain 物件,其中包含一個布林值 value,表示結果。
getDomainDNS
檢查給定網域的 DNS 解析狀態,驗證其是否正確指向 Blocklet Server。
參數
- input
RequestDomainDNSInput(required)- teamDid
string(required) — 與網域關聯的團隊/blocklet 的 DID。 - domain
string(required) — 要檢查的網域。
- teamDid
返回
返回一個 Promise,其會解析為一個 ResponseDomainDNS 物件,詳細說明 DNS 狀態。
憑證
用於管理 SSL/TLS 憑證的查詢。
getCertificates
擷取節點上安裝的所有 SSL 憑證。
返回
返回一個 Promise,其會解析為一個 ResponseGetCertificates 物件,其中包含一個 Certificate 物件陣列。
請求範例
getCertificates Example
import BlockletServerClient from '@blocklet/server-js';
const client = new BlockletServerClient();
async function listCertificates() {
try {
const response = await client.getCertificates();
console.log('已安裝的憑證:', response.certificates);
} catch (error) {
console.error('擷取憑證時發生錯誤:', error);
}
}
listCertificates();回應範例
Response
{
"code": "ok",
"certificates": [
{
"id": "...",
"name": "example.com-cert",
"domain": "example.com",
"source": "letsencrypt",
"status": "valid"
}
]
}findCertificateByDomain
依據關聯的網域名稱尋找特定憑證。
參數
- input
RequestFindCertificateByDomainInput(required)- domain
string(required) — 與憑證關聯的網域名稱。 - did
string— (可選)blocklet 的 DID,以縮小搜尋範圍。
- domain
返回
返回一個 Promise,其會解析為一個 ResponseFindCertificateByDomain 物件,如果找到,則包含 Certificate。
checkDomains
一次性檢查多個網域的狀態和有效性,通常在簽發憑證前使用。
參數
- input
RequestCheckDomainsInput(required)- domains
string[](required) — 要檢查的網域名稱陣列。 - did
string— (可選)blocklet 的 DID。
- domains
返回
返回一個 Promise,其會解析為一個 ResponseCheckDomains 物件,表示檢查的狀態。
Webhooks
用於管理 webhook 及其發送者的查詢。
getWebHooks
擷取所有已設定的 webhook 列表。
返回
返回一個 Promise,其會解析為一個 ResponseWebHooks 物件,其中包含一個 WebHook 物件陣列。
請求範例
getWebHooks Example
import BlockletServerClient from '@blocklet/server-js';
const client = new BlockletServerClient();
async function listWebhooks() {
try {
const response = await client.getWebHooks();
console.log('已設定的 webhook:', response.webhooks);
} catch (error) {
console.error('擷取 webhook 時發生錯誤:', error);
}
}
listWebhooks();回應範例
Response
{
"code": "ok",
"webhooks": [
{
"id": "...",
"type": "slack",
"params": [{"name": "url", "value": "https://hooks.slack.com/..."}]
}
]
}getWebhookSenders
擷取可用的 webhook 發送者類型(例如 Slack、API)及其所需參數的列表。
返回
返回一個 Promise,其會解析為一個 ResponseSenderList 物件,其中包含一個 WebHookSender 物件陣列。
sendTestMessage
向指定的 webhook 發送測試訊息以驗證其設定。
參數
- input
RequestSendMsgInput(required)- webhookId
string(required) — 要測試的 webhook 的 ID。 - message
string(required) — 測試訊息內容。
- webhookId
返回
返回一個 Promise,其會解析為一個 ResponseSendMsg 物件,表示操作的結果。
getWebhookEndpoints
擷取已設定的 webhook 端點的分頁列表。
參數
- input
RequestGetWebhookEndpointsInput(required)- teamDid
string(required) — 團隊/blocklet 的 DID。 - paging
PagingInput— 分頁選項。
- teamDid
返回
返回一個 Promise,其會解析為一個 ResponseGetWebhookEndpoints 物件。
getWebhookEndpoint
依 ID 擷取單一 webhook 端點。
參數
- input
RequestGetWebhookEndpointInput(required)- teamDid
string(required) — 團隊/blocklet 的 DID。 - id
string(required) — webhook 端點的 ID。
- teamDid
返回
返回一個 Promise,其會解析為一個 ResponseGetWebhookEndpoint 物件。
getWebhookAttempts
擷取特定 webhook 事件的傳送嘗試歷史記錄。
參數
- input
RequestGetWebhookAttemptsInput(required)- teamDid
string(required) — 團隊/blocklet 的 DID。 - input
RequestAttemptIdInput(required) — 包含 eventId 和 webhookId 的物件。- eventId
string(required) — 事件的 ID。 - webhookId
string(required) — webhook 的 ID。
- eventId
- paging
PagingInput— 分頁選項。
- teamDid
返回
返回一個 Promise,其會解析為一個 ResponseGetWebhookAttempts 物件。
您現在已經看過管理網路與服務的查詢。要探索如何擷取與備份、日誌和分析相關的資料,請前往 資料與操作 章節。