Files
larksuite__cli/internal/output/envelope.go
liangshuo-1 2a1613484a feat: add framework flag aliases and unified IM pagination (#2146)
* feat: add framework flag aliases and unified IM pagination

Introduce declarative exact-name flag aliases at the shortcut framework boundary while keeping semantic compatibility domain-owned. Add a shared, format-aware IM pagination pipeline with consistent flags, metadata, safety bounds, resumable cursors, and request throttling.

* fix: align alias attribution and pagination contracts

* fix: align alias contracts and documentation

* test: remove environment-dependent contact bot e2e

* test: restore contact bot e2e

* docs: reduce IM pagination guidance noise

---------

Co-authored-by: liangshuo-1 <266696938+liangshuo-1@users.noreply.github.com>
2026-08-03 19:20:40 +08:00

56 lines
2.3 KiB
Go

// Copyright (c) 2026 Lark Technologies Pte. Ltd.
// SPDX-License-Identifier: MIT
package output
// Envelope is the standard success response wrapper.
type Envelope struct {
OK bool `json:"ok"`
Identity string `json:"identity,omitempty"`
DryRun bool `json:"dry_run,omitempty"`
Data interface{} `json:"data,omitempty"`
Meta *Meta `json:"meta,omitempty"`
ContentSafetyAlert interface{} `json:"_content_safety_alert,omitempty"`
Notice map[string]interface{} `json:"_notice,omitempty"`
}
// Meta carries optional metadata in envelope responses.
type Meta struct {
Count int `json:"count,omitempty"`
Rollback string `json:"rollback,omitempty"`
Pagination *PaginationMeta `json:"pagination,omitempty"`
}
// PaginationMeta reports how a paginated read ended.
//
// It lives in the envelope's meta rather than in the business data because a
// stop reason is not part of the resource: writing it into data both pollutes
// the payload and forces the caller to tell an API field apart from one the CLI
// synthesised. Complete plus NextToken is the whole story — a run either
// exhausted the endpoint or stopped at --page-limit with somewhere to resume —
// so there is no separate stop_reason string to keep in sync.
type PaginationMeta struct {
// Complete is true only when the server's exhausted state was observed.
Complete bool `json:"complete"`
// Pages counts successful API pages included in this result.
Pages int `json:"pages"`
// Items counts records after command-level filtering and enrichment.
Items int `json:"items"`
// NextToken is the cursor at which an incomplete result can resume.
NextToken string `json:"next_token,omitempty"`
}
// PendingNotice, if set, returns system-level notices to inject as the
// "_notice" field in JSON output envelopes. Set by cmd/root.go.
// Returns nil when there is nothing to report.
var PendingNotice func() map[string]interface{}
// GetNotice returns the current pending notice for struct-based callers.
// Returns nil when there is nothing to report.
func GetNotice() map[string]interface{} {
if PendingNotice == nil {
return nil
}
return PendingNotice()
}