mirror of
https://github.com/larksuite/cli.git
synced 2026-08-03 08:32:46 +08:00
* feat(apps): read LARKSUITE_CLI_AGENT env var and pass app_source in +create
* feat(apps): add queryAppMeta shared function for app_type/arch_type lookup
* feat(apps): skip scaffold for legacy html apps, pass app_type/arch_type for arch_type=4 html in +init
* feat(apps): add zip packaging for arch_type=4 html publish path
* feat(apps): add TOS upload path for arch_type=4 html in +html-publish with arch_type-based routing
* refactor(apps): replace appMeta struct with queryAppType string for simpler routing
* refactor(apps): simplify to source_agent in +create, unified scaffold in +init, revert html-publish changes
* feat(apps): add --source-path flag to +init for existing source file incorporation
* fix(apps): align queryAppType with actual API path and response structure
* refactor(apps): use appInfo struct to parse GET /apps/{id} response
* test(apps): add full_stack scaffold test case
* feat(apps): surface sync field in +release-create response
* refactor(apps): remove --template flag from +init, derive template from queryAppType with full_stack fallback
* style(apps): fix gofmt formatting in apps_init.go
* test(apps): improve coverage for sync field, queryAppType, and scaffoldInitArgs
* chore(apps): pin miaoda-cli to alpha version 0.1.20-alpha.dd573f8
* feat(apps): add modern_html enum and pass --app-type instead of --template to miaoda-cli
* chore: add global PPE headers for testing (x-use-ppe, x-tt-env)
* feat(apps): add TOS upload path in +html-publish for modern_html, add --tos-path to +release-create
* feat(apps): unify html-publish output structure with app_id for both html and modern_html
* fix(apps): use newFileTransferClient for TOS presigned upload to satisfy forbidigo lint
* test(apps): add coverage for runHTMLPublishTOS success, errors, and upload failures
* fix(apps): change pre_release API method from POST to GET
* fix(apps): adapt pre_release response from map to list<KV> format
* fix(apps): use PUT method and Content-Length for TOS presigned upload
* fix(apps): use tos_path instead of tosPath in release-create request body
* chore(apps): add npmmirror registry for npx miaoda-cli, fix TOS upload test to expect PUT
* refactor(apps): use envvars.AgentName() for source_agent in +create
* feat(apps): integrate release-create into html-publish for modern_html, auto-detect modern_html from doubao agent env
* refactor(apps): remove --tos-path flag from +release-create (now internal to html-publish)
* refactor(apps): remove app_id from html-publish output, update skill doc
* docs(apps): update html-publish description to reflect dual return values
* refactor(apps): remove doubao app_type conversion in +create, let server decide via source_agent
* feat(apps): skip env-pull for modern_html apps in +init
* test(apps): add tests for modern_html env-pull skip in +init
* refactor(apps): introduce appTypePolicy for init control points (skipInstall, skipEnvPull, skipSkillsSync)
* feat(apps): add init step timing and default git config for +init
* feat(apps): add +get shortcut to fetch single app detail by app_id
* chore(apps): remove init step timing (not ready for production)
* test(apps): add coverage for +get shortcut
* chore: remove PPE headers and revert miaoda-cli to @latest for production
* refactor(apps): extract shared prepareHTMLPublishTarball, fix stale comments, simplify queryAppType
* fix(apps): update html-publish dry-run desc, remove hardcoded API path
* fix(apps): use rctx.IO().ErrOut instead of os.Stderr, remove unused appInfo struct
* fix(apps): restore dry-run API path output for E2E compatibility
* refactor(apps): move --source-path control char validation to Validate for dry-run coverage
* fix(apps): update stale --template comments to --app-type in init tests
* test(apps): explicitly unset agent env var for test isolation
106 lines
3.9 KiB
Go
106 lines
3.9 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package apps
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/larksuite/cli/errs"
|
|
"github.com/larksuite/cli/extension/fileio"
|
|
"github.com/larksuite/cli/internal/client"
|
|
)
|
|
|
|
func appsValidationError(format string, args ...any) *errs.ValidationError {
|
|
return errs.NewValidationError(errs.SubtypeInvalidArgument, format, args...)
|
|
}
|
|
|
|
func appsValidationParamError(param, format string, args ...any) *errs.ValidationError {
|
|
return appsValidationError(format, args...).WithParam(param)
|
|
}
|
|
|
|
func appsInvalidParam(name, reason string) errs.InvalidParam {
|
|
return errs.InvalidParam{Name: name, Reason: reason}
|
|
}
|
|
|
|
func appsFailedPreconditionParamError(param, format string, args ...any) *errs.ValidationError {
|
|
return errs.NewValidationError(errs.SubtypeFailedPrecondition, format, args...).WithParam(param)
|
|
}
|
|
|
|
func appsFailedPreconditionError(format string, args ...any) *errs.ValidationError {
|
|
return errs.NewValidationError(errs.SubtypeFailedPrecondition, format, args...)
|
|
}
|
|
|
|
// appsStorageError classifies a local credential/state storage failure
|
|
// (read, write, delete, list) as internal/storage.
|
|
func appsStorageError(err error, format string, args ...any) *errs.InternalError {
|
|
return errs.NewInternalError(errs.SubtypeStorage, format, args...).WithCause(err)
|
|
}
|
|
|
|
// appsExternalToolError classifies a runtime failure of an external tool the
|
|
// CLI shells out to (git, npx) as internal/external_tool. The tool output is
|
|
// carried in the message; recovery guidance goes in the hint.
|
|
func appsExternalToolError(err error, format string, args ...any) *errs.InternalError {
|
|
return errs.NewInternalError(errs.SubtypeExternalTool, format, args...).WithCause(err)
|
|
}
|
|
|
|
// appsSubprocessEnvelopeError classifies a malformed or unexpected response
|
|
// structure as internal/invalid_response. Used for subprocess envelopes
|
|
// (+git-credential-init / +env-pull) and server responses (e.g. pre_release).
|
|
func appsSubprocessEnvelopeError(format string, args ...any) *errs.InternalError {
|
|
return errs.NewInternalError(errs.SubtypeInvalidResponse, format, args...)
|
|
}
|
|
|
|
func appsInputPathError(err error) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
if errors.Is(err, fileio.ErrPathValidation) {
|
|
return appsValidationParamError("--path", "unsafe --path: %s", err).WithCause(err)
|
|
}
|
|
return appsValidationParamError("--path", "cannot read --path: %s", err).WithCause(err)
|
|
}
|
|
|
|
func appsInputPathEntryError(path string, err error) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
if errors.Is(err, fileio.ErrPathValidation) {
|
|
return appsValidationParamError("--path", "unsafe --path entry %s: %s", path, err).WithCause(err)
|
|
}
|
|
return appsValidationParamError("--path", "cannot read --path entry %s: %s", path, err).WithCause(err)
|
|
}
|
|
|
|
func appsFileIOError(err error, format string, args ...any) *errs.InternalError {
|
|
return errs.NewInternalError(errs.SubtypeFileIO, format, args...).WithCause(err)
|
|
}
|
|
|
|
// enrichHTMLPublishAPIError adapts a typed failure from the HTML publish
|
|
// endpoint: refines endpoint-scoped business codes, prefixes the message with
|
|
// command context, and attaches endpoint-specific recovery hints. A
|
|
// still-untyped error is lifted at the SDK boundary instead.
|
|
func enrichHTMLPublishAPIError(err error) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
p, ok := errs.ProblemOf(err)
|
|
if !ok {
|
|
return client.WrapDoAPIError(err)
|
|
}
|
|
// The HTML publish business codes (90001/90002) are scoped to this
|
|
// endpoint, not service-global, so their subtype classification lives
|
|
// here instead of the global errclass code table. Only an
|
|
// otherwise-unclassified API error is refined; a stronger upstream
|
|
// classification is never overridden.
|
|
if p.Category == errs.CategoryAPI && p.Subtype == errs.SubtypeUnknown && p.Code == errCodeAppNotFound {
|
|
p.Subtype = errs.SubtypeNotFound
|
|
}
|
|
if p.Message != "" {
|
|
p.Message = "html-publish failed: " + p.Message
|
|
}
|
|
if hint := buildHTMLPublishFailureHint(p.Code); hint != "" {
|
|
p.Hint = hint
|
|
}
|
|
return err
|
|
}
|