@lovrabet/rabetbase-cli 2.5.13-beta.1 → 2.6.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -17
- package/lib/api/api-doc.js +3 -1
- package/lib/api/api-group.js +3 -1
- package/lib/api/fetch-model-list.js +1 -1
- package/lib/api/generate-api-file.js +8 -1
- package/lib/api/generate-sdk-config-file.js +1 -1
- package/lib/api/legacy-api-file.js +2 -1
- package/lib/api/model-registry-file.js +11 -1
- package/lib/api/model-registry-scaffold.js +2 -1
- package/lib/api/model-source.js +3 -1
- package/lib/auth/auth-server-ui.js +2 -1
- package/lib/auth/auth-server.js +5 -1
- package/lib/auth/constant.js +1 -1
- package/lib/auth/get-cookie.js +1 -1
- package/lib/auth/get-session-user.js +1 -1
- package/lib/auth/is-session-valid.js +1 -1
- package/lib/auth/login-success-html.js +3 -1
- package/lib/auth/logout.js +1 -1
- package/lib/cli-flags.js +1 -1
- package/lib/cli.js +5 -1
- package/lib/commands/api/generate.js +4 -1
- package/lib/commands/api/index.js +1 -1
- package/lib/commands/api/list.js +2 -1
- package/lib/commands/api/pull.js +10 -1
- package/lib/commands/api/shared.js +1 -1
- package/lib/commands/app/detail.js +1 -1
- package/lib/commands/app/index.js +1 -1
- package/lib/commands/app/list.js +5 -1
- package/lib/commands/app/members-list.js +1 -1
- package/lib/commands/app/remote-directory.js +1 -1
- package/lib/commands/app/shared.js +4 -1
- package/lib/commands/app-config/delete.js +2 -1
- package/lib/commands/app-config/get.js +2 -1
- package/lib/commands/app-config/index.js +1 -1
- package/lib/commands/app-config/list.js +2 -1
- package/lib/commands/app-config/set.js +3 -1
- package/lib/commands/app-config/shared.d.ts +9 -2
- package/lib/commands/app-config/shared.js +6 -1
- package/lib/commands/auth/index.js +1 -1
- package/lib/commands/bff/create.js +11 -1
- package/lib/commands/bff/delete.js +6 -1
- package/lib/commands/bff/detail.js +1 -1
- package/lib/commands/bff/index.js +1 -1
- package/lib/commands/bff/list.js +1 -1
- package/lib/commands/bff/logs.js +4 -1
- package/lib/commands/bff/pull.js +22 -1
- package/lib/commands/bff/push.js +16 -1
- package/lib/commands/bff/status.js +3 -1
- package/lib/commands/cli-skill/index.js +2 -1
- package/lib/commands/cli-update.js +7 -1
- package/lib/commands/codegen/index.js +1 -1
- package/lib/commands/codegen/sdk.js +1 -1
- package/lib/commands/codegen/sql.js +1 -1
- package/lib/commands/common/app-registry.js +4 -1
- package/lib/commands/common/app-selector.js +4 -1
- package/lib/commands/common/async-task.js +2 -1
- package/lib/commands/common/dry-run.js +1 -1
- package/lib/commands/common/flags.js +3 -1
- package/lib/commands/common/local-file.js +1 -1
- package/lib/commands/common/validate.js +1 -1
- package/lib/commands/config/delete.js +2 -1
- package/lib/commands/config/get.js +1 -1
- package/lib/commands/config/index.js +1 -1
- package/lib/commands/config/init.js +5 -1
- package/lib/commands/config/list.js +1 -1
- package/lib/commands/config/set.js +4 -1
- package/lib/commands/config/shared.js +2 -1
- package/lib/commands/dataset/batch-design.js +9 -1
- package/lib/commands/dataset/business-group-update.js +10 -1
- package/lib/commands/dataset/business-groups.js +1 -1
- package/lib/commands/dataset/capability.js +3 -1
- package/lib/commands/dataset/cross-relation-create.js +2 -1
- package/lib/commands/dataset/cross-relation-delete.js +1 -1
- package/lib/commands/dataset/cross-relation-list.js +2 -1
- package/lib/commands/dataset/cross-relation-shared.js +10 -1
- package/lib/commands/dataset/cross-relation-update.js +2 -1
- package/lib/commands/dataset/delete.js +6 -1
- package/lib/commands/dataset/design-context.js +1 -1
- package/lib/commands/dataset/design-start.js +1 -1
- package/lib/commands/dataset/design-status.js +1 -1
- package/lib/commands/dataset/design-sync-retry.js +1 -1
- package/lib/commands/dataset/design-sync-status.js +1 -1
- package/lib/commands/dataset/design-validate.js +1 -1
- package/lib/commands/dataset/detail.js +5 -1
- package/lib/commands/dataset/extend-update.js +7 -1
- package/lib/commands/dataset/field-restore.js +7 -1
- package/lib/commands/dataset/field-update.js +7 -1
- package/lib/commands/dataset/generate.js +19 -1
- package/lib/commands/dataset/index.js +3 -1
- package/lib/commands/dataset/list.js +2 -1
- package/lib/commands/dataset/operations.js +2 -1
- package/lib/commands/dataset/relation-audit.js +7 -1
- package/lib/commands/dataset/relation-create.js +3 -1
- package/lib/commands/dataset/relation-delete.js +3 -1
- package/lib/commands/dataset/relation-shared.js +21 -1
- package/lib/commands/dataset/relation-update.js +4 -1
- package/lib/commands/dataset/relations.js +7 -1
- package/lib/commands/dataset/rename.js +4 -1
- package/lib/commands/dataset/restore.js +7 -1
- package/lib/commands/dataset/user-deleted-field-list.js +3 -1
- package/lib/commands/db/analysis-batching.js +3 -1
- package/lib/commands/db/analyze-batch-plan.js +2 -1
- package/lib/commands/db/analyze-cancel.js +1 -1
- package/lib/commands/db/analyze-start.js +3 -1
- package/lib/commands/db/analyze-status.js +6 -1
- package/lib/commands/db/create.js +4 -1
- package/lib/commands/db/cross-db-analysis-shared.js +3 -1
- package/lib/commands/db/cross-db-analyze-latest.js +1 -1
- package/lib/commands/db/cross-db-analyze-start.js +2 -1
- package/lib/commands/db/cross-db-analyze-status.js +1 -1
- package/lib/commands/db/delete.js +3 -1
- package/lib/commands/db/detail.js +1 -1
- package/lib/commands/db/diff-refresh-start.js +1 -1
- package/lib/commands/db/diff-refresh-status.js +2 -1
- package/lib/commands/db/diff.js +3 -1
- package/lib/commands/db/index.js +2 -1
- package/lib/commands/db/list.js +2 -1
- package/lib/commands/db/shared.js +3 -1
- package/lib/commands/db/table-diff-shared.js +2 -1
- package/lib/commands/db/tables.js +2 -1
- package/lib/commands/db/test.js +2 -1
- package/lib/commands/db/update.js +4 -1
- package/lib/commands/deployment/index.js +1 -1
- package/lib/commands/deployment/sync-all.js +3 -1
- package/lib/commands/deployment/sync-jobs.js +2 -1
- package/lib/commands/deployment/sync-status.js +2 -1
- package/lib/commands/doctor.js +12 -1
- package/lib/commands/file/index.js +3 -1
- package/lib/commands/flow/create.js +2 -1
- package/lib/commands/flow/detail.js +3 -1
- package/lib/commands/flow/index.js +1 -1
- package/lib/commands/flow/list.js +2 -1
- package/lib/commands/flow/page-list.js +2 -1
- package/lib/commands/flow/publish.js +2 -1
- package/lib/commands/flow/runtime-resources-shared.js +3 -1
- package/lib/commands/flow/runtime-role-list.js +2 -1
- package/lib/commands/flow/runtime-role-user-list.js +2 -1
- package/lib/commands/flow/runtime-user-search.js +2 -1
- package/lib/commands/flow/shared.js +6 -1
- package/lib/commands/flow/update.js +4 -1
- package/lib/commands/flow/validate.js +2 -1
- package/lib/commands/instant-api-policy/current.js +1 -1
- package/lib/commands/instant-api-policy/index.js +1 -1
- package/lib/commands/instant-api-policy/init.js +2 -1
- package/lib/commands/instant-api-policy/publish.js +5 -1
- package/lib/commands/instant-api-policy/pull.js +2 -1
- package/lib/commands/instant-api-policy/revision.js +1 -1
- package/lib/commands/instant-api-policy/revisions.js +1 -1
- package/lib/commands/instant-api-policy/rollback.js +5 -1
- package/lib/commands/instant-api-policy/shared.js +5 -1
- package/lib/commands/instant-api-policy/validate.js +1 -1
- package/lib/commands/issue/context.js +1 -1
- package/lib/commands/issue/index.js +1 -1
- package/lib/commands/issue/nudge.js +2 -1
- package/lib/commands/issue/report.js +5 -1
- package/lib/commands/kb/create.js +5 -1
- package/lib/commands/kb/delete.js +5 -1
- package/lib/commands/kb/detail.js +1 -1
- package/lib/commands/kb/import-api.d.ts +3 -0
- package/lib/commands/kb/import-api.js +1 -0
- package/lib/commands/kb/import-resume.d.ts +2 -0
- package/lib/commands/kb/import-resume.js +2 -0
- package/lib/commands/kb/import-shared.d.ts +69 -0
- package/lib/commands/kb/import-shared.js +9 -0
- package/lib/commands/kb/import-status.d.ts +2 -0
- package/lib/commands/kb/import-status.js +1 -0
- package/lib/commands/kb/import.d.ts +2 -0
- package/lib/commands/kb/import.js +3 -0
- package/lib/commands/kb/index.js +1 -1
- package/lib/commands/kb/list.js +1 -1
- package/lib/commands/kb/search.js +3 -1
- package/lib/commands/kb/shared.js +9 -1
- package/lib/commands/kb/update.js +7 -1
- package/lib/commands/logs/index.js +2 -1
- package/lib/commands/menu/asset-update.js +8 -1
- package/lib/commands/menu/delete.js +15 -1
- package/lib/commands/menu/external-link-create.js +16 -1
- package/lib/commands/menu/external-link-update.js +10 -1
- package/lib/commands/menu/group-create.js +8 -1
- package/lib/commands/menu/group-update.js +6 -1
- package/lib/commands/menu/index.js +2 -1
- package/lib/commands/menu/list.js +1 -1
- package/lib/commands/menu/move.js +6 -1
- package/lib/commands/menu/regroup-start.js +11 -1
- package/lib/commands/menu/rename.js +9 -1
- package/lib/commands/menu/shared/compare-table.js +2 -1
- package/lib/commands/menu/shared/delete-plan.js +13 -1
- package/lib/commands/menu/shared/facts.js +5 -1
- package/lib/commands/menu/shared/index.js +1 -1
- package/lib/commands/menu/shared/inquirer.js +4 -1
- package/lib/commands/menu/shared/local-pages.js +5 -1
- package/lib/commands/menu/shared/logic.js +3 -1
- package/lib/commands/menu/shared/mutations.js +9 -1
- package/lib/commands/menu/shared/path.js +1 -1
- package/lib/commands/menu/shared/service.js +4 -1
- package/lib/commands/menu/shared/subapp-assets.js +4 -1
- package/lib/commands/menu/shared/sync-core.js +7 -1
- package/lib/commands/menu/shared/types.js +1 -1
- package/lib/commands/menu/shared/update-core.js +8 -1
- package/lib/commands/menu/shared/valid-url.js +1 -1
- package/lib/commands/menu/subapp-assets-status.js +1 -1
- package/lib/commands/menu/subapp-assets-update.js +7 -1
- package/lib/commands/menu/sync.js +7 -1
- package/lib/commands/menu/visibility-update.js +13 -1
- package/lib/commands/metric/contract.d.ts +8 -0
- package/lib/commands/metric/contract.js +5 -0
- package/lib/commands/metric/definition.d.ts +43 -0
- package/lib/commands/metric/definition.js +4 -0
- package/lib/commands/metric/delete.d.ts +2 -0
- package/lib/commands/metric/delete.js +3 -0
- package/lib/commands/metric/detail.d.ts +2 -0
- package/lib/commands/metric/detail.js +1 -0
- package/lib/commands/metric/example.d.ts +2 -0
- package/lib/commands/metric/example.js +1 -0
- package/lib/commands/metric/index.d.ts +2 -0
- package/lib/commands/metric/index.js +1 -0
- package/lib/commands/metric/list.d.ts +2 -0
- package/lib/commands/metric/list.js +2 -0
- package/lib/commands/metric/publication-diff.d.ts +8 -0
- package/lib/commands/metric/publication-diff.js +1 -0
- package/lib/commands/metric/publish.d.ts +2 -0
- package/lib/commands/metric/publish.js +4 -0
- package/lib/commands/metric/schema.d.ts +2 -0
- package/lib/commands/metric/schema.js +1 -0
- package/lib/commands/metric/shared.d.ts +14 -0
- package/lib/commands/metric/shared.js +2 -0
- package/lib/commands/metric/validate.d.ts +2 -0
- package/lib/commands/metric/validate.js +1 -0
- package/lib/commands/notification/config-create.js +4 -1
- package/lib/commands/notification/config-delete.js +4 -1
- package/lib/commands/notification/config-list.js +2 -1
- package/lib/commands/notification/config-update.js +4 -1
- package/lib/commands/notification/index.js +1 -1
- package/lib/commands/notification/shared.js +18 -1
- package/lib/commands/ocr/index.js +4 -1
- package/lib/commands/page/create.js +6 -1
- package/lib/commands/page/custom/detail.js +2 -1
- package/lib/commands/page/custom/list.js +2 -1
- package/lib/commands/page/custom/publish.js +3 -1
- package/lib/commands/page/custom/shared.js +3 -1
- package/lib/commands/page/custom/syntax.js +2 -1
- package/lib/commands/page/custom/update.js +3 -1
- package/lib/commands/page/data-list-status.js +2 -1
- package/lib/commands/page/generate-start.js +5 -1
- package/lib/commands/page/generate-status.js +4 -1
- package/lib/commands/page/index.js +2 -1
- package/lib/commands/page/pull.js +6 -1
- package/lib/commands/page/push.js +11 -1
- package/lib/commands/page/relation-audit.js +15 -1
- package/lib/commands/page/restore.js +5 -1
- package/lib/commands/page/shared.js +16 -1
- package/lib/commands/page/sync.js +2 -1
- package/lib/commands/project/api-architecture-upgrade.js +11 -1
- package/lib/commands/project/create/enhanced-guided-create.js +2 -1
- package/lib/commands/project/create/format-elapsed.js +1 -1
- package/lib/commands/project/create/main.js +13 -1
- package/lib/commands/project/create/materialize-project-template.js +12 -1
- package/lib/commands/project/create/project-name.js +1 -1
- package/lib/commands/project/create/project-template-archive.js +5 -1
- package/lib/commands/project/create/project-template-path.js +1 -1
- package/lib/commands/project/create/use-copy-project-template.js +2 -1
- package/lib/commands/project/create/use-format-code.js +1 -1
- package/lib/commands/project/create/use-install-dependencies.js +1 -1
- package/lib/commands/project/domain-routing-sync.js +1 -1
- package/lib/commands/project/index.js +4 -1
- package/lib/commands/project/upgrade.js +7 -1
- package/lib/commands/registry.js +10 -1
- package/lib/commands/role/delete.js +2 -1
- package/lib/commands/role/detail.js +1 -1
- package/lib/commands/role/index.js +1 -1
- package/lib/commands/role/list.js +2 -1
- package/lib/commands/role/shared.js +8 -1
- package/lib/commands/role/update.js +3 -1
- package/lib/commands/role/user-add.js +2 -1
- package/lib/commands/role/user-remove.js +2 -1
- package/lib/commands/role/user-resolve.js +1 -1
- package/lib/commands/rule/get.js +1 -1
- package/lib/commands/rule/index.js +1 -1
- package/lib/commands/rule/list.js +1 -1
- package/lib/commands/rule/set.js +7 -1
- package/lib/commands/rule/shared.js +4 -1
- package/lib/commands/run/index.js +5 -1
- package/lib/commands/schema.js +1 -1
- package/lib/commands/sql/create.js +7 -1
- package/lib/commands/sql/delete.js +4 -1
- package/lib/commands/sql/detail.js +1 -1
- package/lib/commands/sql/exec.js +1 -1
- package/lib/commands/sql/index.js +1 -1
- package/lib/commands/sql/list.js +2 -1
- package/lib/commands/sql/pull.js +10 -1
- package/lib/commands/sql/push.js +9 -1
- package/lib/commands/sql/shared.js +5 -1
- package/lib/commands/sql/status.js +3 -1
- package/lib/commands/sql/validate.js +5 -1
- package/lib/commands/task/index.js +1 -1
- package/lib/commands/task/status.js +2 -1
- package/lib/commands/tenant/index.js +1 -1
- package/lib/commands/tenant/members-list.js +2 -1
- package/lib/commands/tenant/shared.js +2 -1
- package/lib/commands/user-account/dingding-sandbox-bind.js +2 -1
- package/lib/commands/user-account/feishu-bind.js +2 -1
- package/lib/commands/user-account/index.js +1 -1
- package/lib/commands/workspace/add.js +1 -1
- package/lib/commands/workspace/index.js +7 -1
- package/lib/commands/workspace/remove.js +1 -1
- package/lib/config/domain-config.js +8 -1
- package/lib/config/project-domain-routing.js +3 -1
- package/lib/config/region-config.js +2 -1
- package/lib/config/schema.js +7 -1
- package/lib/constant/cdn.js +2 -1
- package/lib/constant/cli.js +8 -1
- package/lib/constant/defaults.js +1 -1
- package/lib/constant/domain.js +4 -1
- package/lib/constant/env.js +1 -1
- package/lib/constant/output.js +1 -1
- package/lib/constant/paths.js +1 -1
- package/lib/constant/region.js +1 -1
- package/lib/constant/risk.js +1 -1
- package/lib/constant/routing-profile.js +1 -1
- package/lib/context/app-resolver.js +7 -1
- package/lib/context/auth-resolver.js +1 -1
- package/lib/context/config-loader.js +7 -1
- package/lib/context.js +9 -1
- package/lib/core/alias-resolver.js +5 -1
- package/lib/core/api-client.d.ts +14 -7
- package/lib/core/api-client.js +69 -1
- package/lib/core/bff/config.js +1 -1
- package/lib/core/bff/file-system.js +6 -1
- package/lib/core/bff/hash.js +1 -1
- package/lib/core/bff/hook-directory.js +9 -1
- package/lib/core/bff/lock.js +2 -1
- package/lib/core/bff/types.js +1 -1
- package/lib/core/bff/utils.js +3 -1
- package/lib/core/cross-db-analysis.js +1 -1
- package/lib/core/cross-db-relation.js +1 -1
- package/lib/core/db-resolver.js +2 -1
- package/lib/core/flow-config.js +49 -1
- package/lib/core/instant-api-policy/config.js +7 -1
- package/lib/core/instant-api-policy/endpoints.js +1 -1
- package/lib/core/kb-management-client.d.ts +11 -0
- package/lib/core/kb-management-client.js +4 -1
- package/lib/core/kb-search-client.js +3 -1
- package/lib/core/page/file-system.js +2 -1
- package/lib/core/page/hash.js +1 -1
- package/lib/core/page/lock.js +2 -1
- package/lib/core/page/lr-smart-jsx.js +4 -1
- package/lib/core/page/types.js +1 -1
- package/lib/core/sql-index-auditor.js +14 -1
- package/lib/core/sql-sync/config.js +1 -1
- package/lib/core/sql-sync/file-system.js +3 -1
- package/lib/core/sql-sync/hash.js +1 -1
- package/lib/core/sql-sync/lock.js +2 -1
- package/lib/core/sql-sync/types.js +1 -1
- package/lib/core/sql-sync/utils.js +2 -1
- package/lib/core/sql-validator.js +15 -1
- package/lib/errors.js +3 -1
- package/lib/framework/build-all-flags.js +1 -1
- package/lib/framework/error-output.js +1 -1
- package/lib/framework/explicit-yes.js +1 -1
- package/lib/framework/flags.js +1 -1
- package/lib/framework/help.js +2 -1
- package/lib/framework/index.js +1 -1
- package/lib/framework/output.js +2 -1
- package/lib/framework/response.js +1 -1
- package/lib/framework/runner-alias.js +2 -1
- package/lib/framework/runner.js +9 -1
- package/lib/framework/schema-export.js +1 -1
- package/lib/framework/supported-flags.js +2 -1
- package/lib/framework/types.js +1 -1
- package/lib/generated/build-info.d.ts +4 -4
- package/lib/generated/build-info.js +1 -1
- package/lib/generated/official-routing.js +3 -1
- package/lib/generated/routing-contract.js +1 -1
- package/lib/help.js +1 -1
- package/lib/runtime/confirmation.js +2 -1
- package/lib/runtime/event.js +1 -1
- package/lib/runtime/index.js +4 -1
- package/lib/runtime/queue.js +1 -1
- package/lib/runtime/resolve.js +2 -1
- package/lib/runtime/types.js +1 -1
- package/lib/services/dataset-design/checkpoint.js +2 -1
- package/lib/services/dataset-design/commands.js +14 -1
- package/lib/services/dataset-design/contract.js +8 -1
- package/lib/skills/builtin-skill.js +8 -1
- package/lib/skills/install-updated-skill.d.ts +8 -0
- package/lib/skills/install-updated-skill.js +3 -0
- package/lib/skills/local-skills-installer.d.ts +2 -0
- package/lib/skills/local-skills-installer.js +1 -0
- package/lib/skills/main.js +2 -1
- package/lib/skills/npx-skills-add.d.ts +6 -6
- package/lib/skills/npx-skills-add.js +5 -1
- package/lib/skills/skill-presence.d.ts +1 -30
- package/lib/skills/skill-presence.js +2 -1
- package/lib/telemetry/cli-command-trace.js +2 -1
- package/lib/telemetry/cli-help-trace.js +1 -1
- package/lib/telemetry/ensure-cli-otel-config.js +1 -1
- package/lib/telemetry/register-otel-exit-shutdown.js +1 -1
- package/lib/telemetry/send-cli-trace-log.js +1 -1
- package/lib/types/index.js +1 -1
- package/lib/utils/ai_config.js +3 -1
- package/lib/utils/apply-jq-filter.js +1 -1
- package/lib/utils/cdn-config.js +1 -1
- package/lib/utils/check-sdk-version.js +5 -1
- package/lib/utils/cli-version-check.js +4 -1
- package/lib/utils/cli-version-policy.js +3 -1
- package/lib/utils/config.js +1 -1
- package/lib/utils/entity-with-id.js +1 -1
- package/lib/utils/file-utils.js +1 -1
- package/lib/utils/guides-cdn.js +3 -1
- package/lib/utils/http-client.js +2 -1
- package/lib/utils/is-non-interactive.js +1 -1
- package/lib/utils/logger.js +3 -1
- package/lib/utils/params.js +1 -1
- package/lib/utils/platform.js +1 -1
- package/lib/utils/sleep.js +1 -1
- package/lib/utils/template-replacer.js +5 -1
- package/lib/utils/update-notice.js +3 -1
- package/lib/utils/version.js +1 -1
- package/lib/utils/with-active-cookie.js +1 -1
- package/lib/utils/write-cli-side-channel.js +1 -1
- package/package.json +10 -7
- package/skills/rabetbase/SKILL.md +11 -7
- package/skills/rabetbase/guides/backend-function.md +3 -1
- package/skills/rabetbase/guides/data-api-guidelines.md +1 -1
- package/skills/rabetbase/guides/frontend-development.md +1 -0
- package/skills/rabetbase/guides/metric-development.md +185 -0
- package/skills/rabetbase/references/rabetbase-app-config.md +4 -3
- package/skills/rabetbase/references/rabetbase-cli-skill-install.md +5 -5
- package/skills/rabetbase/references/rabetbase-dataset-design.md +1 -1
- package/skills/rabetbase/references/rabetbase-kb.md +16 -0
- package/skills/rabetbase/references/rabetbase-metric.md +119 -0
- package/skills/rabetbase/references/rabetbase-update.md +7 -5
- package/skills/rabetbase-dataset-generation/SKILL.md +1 -1
- package/skills/rabetbase-dataset-generation/references/workflow.md +1 -1
- package/skills/rabetbase-metrics-generation/SKILL.md +22 -0
- package/skills/rabetbase-metrics-generation/references/verification.md +19 -0
- package/skills/rabetbase-metrics-generation/references/workflow.md +41 -0
- package/skills/rabetbase-metrics-generation/templates/statistics-delivery.md +11 -0
- package/skills/rabetbase-page-generation/SKILL.md +1 -1
- package/skills/rabetbase-page-generation/references/generation.md +1 -1
- package/skills/rabetbase.manifest.json +5 -3
- package/templates/metrics/definition.json +78 -0
- package/templates/metrics/metric-definition.schema.json +136 -0
- package/lib/postinstall.d.ts +0 -3
- package/lib/postinstall.js +0 -1
- package/scripts/postinstall.mjs +0 -24
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{apiList}from"../../commands/api/list.js";import{apiPull}from"../../commands/api/pull.js";import{apiGenerate}from"../../commands/api/generate.js";export const apiDefinitions=[apiList,apiPull,apiGenerate];
|
package/lib/commands/api/list.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{fetchModelList}from"../../core/api-client.js";import{APPCODE_FLAG_OPTIONAL}from"../../commands/common/flags.js";import{resolveTargetApps}from"../../commands/api/shared.js";import{initMultiAppEnvironment}from"../../context.js";export const apiList={service:"api",command:"list",description:"List all datasets/models for the configured app(s)",risk:"read",requiresAppCode:true,flags:[{...APPCODE_FLAG_OPTIONAL,hidden:true},{name:"global",type:"boolean",description:"Resolve apps from merged global+project config (default: project apps only)",default:false}],async execute(ctx){const explicitAppcode=ctx.rawFlags.appcode?String(ctx.rawFlags.appcode):undefined;const targetApps=resolveTargetApps(ctx,explicitAppcode);if(targetApps){const allModels=[];for(const app of targetApps){const appCookie=app.cookie||ctx.cookie;await initMultiAppEnvironment(app);const{configArray:configArray}=await fetchModelList(app.appcode,appCookie);allModels.push(...configArray.map(m=>({...m,_appName:app.name,
|
|
2
|
+
_appCode:app.appcode,_region:app.region,_isDefault:app.isDefault})))}return{ok:true,data:allModels}}const{configArray:configArray}=await fetchModelList(ctx.appCode,ctx.cookie);return{ok:true,data:configArray}}};
|
package/lib/commands/api/pull.js
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
const a22_0x1640ac=a22_0x3203;(function(_0x378a55,_0x55139c){const _0x33d262=a22_0x3203,_0xfe2a25=_0x378a55();while(!![]){try{const _0x289d9d=parseInt(_0x33d262(0x143))/0x1*(-parseInt(_0x33d262(0x150))/0x2)+-parseInt(_0x33d262(0x114))/0x3*(parseInt(_0x33d262(0x12a))/0x4)+parseInt(_0x33d262(0x115))/0x5*(-parseInt(_0x33d262(0x13d))/0x6)+-parseInt(_0x33d262(0x132))/0x7+parseInt(_0x33d262(0x151))/0x8+parseInt(_0x33d262(0x118))/0x9*(parseInt(_0x33d262(0x106))/0xa)+parseInt(_0x33d262(0x10f))/0xb;if(_0x289d9d===_0x55139c)break;else _0xfe2a25['push'](_0xfe2a25['shift']());}catch(_0x4af9aa){_0xfe2a25['push'](_0xfe2a25['shift']());}}}(a22_0x5921,0x6bbd1));import a22_0x3c605c from'ora';function a22_0x5921(){const _0x1a7cd1=['string','succeed','apiFilePath','\x20dataset\x20fact(s)\x20and\x20refreshed\x20','\x22\x20was\x20not\x20resolved.','client','validation','Accept\x20an\x20empty\x20model\x20result,\x20or\x20replace\x20a\x20legacy\x20prefixed\x20scaffold;\x20requires\x20--yes','6573237YceURz','\x20is\x20not\x20a\x20valid\x20Rabetbase\x20generated\x20file.\x20Move\x20or\x20repair\x20it\x20before\x20pulling\x20models\x20again.','read','selectedAppName','production','185730IiAzOU','2115210jMhLCX',';\x20created\x20the\x20stable\x20TypeScript\x20entrypoints','modelRuntimePath','9lcggJv','Select\x20the\x20target\x20explicitly\x20with\x20--app\x20<profile>.','map','Output\x20directory\x20(default:\x20','app','split','Failed:\x20','\x20dataset\x20fact(s)\x20and\x20replaced\x20the\x20TypeScript\x20scaffold\x20with\x20','...','currentApp','includes','none','NOT-SET','join','files',')...','models','profiles','20PuxMfl','\x20\x20•\x20','Select\x20a\x20configured\x20app\x20profile\x20or\x20use\x20a\x20separate\x20apiDir.','appCode','isDefault','\x20succeeded,\x20','modelRegistryPath','\x20dataset\x20fact(s)\x20and\x20refreshed\x20model\x20profile\x20\x22','144298lnmSqY','modelProfile','mergedCli','Pulling\x20','force','filter','\x20dataset\x20fact(s)\x20and\x20wrote\x20a\x20scaffold\x20with\x20','exists','Model\x20facts\x20were\x20refreshed,\x20but\x20the\x20stable\x20source\x20entrypoints\x20are\x20not\x20installed.\x20Run\x20`rabetbase\x20project\x20upgrade\x20--dry-run`,\x20then\x20`rabetbase\x20project\x20upgrade\x20--yes`.','appcode','overwritten','6blVtnE','isUnboundTemplate',';\x20preserved\x20the\x20stable\x20TypeScript\x20entrypoints','boolean','size','needsAgentMerge','1RIOwYp','\x22\x20belongs\x20to\x20multiple\x20app\x20profiles:\x20','env','Pulling\x20API\x20config\x20for\x20','pull','configName','\x20model(s)','project','basename','cookie','find','rawFlags','global','1764332ddsUWP','6282952efUItK','merged','length',';\x20replaced\x20the\x20stable\x20TypeScript\x20entrypoints','sdkRouting','hasAppCode','Done:\x20','yes','Fetched\x20','sdkConfigPath','output','Pull\x20dataset\x20facts\x20and\x20refresh\x20the\x20generated\x20SDK\x20model\x20registry\x20(','defaultApp','bool','modelCount','clientFilePath','name','outputDir','isDefaultConfig','apiDir','action','fail','api','created','Verify\x20the\x20selected\x20profile\x20and\x20review\x20legacy\x20generated\x20files,\x20then\x20rerun\x20with\x20--force\x20--yes.','Internal\x20error:\x20API\x20layout\x20for\x20app\x20profile\x20\x22','6937330WHbIwz'];a22_0x5921=function(){return _0x1a7cd1;};return a22_0x5921();}import{getEnv}from'../../constant/env.js';import{fetchModelList}from'../../core/api-client.js';import{generateApiFile}from'../../api/generate-api-file.js';function a22_0x3203(_0x368d92,_0x1764ed){_0x368d92=_0x368d92-0xee;const _0x59211b=a22_0x5921();let _0x3203d7=_0x59211b[_0x368d92];return _0x3203d7;}import{APPCODE_FLAG_OPTIONAL}from'../../commands/common/flags.js';import{DEFAULT_API_DIR}from'../../constant/paths.js';import{resolveTargetApps}from'../../commands/api/shared.js';import{writeCliSideChannelLine}from'../../utils/write-cli-side-channel.js';import{getRuntimeDomain,getSdkClientRoutingConfig}from'../../constant/domain.js';import{CliErrors}from'../../errors.js';import{initMultiAppEnvironment}from'../../context.js';import a22_0x1e24c9 from'node:path';import{existsSync}from'node:fs';import{MODEL_REGISTRY_FILE_NAME,readModelRegistry}from'../../api/model-registry-file.js';import{getMultiAppConfigs}from'../../utils/config.js';import{getRegistryGroup,resolveApiProfileLayouts}from'../../api/api-group.js';const EXISTING_TS_HINT=a22_0x1640ac(0x13a);function inspectModelRegistry(_0x235358,_0x3b12b3){const _0x1610db=a22_0x1640ac,_0x240bd0=a22_0x1e24c9[_0x1610db(0x125)](_0x235358,MODEL_REGISTRY_FILE_NAME),_0x195c92=existsSync(_0x240bd0);if(!_0x195c92)return{'exists':![],'hasAppCode':![],'isUnboundTemplate':![]};const _0x49d0cf=readModelRegistry(_0x240bd0);if(!_0x49d0cf)throw new Error(MODEL_REGISTRY_FILE_NAME+_0x1610db(0x110));const _0x354b4c=new Set(Object['values'](_0x49d0cf[_0x1610db(0x129)])[_0x1610db(0x11a)](_0x289f32=>_0x289f32[_0x1610db(0x12d)])[_0x1610db(0x137)](_0x3b4620=>_0x3b4620!==_0x1610db(0x124)));return{'exists':!![],'hasAppCode':!!_0x3b12b3&&_0x354b4c['has'](_0x3b12b3),'isUnboundTemplate':_0x354b4c[_0x1610db(0x141)]===0x0};}function toPullData(_0x1252a4){const _0x333bb0=a22_0x1640ac;return{'appCode':_0x1252a4[_0x333bb0(0x12d)],'configName':_0x1252a4[_0x333bb0(0x148)],'isDefaultConfig':_0x1252a4[_0x333bb0(0xfe)],'models':_0x1252a4[_0x333bb0(0x128)],'sdkRouting':_0x1252a4[_0x333bb0(0xf0)],'files':_0x1252a4[_0x333bb0(0x126)],'needsAgentMerge':_0x1252a4[_0x333bb0(0x142)],'needsProjectUpgrade':_0x1252a4['needsProjectUpgrade'],'apiFilePath':_0x1252a4[_0x333bb0(0x109)],'clientFilePath':_0x1252a4['clientFilePath'],'sdkConfigPath':_0x1252a4['sdkConfigPath'],'modelRegistryPath':_0x1252a4['modelRegistryPath'],'modelRuntimePath':_0x1252a4[_0x333bb0(0x117)],'modelProfile':_0x1252a4[_0x333bb0(0x133)],'datasetCount':_0x1252a4['modelCount'],'modelCount':_0x1252a4[_0x333bb0(0xfa)]};}function describePull(_0x4b95a1){const _0xc897b0=a22_0x1640ac,_0x29ad36=a22_0x1e24c9[_0xc897b0(0x14b)](_0x4b95a1[_0xc897b0(0xf5)]);if(_0x4b95a1['modelProfile']){const _0x32bcc2=_0xc897b0(0xf4)+_0x4b95a1[_0xc897b0(0xfa)]+_0xc897b0(0x131)+_0x4b95a1['modelProfile']+'\x22';if(_0x4b95a1[_0xc897b0(0x142)])return _0x32bcc2+'.\x20'+EXISTING_TS_HINT;if(_0x4b95a1[_0xc897b0(0x126)][_0xc897b0(0x102)][_0xc897b0(0x100)]===_0xc897b0(0x13c)||_0x4b95a1[_0xc897b0(0x126)][_0xc897b0(0x10c)]['action']===_0xc897b0(0x13c))return _0x32bcc2+_0xc897b0(0xef);if(_0x4b95a1[_0xc897b0(0x126)][_0xc897b0(0x102)][_0xc897b0(0x100)]===_0xc897b0(0x103)||_0x4b95a1['files'][_0xc897b0(0x10c)]['action']===_0xc897b0(0x103))return _0x32bcc2+_0xc897b0(0x116);return _0x32bcc2+_0xc897b0(0x13f);}if(_0x4b95a1[_0xc897b0(0x142)])return'Fetched\x20'+_0x4b95a1[_0xc897b0(0xfa)]+_0xc897b0(0x10a)+_0x29ad36+'.\x20'+EXISTING_TS_HINT;if(_0x4b95a1['files'][_0xc897b0(0x102)][_0xc897b0(0x100)]===_0xc897b0(0x13c)||_0x4b95a1[_0xc897b0(0x126)][_0xc897b0(0x10c)][_0xc897b0(0x100)]===_0xc897b0(0x13c))return _0xc897b0(0xf4)+_0x4b95a1['modelCount']+_0xc897b0(0x11f)+_0x4b95a1['modelCount']+_0xc897b0(0x149);return _0xc897b0(0xf4)+_0x4b95a1['modelCount']+_0xc897b0(0x138)+_0x4b95a1[_0xc897b0(0xfa)]+_0xc897b0(0x149);}export const apiPull={'service':a22_0x1640ac(0x102),'command':a22_0x1640ac(0x147),'description':a22_0x1640ac(0xf7)+DEFAULT_API_DIR+'/)','risk':a22_0x1640ac(0x111),'requiresAppCode':!![],'hasFormat':!![],'flags':[{...APPCODE_FLAG_OPTIONAL,'hidden':!![]},{'name':a22_0x1640ac(0xf6),'type':a22_0x1640ac(0x107),'description':a22_0x1640ac(0x11b)+DEFAULT_API_DIR+'/)'},{'name':a22_0x1640ac(0x14f),'type':a22_0x1640ac(0x140),'description':'Resolve\x20apps\x20from\x20merged\x20global+project\x20config\x20(default:\x20project\x20apps\x20only)','default':![]},{'name':'force','type':a22_0x1640ac(0x140),'description':a22_0x1640ac(0x10e),'default':![]}],async 'validate'(_0xd15ba4){const _0x22ec17=a22_0x1640ac;if(_0xd15ba4[_0x22ec17(0xf9)]('force')&&!_0xd15ba4[_0x22ec17(0xf9)](_0x22ec17(0xf3)))throw CliErrors[_0x22ec17(0x10d)]('--force\x20requires\x20--yes\x20because\x20it\x20may\x20remove\x20existing\x20model\x20facts\x20or\x20replace\x20a\x20legacy\x20generated\x20scaffold.',_0x22ec17(0x104));},async 'execute'(_0x304ce5){const _0x24559a=a22_0x1640ac,_0x12553=_0x304ce5['rawFlags'][_0x24559a(0x13b)]?String(_0x304ce5[_0x24559a(0x14e)][_0x24559a(0x13b)]):undefined,_0x470a33=_0x304ce5['str'](_0x24559a(0xf6))||undefined,_0x5c0380=_0x304ce5[_0x24559a(0xf9)](_0x24559a(0x136)),_0x3b7938=resolveTargetApps(_0x304ce5,_0x12553),_0x38e8b8=_0x304ce5[_0x24559a(0xf9)](_0x24559a(0x14f))?_0x24559a(0x152):_0x24559a(0x14a),_0x1611c2=getMultiAppConfigs(_0x38e8b8),_0x60cc4=_0x1e5367=>_0x1e5367[_0x24559a(0xff)]||_0x470a33||_0x304ce5[_0x24559a(0xff)]||DEFAULT_API_DIR,_0x535a1b=_0x1611c2?resolveApiProfileLayouts(_0x1611c2,_0x60cc4):undefined;let _0x33af3d=_0x3b7938;if(!_0x33af3d&&_0x1611c2){const _0x1f5661=_0x304ce5['selectedAppName']?_0x1611c2[_0x24559a(0x14d)](_0x3146fe=>_0x3146fe[_0x24559a(0xfc)]===_0x304ce5[_0x24559a(0x112)]):undefined,_0x24978e=_0x1611c2[_0x24559a(0x137)](_0x1b12d0=>_0x1b12d0[_0x24559a(0x13b)]===_0x304ce5[_0x24559a(0x12d)]);if(!_0x1f5661&&_0x24978e[_0x24559a(0xee)]>0x1)throw CliErrors[_0x24559a(0x10d)]('AppCode\x20\x22'+_0x304ce5['appCode']+_0x24559a(0x144)+_0x24978e['map'](_0x4e0f5f=>_0x4e0f5f[_0x24559a(0xfc)])[_0x24559a(0x125)](',\x20')+'.',_0x24559a(0x119));const _0x7b1d3a=_0x1f5661??_0x24978e[0x0];if(_0x7b1d3a)_0x33af3d=[_0x7b1d3a];}if(_0x33af3d){let _0x35383e=0x0,_0x55359e=0x0;const _0x2abbcb=[],_0x417eac=_0x535a1b??resolveApiProfileLayouts(_0x33af3d,_0x60cc4);for(const _0x40bb96 of _0x33af3d){const _0x9c5a98=_0x40bb96[_0x24559a(0x14c)]||_0x304ce5[_0x24559a(0x14c)],_0x5641dc=_0x40bb96[_0x24559a(0x145)]||_0x24559a(0x113);await initMultiAppEnvironment(_0x40bb96);const _0x102fa7=_0x417eac[_0x24559a(0x14d)](_0x2990dd=>_0x2990dd['app'][_0x24559a(0xfc)]===_0x40bb96[_0x24559a(0xfc)]);if(!_0x102fa7)throw new Error(_0x24559a(0x105)+_0x40bb96[_0x24559a(0xfc)]+_0x24559a(0x10b));const _0xa064b1=getRegistryGroup(_0x417eac,_0x102fa7),_0x416023=_0x102fa7[_0x24559a(0xfd)],_0x1b0bea=_0xa064b1?'':_0x40bb96['isDefault']?'':_0x40bb96[_0x24559a(0xfc)]||_0x40bb96[_0x24559a(0x13b)],_0x4d91c4=_0xa064b1?.[_0x24559a(0x14d)](_0x2132ff=>_0x2132ff[_0x24559a(0x11c)][_0x24559a(0x12e)])??_0xa064b1?.[0x0];if(_0xa064b1)inspectModelRegistry(_0x416023);const _0x55e90d=a22_0x3c605c(_0x24559a(0x135)+_0x40bb96[_0x24559a(0xfc)]+'\x20('+_0x40bb96[_0x24559a(0x13b)]+_0x24559a(0x127))['start']();try{const {configArray:_0x16ed1c}=await fetchModelList(_0x40bb96['appcode'],_0x9c5a98),_0x1c1d2a=await generateApiFile(_0x16ed1c,_0x1b0bea,_0x40bb96[_0x24559a(0x13b)],_0x40bb96['isDefault'],_0x5641dc,_0x416023,_0x40bb96['name'],getSdkClientRoutingConfig(),{'overwriteTypescript':_0xa064b1?![]:_0x5c0380,'allowEmptyModelReplacement':_0xa064b1?_0x5c0380:undefined,'scaffoldMode':_0xa064b1?_0x24559a(0x123):undefined,..._0xa064b1?{'modelProfile':{'name':_0x40bb96[_0x24559a(0xfc)],'defaultName':_0x4d91c4[_0x24559a(0x11c)][_0x24559a(0xfc)],'runtimeDomain':getRuntimeDomain()}}:{}});_0x55e90d[_0x24559a(0x108)](_0x40bb96[_0x24559a(0xfc)]+':\x20'+describePull(_0x1c1d2a)),writeCliSideChannelLine(_0x24559a(0x12b)+_0x1c1d2a[_0x24559a(0xf5)]),writeCliSideChannelLine(_0x24559a(0x12b)+_0x1c1d2a[_0x24559a(0x109)]),writeCliSideChannelLine(_0x24559a(0x12b)+_0x1c1d2a[_0x24559a(0xfb)]),_0x1c1d2a['modelRegistryPath']&&writeCliSideChannelLine(_0x24559a(0x12b)+_0x1c1d2a[_0x24559a(0x130)]),_0x1c1d2a[_0x24559a(0x117)]&&writeCliSideChannelLine(_0x24559a(0x12b)+_0x1c1d2a[_0x24559a(0x117)]),_0x2abbcb['push'](toPullData(_0x1c1d2a)),_0x35383e++;}catch(_0x3ad150){_0x55e90d[_0x24559a(0x101)](_0x40bb96[_0x24559a(0xfc)]+':\x20'+(_0x3ad150 instanceof Error?_0x3ad150['message']:String(_0x3ad150))),_0x55359e++;}}writeCliSideChannelLine('');if(_0x55359e>0x0)writeCliSideChannelLine('!\x20'+_0x55359e+'\x20app(s)\x20failed');return{'ok':_0x55359e===0x0,'message':_0x24559a(0xf2)+_0x35383e+_0x24559a(0x12f)+_0x55359e+'\x20failed','data':{'apps':_0x2abbcb,'succeeded':_0x35383e,'failed':_0x55359e}};}const _0x122408=_0x12553&&_0x12553[_0x24559a(0x122)]('-')?_0x12553[_0x24559a(0x11d)]('-')['slice'](0x1)['join']('-'):'',_0x22e393=_0x470a33||_0x304ce5[_0x24559a(0xff)]||DEFAULT_API_DIR,_0x59bbb6=!_0x12553,_0x1908b2=inspectModelRegistry(_0x22e393,_0x304ce5[_0x24559a(0x12d)]),_0x5149ee=_0x304ce5['selectedAppName']||_0x304ce5[_0x24559a(0x134)]?.[_0x24559a(0x121)]||_0x304ce5[_0x24559a(0x134)]?.[_0x24559a(0xf8)]||'default';if(_0x1908b2[_0x24559a(0x139)]&&!_0x1908b2[_0x24559a(0xf1)]&&!_0x1908b2[_0x24559a(0x13e)])throw CliErrors[_0x24559a(0x10d)](MODEL_REGISTRY_FILE_NAME+'\x20does\x20not\x20contain\x20AppCode\x20\x22'+_0x304ce5[_0x24559a(0x12d)]+'\x22.',_0x24559a(0x12c));const _0x21b157=a22_0x3c605c(_0x24559a(0x146)+_0x304ce5[_0x24559a(0x12d)]+_0x24559a(0x120))['start']();try{const {configArray:_0x5d58ae}=await fetchModelList(_0x304ce5[_0x24559a(0x12d)],_0x304ce5[_0x24559a(0x14c)]),_0x2049d0=await generateApiFile(_0x5d58ae,_0x122408,_0x304ce5['appCode'],_0x59bbb6,getEnv(),_0x22e393,undefined,getSdkClientRoutingConfig(),{'overwriteTypescript':_0x1908b2['exists']?![]:_0x5c0380,'allowEmptyModelReplacement':_0x1908b2[_0x24559a(0x139)]?_0x5c0380:undefined,'scaffoldMode':_0x1908b2['exists']?_0x24559a(0x123):undefined,..._0x1908b2[_0x24559a(0xf1)]||_0x1908b2[_0x24559a(0x13e)]||!_0x1908b2['exists']&&_0x5c0380?{'modelProfile':{'name':_0x5149ee,'defaultName':_0x304ce5[_0x24559a(0x134)]?.[_0x24559a(0xf8)]??_0x5149ee,'runtimeDomain':getRuntimeDomain()}}:{}});return _0x21b157[_0x24559a(0x108)](describePull(_0x2049d0)),writeCliSideChannelLine('\x20\x20•\x20'+_0x2049d0[_0x24559a(0xf5)]),writeCliSideChannelLine(_0x24559a(0x12b)+_0x2049d0[_0x24559a(0x109)]),writeCliSideChannelLine(_0x24559a(0x12b)+_0x2049d0[_0x24559a(0xfb)]),_0x2049d0[_0x24559a(0x130)]&&writeCliSideChannelLine(_0x24559a(0x12b)+_0x2049d0[_0x24559a(0x130)]),_0x2049d0['modelRuntimePath']&&writeCliSideChannelLine(_0x24559a(0x12b)+_0x2049d0['modelRuntimePath']),{'ok':!![],'message':describePull(_0x2049d0),'data':toPullData(_0x2049d0)};}catch(_0x57c31a){_0x21b157[_0x24559a(0x101)](_0x24559a(0x11e)+(_0x57c31a instanceof Error?_0x57c31a['message']:String(_0x57c31a)));throw _0x57c31a;}}};
|
|
1
|
+
import ora from"ora";import{getEnv}from"../../constant/env.js";import{fetchModelList}from"../../core/api-client.js";import{generateApiFile}from"../../api/generate-api-file.js";import{APPCODE_FLAG_OPTIONAL}from"../../commands/common/flags.js";import{DEFAULT_API_DIR}from"../../constant/paths.js";import{resolveTargetApps}from"../../commands/api/shared.js";import{writeCliSideChannelLine}from"../../utils/write-cli-side-channel.js";import{getRuntimeDomain,getSdkClientRoutingConfig}from"../../constant/domain.js";import{CliErrors}from"../../errors.js";import{initMultiAppEnvironment}from"../../context.js";import path from"node:path";import{existsSync}from"node:fs";import{MODEL_REGISTRY_FILE_NAME,readModelRegistry}from"../../api/model-registry-file.js";import{getMultiAppConfigs}from"../../utils/config.js";import{getRegistryGroup,resolveApiProfileLayouts}from"../../api/api-group.js"
|
|
2
|
+
;const EXISTING_TS_HINT="Model facts were refreshed, but the stable source entrypoints are not installed. Run `rabetbase project upgrade --dry-run`, then `rabetbase project upgrade --yes`.";function inspectModelRegistry(outputDir,appCode){const registryPath=path.join(outputDir,MODEL_REGISTRY_FILE_NAME);const exists=existsSync(registryPath);if(!exists)return{exists:false,hasAppCode:false,isUnboundTemplate:false};const registry=readModelRegistry(registryPath);if(!registry){throw new Error(`${MODEL_REGISTRY_FILE_NAME} is not a valid Rabetbase generated file. Move or repair it before pulling models again.`)}const appCodes=new Set(Object.values(registry.profiles).map(profile=>profile.appCode).filter(code=>code!=="NOT-SET"));return{exists:true,hasAppCode:!!appCode&&appCodes.has(appCode),isUnboundTemplate:appCodes.size===0}}function toPullData(result){return{appCode:result.appCode,configName:result.configName,isDefaultConfig:result.isDefaultConfig,models:result.models,
|
|
3
|
+
sdkRouting:result.sdkRouting,files:result.files,needsAgentMerge:result.needsAgentMerge,needsProjectUpgrade:result.needsProjectUpgrade,apiFilePath:result.apiFilePath,clientFilePath:result.clientFilePath,sdkConfigPath:result.sdkConfigPath,modelRegistryPath:result.modelRegistryPath,modelRuntimePath:result.modelRuntimePath,modelProfile:result.modelProfile,datasetCount:result.modelCount,modelCount:result.modelCount}}function describePull(result){const sdkConfigName=path.basename(result.sdkConfigPath);if(result.modelProfile){const base=`Fetched ${result.modelCount} dataset fact(s) and refreshed model profile "${result.modelProfile}"`;if(result.needsAgentMerge)return`${base}. ${EXISTING_TS_HINT}`;if(result.files.api.action==="overwritten"||result.files.client.action==="overwritten"){return`${base}; replaced the stable TypeScript entrypoints`}if(result.files.api.action==="created"||result.files.client.action==="created"){return`${base}; created the stable TypeScript entrypoints`}
|
|
4
|
+
return`${base}; preserved the stable TypeScript entrypoints`}if(result.needsAgentMerge){return`Fetched ${result.modelCount} dataset fact(s) and refreshed ${sdkConfigName}. ${EXISTING_TS_HINT}`}if(result.files.api.action==="overwritten"||result.files.client.action==="overwritten"){return`Fetched ${result.modelCount} dataset fact(s) and replaced the TypeScript scaffold with ${result.modelCount} model(s)`}return`Fetched ${result.modelCount} dataset fact(s) and wrote a scaffold with ${result.modelCount} model(s)`}export const apiPull={service:"api",command:"pull",description:`Pull dataset facts and refresh the generated SDK model registry (${DEFAULT_API_DIR}/)`,risk:"read",requiresAppCode:true,hasFormat:true,flags:[{...APPCODE_FLAG_OPTIONAL,hidden:true},{name:"output",type:"string",description:`Output directory (default: ${DEFAULT_API_DIR}/)`},{name:"global",type:"boolean",description:"Resolve apps from merged global+project config (default: project apps only)",default:false},{
|
|
5
|
+
name:"force",type:"boolean",description:"Accept an empty model result, or replace a legacy prefixed scaffold; requires --yes",default:false}],async validate(ctx){if(ctx.bool("force")&&!ctx.bool("yes")){throw CliErrors.validation("--force requires --yes because it may remove existing model facts or replace a legacy generated scaffold.","Verify the selected profile and review legacy generated files, then rerun with --force --yes.")}},async execute(ctx){const explicitAppcode=ctx.rawFlags.appcode?String(ctx.rawFlags.appcode):undefined;const output=ctx.str("output")||undefined;const force=ctx.bool("force");const targetApps=resolveTargetApps(ctx,explicitAppcode);const scope=ctx.bool("global")?"merged":"project";const configuredApps=getMultiAppConfigs(scope);const resolveOutputDir=app=>app.apiDir||output||ctx.apiDir||DEFAULT_API_DIR;const configuredLayouts=configuredApps?resolveApiProfileLayouts(configuredApps,resolveOutputDir):undefined;let effectiveTargetApps=targetApps
|
|
6
|
+
;if(!effectiveTargetApps&&configuredApps){const selectedByName=ctx.selectedAppName?configuredApps.find(app=>app.name===ctx.selectedAppName):undefined;const appCodeMatches=configuredApps.filter(app=>app.appcode===ctx.appCode);if(!selectedByName&&appCodeMatches.length>1){throw CliErrors.validation(`AppCode "${ctx.appCode}" belongs to multiple app profiles: ${appCodeMatches.map(app=>app.name).join(", ")}.`,"Select the target explicitly with --app <profile>.")}const selected=selectedByName??appCodeMatches[0];if(selected)effectiveTargetApps=[selected]}if(effectiveTargetApps){let succeeded=0;let failed=0;const apps=[];const allLayouts=configuredLayouts??resolveApiProfileLayouts(effectiveTargetApps,resolveOutputDir);for(const app of effectiveTargetApps){const appCookie=app.cookie||ctx.cookie;const appEnv=app.env||"production";await initMultiAppEnvironment(app);const layout=allLayouts.find(candidate=>candidate.app.name===app.name);if(!layout){
|
|
7
|
+
throw new Error(`Internal error: API layout for app profile "${app.name}" was not resolved.`)}const registryGroup=getRegistryGroup(allLayouts,layout);const outputDir=layout.outputDir;const filePrefix=registryGroup?"":app.isDefault?"":app.name||app.appcode;const configuredDefault=registryGroup?.find(candidate=>candidate.app.isDefault)??registryGroup?.[0];if(registryGroup)inspectModelRegistry(outputDir);const spinner=ora(`Pulling ${app.name} (${app.appcode})...`).start();try{const{configArray:configArray}=await fetchModelList(app.appcode,appCookie);const result=await generateApiFile(configArray,filePrefix,app.appcode,app.isDefault,appEnv,outputDir,app.name,getSdkClientRoutingConfig(),{overwriteTypescript:registryGroup?false:force,allowEmptyModelReplacement:registryGroup?force:undefined,scaffoldMode:registryGroup?"none":undefined,...registryGroup?{modelProfile:{name:app.name,defaultName:configuredDefault.app.name,runtimeDomain:getRuntimeDomain()}}:{}})
|
|
8
|
+
;spinner.succeed(`${app.name}: ${describePull(result)}`);writeCliSideChannelLine(` • ${result.sdkConfigPath}`);writeCliSideChannelLine(` • ${result.apiFilePath}`);writeCliSideChannelLine(` • ${result.clientFilePath}`);if(result.modelRegistryPath){writeCliSideChannelLine(` • ${result.modelRegistryPath}`)}if(result.modelRuntimePath){writeCliSideChannelLine(` • ${result.modelRuntimePath}`)}apps.push(toPullData(result));succeeded++}catch(err){spinner.fail(`${app.name}: ${err instanceof Error?err.message:String(err)}`);failed++}}writeCliSideChannelLine("");if(failed>0)writeCliSideChannelLine(`! ${failed} app(s) failed`);return{ok:failed===0,message:`Done: ${succeeded} succeeded, ${failed} failed`,data:{apps:apps,succeeded:succeeded,failed:failed}}}const filePrefix=explicitAppcode&&explicitAppcode.includes("-")?explicitAppcode.split("-").slice(1).join("-"):"";const outputDir=output||ctx.apiDir||DEFAULT_API_DIR;const isFromDefaultConfig=!explicitAppcode
|
|
9
|
+
;const registry=inspectModelRegistry(outputDir,ctx.appCode);const profileName=ctx.selectedAppName||ctx.mergedCli?.currentApp||ctx.mergedCli?.defaultApp||"default";if(registry.exists&&!registry.hasAppCode&&!registry.isUnboundTemplate){throw CliErrors.validation(`${MODEL_REGISTRY_FILE_NAME} does not contain AppCode "${ctx.appCode}".`,"Select a configured app profile or use a separate apiDir.")}const spinner=ora(`Pulling API config for ${ctx.appCode}...`).start();try{const{configArray:configArray}=await fetchModelList(ctx.appCode,ctx.cookie);const result=await generateApiFile(configArray,filePrefix,ctx.appCode,isFromDefaultConfig,getEnv(),outputDir,undefined,getSdkClientRoutingConfig(),{overwriteTypescript:registry.exists?false:force,allowEmptyModelReplacement:registry.exists?force:undefined,scaffoldMode:registry.exists?"none":undefined,...registry.hasAppCode||registry.isUnboundTemplate||!registry.exists&&force?{modelProfile:{name:profileName,
|
|
10
|
+
defaultName:ctx.mergedCli?.defaultApp??profileName,runtimeDomain:getRuntimeDomain()}}:{}});spinner.succeed(describePull(result));writeCliSideChannelLine(` • ${result.sdkConfigPath}`);writeCliSideChannelLine(` • ${result.apiFilePath}`);writeCliSideChannelLine(` • ${result.clientFilePath}`);if(result.modelRegistryPath){writeCliSideChannelLine(` • ${result.modelRegistryPath}`)}if(result.modelRuntimePath){writeCliSideChannelLine(` • ${result.modelRuntimePath}`)}return{ok:true,message:describePull(result),data:toPullData(result)}}catch(err){spinner.fail(`Failed: ${err instanceof Error?err.message:String(err)}`);throw err}}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{getMultiAppConfigs}from"../../utils/config.js";import{CliErrors}from"../../errors.js";export function resolveTargetApps(ctx,explicitAppcode){if(explicitAppcode)return null;const scope=ctx.bool("global")?"merged":"project";let multiApps=getMultiAppConfigs(scope);if(!multiApps||multiApps.length===0)return null;if(ctx.selectedAppName){const filtered=multiApps.filter(a=>a.name===ctx.selectedAppName);if(filtered.length===0){const available=multiApps.map(a=>a.name).join(", ");throw CliErrors.validation(`App "${ctx.selectedAppName}" not found in config. Available: ${available}`)}multiApps=filtered}return multiApps}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{APPCODE_FLAG_OPTIONAL}from"../../commands/common/flags.js";import{getAppVipDeploy}from"../../core/api-client.js";export const appDetailDefinition={service:"app",command:"detail",description:"Read the platform's vipDeploy flag for independent deployment data sync",risk:"read",requiresAuth:true,requiresAppCode:true,structuredErrors:true,flags:[APPCODE_FLAG_OPTIONAL],async execute(ctx){const vipDeploy=await getAppVipDeploy(ctx.appCode,ctx.cookie);return{ok:true,data:{vipDeploy:vipDeploy??null},message:vipDeploy===undefined?"Application vipDeploy is unknown: the platform did not return a boolean flag.":"Platform deployment sync flag read; automatic sync, runtime login and sync progress are not assessed."}}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{appListDefinition}from"../../commands/app/list.js";import{appMembersListDefinition}from"../../commands/app/members-list.js";import{appDetailDefinition}from"../../commands/app/detail.js";export const appDefinitions=[appListDefinition,appDetailDefinition,appMembersListDefinition];
|
package/lib/commands/app/list.js
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import{readRawConfigWithLayers}from"../../context.js";import{CLI_BIN_NAME}from"../../constant/cli.js";import{CliErrors}from"../../errors.js";import{buildAppProfileListFields}from"../../config/schema.js";import{appDefinedIn,enrichAppListItemsWithMergedSelection,resolveDefaultAppSource}from"../../commands/app/shared.js";import{listRemoteAppDirectory}from"../../commands/app/remote-directory.js";import{resolveEffectiveRegion}from"../../config/region-config.js";function buildItemsFromLayer(layerConfig,definedIn,inheritedRegion){const items=[];const apps=layerConfig.apps&&typeof layerConfig.apps==="object"?layerConfig.apps:{};const explicitDefault=layerConfig.defaultApp||undefined;const defaultApp=explicitDefault??(Object.keys(apps).length===1?Object.keys(apps)[0]:undefined);for(const[name,profile]of Object.entries(apps)){if(!profile||typeof profile!=="object"||!profile.appcode)continue;const resolvedRegion=resolveEffectiveRegion({appRegion:profile.region,
|
|
2
|
+
projectRegion:definedIn==="project"?layerConfig.region:undefined,globalRegion:definedIn==="global"?layerConfig.region:inheritedRegion,appName:name});items.push({name:name,appcode:profile.appcode,named:true,definedIn:definedIn,isDefault:name===defaultApp,...buildAppProfileListFields(profile),effectiveRegion:resolvedRegion.region,regionSource:resolvedRegion.source})}return items}function buildMergedItems(config,layers){const{apps:apps={}}=config;const explicitDefault=config.defaultApp;const defaultApp=explicitDefault??(Object.keys(apps).length===1?Object.keys(apps)[0]:undefined);const globalApps=layers.globalConfig.apps&&typeof layers.globalConfig.apps==="object"?layers.globalConfig.apps:{};const projectApps=layers.projectConfig.apps&&typeof layers.projectConfig.apps==="object"?layers.projectConfig.apps:{};const entries=Object.entries(apps);const items=entries.map(([name,profile])=>{const definedIn=appDefinedIn(name,globalApps,projectApps)
|
|
3
|
+
;const isProjectDefinition=Object.prototype.hasOwnProperty.call(projectApps,name);const resolvedRegion=resolveEffectiveRegion({appRegion:profile.region,projectRegion:isProjectDefinition?layers.projectConfig.region:undefined,globalRegion:layers.globalConfig.region,mergedRegion:config.region,appName:name});return{name:name,appcode:profile.appcode,named:true,definedIn:definedIn,isDefault:name===defaultApp,...buildAppProfileListFields(profile),effectiveRegion:resolvedRegion.region,regionSource:resolvedRegion.source}});return items}function validateAppListFlags(ctx){if(!ctx.bool("remote"))return;if(!ctx.bool("global")&&!ctx.bool("project"))return;throw CliErrors.validation("`--remote` cannot be used with `--global` or `--project`.","Use `rabetbase app list --remote` for the platform directory, or `rabetbase app list --global/--project` for local config.")}async function execute(ctx){validateAppListFlags(ctx);if(ctx.bool("remote")){return{ok:true,data:await listRemoteAppDirectory(ctx)}}
|
|
4
|
+
const isGlobal=ctx.bool("global");const isProject=ctx.bool("project");const scope=isGlobal?"global":isProject?"project":"merged";const{config:config,layers:layers}=readRawConfigWithLayers();const defaultAppSource=resolveDefaultAppSource(layers);const{defaultApp:defaultApp}=config;let items;let configPath;switch(scope){case"global":items=buildItemsFromLayer(layers.globalConfig,"global");configPath=layers.globalPath;break;case"project":items=buildItemsFromLayer(layers.projectConfig,"project",layers.globalConfig.region);configPath=layers.projectPath;break;default:items=buildMergedItems(config,layers);break}enrichAppListItemsWithMergedSelection(items,ctx.mergedCli);if(items.length===0){const hint=scope==="merged"?"":` in ${scope} config`;return{ok:true,data:[],message:`No apps configured${hint}. Use \`${CLI_BIN_NAME} workspace add <name> --appcode <code>\` to add one.`}}const currentItem=items.find(i=>i.isCurrent===true);const effectiveDefault=defaultApp??currentItem?.name??null
|
|
5
|
+
;const meta=scope==="merged"?{globalPath:layers.globalPath??null,projectPath:layers.projectPath??null,defaultApp:effectiveDefault,defaultAppSource:defaultApp!=null?defaultAppSource:null}:{scope:scope,configPath:configPath??null};return{ok:true,data:{items:items,meta:meta}}}export const appListDefinition={service:"app",command:"list",description:"List configured apps, or platform apps with --remote",risk:"read",auth:"optional",requiresAuth:false,requiresAppCode:false,flags:[{name:"remote",type:"boolean",description:"List apps available on the platform for the current login",default:false},{name:"global",type:"boolean",description:"Show only apps from global ~/.rabetbase.json",default:false},{name:"project",type:"boolean",description:"Show only apps from project .rabetbase.json",default:false}],async validate(ctx){validateAppListFlags(ctx)},execute:execute};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{APPCODE_FLAG_OPTIONAL}from"../../commands/common/flags.js";import{projectAppMembers}from"../../commands/app/shared.js";import{listRoleUsers}from"../../core/api-client.js";export const appMembersListDefinition={service:"app",command:"members-list",description:"List application members with their role memberships",risk:"read",requiresAuth:true,requiresAppCode:true,structuredErrors:true,flags:[APPCODE_FLAG_OPTIONAL],async execute(ctx){const items=projectAppMembers(await listRoleUsers(ctx.appCode));return{ok:true,data:{appCode:ctx.appCode,items:items,totalCount:items.length},message:`Found ${items.length} application member(s)`}}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{listRemoteApps}from"../../core/api-client.js";import{getCookie}from"../../auth/get-cookie.js";import{CliErrors}from"../../errors.js";import{withActiveCookie}from"../../utils/with-active-cookie.js";function resolveCookie(ctx){const cookie=ctx.cookie||getCookie();if(!cookie)throw CliErrors.authRequired();return cookie}export async function listRemoteAppDirectory(ctx){const apps=await withActiveCookie(resolveCookie(ctx),()=>listRemoteApps());return{items:apps.map(app=>({...app.id!=null?{id:app.id}:{},appCode:app.appCode,appName:app.appName,...app.appDesc!=null?{appDesc:app.appDesc}:{}})),meta:{source:"platform"}}}
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import{resolveWriteConfigPath,readConfigFile,writeConfigFile}from"../../context.js";function nullableText(value){const normalized=value?.trim();return normalized?normalized:null}export function projectAppMembers(groups){const members=new Map;const sortedGroups=[...groups].sort((left,right)=>left.id-right.id);const addUsers=(group,users,membershipStatus)=>{for(const user of users){const userId=Number(user.userId);if(!Number.isFinite(userId)||userId<=0)continue;let member=members.get(userId);if(!member){member={userId:userId,username:nullableText(user.username),displayName:nullableText(user.nickname),status:membershipStatus,roles:[],roleKeys:new Set};members.set(userId,member)}else{member.username??=nullableText(user.username);member.displayName??=nullableText(user.nickname);if(membershipStatus==="ACTIVE")member.status="ACTIVE"}const roleKey=`${group.id}:${membershipStatus}`;if(member.roleKeys.has(roleKey))continue;member.roleKeys.add(roleKey);member.roles.push({roleId:group.id,
|
|
2
|
+
roleCode:group.roleCode,roleName:nullableText(group.roleName),roleType:nullableText(group.roleType),membershipStatus:membershipStatus})}};for(const group of sortedGroups){addUsers(group,group.userList??[],"ACTIVE");addUsers(group,group.applyUserList??[],"PENDING")}return[...members.values()].map(member=>({userId:member.userId,username:member.username,displayName:member.displayName,status:member.status,roles:member.roles.sort((left,right)=>left.roleId-right.roleId||(left.membershipStatus===right.membershipStatus?0:left.membershipStatus==="ACTIVE"?-1:1))})).sort((left,right)=>left.userId-right.userId)}export function enrichAppListItemsWithMergedSelection(items,merged){if(!merged)return;const apps=merged.apps&&typeof merged.apps==="object"?merged.apps:{};const isMultiApp=Object.keys(apps).length>0;for(const item of items){item.isCurrent=false}const appCodeStr=merged.appCode!=null?String(merged.appCode).trim():"";if(isMultiApp){const eff=merged.currentApp??merged.defaultApp;if(eff){
|
|
3
|
+
for(const item of items){if(item.named===true&&item.name===eff){item.isCurrent=true}}}for(const item of items){if(item.named!==false)continue;if(merged.defaultApp)continue;if(appCodeStr&&String(item.appcode??"").trim()===appCodeStr){item.isCurrent=true}}return}if(!appCodeStr)return;for(const item of items){if(String(item.appcode??"").trim()===appCodeStr){item.isCurrent=true}}}export function resolveAppScopeForWrite(name,explicitGlobal,layers){if(explicitGlobal)return"global";const projectApps=layers.projectConfig.apps&&typeof layers.projectConfig.apps==="object"?layers.projectConfig.apps:{};const globalApps=layers.globalConfig.apps&&typeof layers.globalConfig.apps==="object"?layers.globalConfig.apps:{};if(Object.prototype.hasOwnProperty.call(projectApps,name))return"project";if(Object.prototype.hasOwnProperty.call(globalApps,name))return"global";return"project"}export function appDefinedIn(name,globalApps,projectApps){const g=Object.prototype.hasOwnProperty.call(globalApps,name)
|
|
4
|
+
;const p=Object.prototype.hasOwnProperty.call(projectApps,name);if(g&&p)return"both";if(p)return"project";return"global"}export function resolveDefaultAppSource(layers){const projectApps=layers.projectConfig.apps&&typeof layers.projectConfig.apps==="object"?layers.projectConfig.apps:{};if("defaultApp"in layers.projectConfig)return"project";if(Object.keys(projectApps).length>0)return"project";if(Object.keys(layers.projectConfig).length===0&&layers.globalConfig.defaultApp)return"global";return null}export function getConfigPath(flags={}){const scope=flags.global?"global":"project";return resolveWriteConfigPath(scope)}export function readConfig(flags={}){return readConfigFile(getConfigPath(flags))}export function writeConfig(config,flags={}){writeConfigFile(getConfigPath(flags),config)}export function scopeLabel(flags){return flags.global?" (global)":""}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{deleteAppConfig,getAppConfigByKey}from"../../core/api-client.js";import{CliErrors}from"../../errors.js";import{APPCODE_FLAG_OPTIONAL}from"../../commands/common/flags.js";import{asAppConfigDryRunResult,buildMutationData,KEY_ARG,projectAppConfig,requireAppConfigId,readKeyArg,withAppConfigApiBoundary}from"../../commands/app-config/shared.js";const DELETE_PATH="/smartapi/app-config/delete";export const appConfigDelete={service:"app-config",command:"delete",description:"Delete one runtime app-config key",risk:"high-risk-write",args:[KEY_ARG],flags:[APPCODE_FLAG_OPTIONAL],async validate(ctx){readKeyArg(ctx)},async dryRun(ctx){const key=readKeyArg(ctx);const before=await mustGetByKey(ctx.appCode,key);requireAppConfigId(before);return asAppConfigDryRunResult(buildMutationData({operation:"delete",appCode:ctx.appCode,key:key,before:projectAppConfig(before),after:null,dryRun:true}),{method:"POST",url:DELETE_PATH})},async execute(ctx){const key=readKeyArg(ctx)
|
|
2
|
+
;const before=await mustGetByKey(ctx.appCode,key);await withAppConfigApiBoundary("delete",{appCode:ctx.appCode,key:key},()=>deleteAppConfig({appCode:ctx.appCode,id:requireAppConfigId(before)}));return{ok:true,data:buildMutationData({operation:"delete",appCode:ctx.appCode,key:key,before:projectAppConfig(before),after:null,dryRun:false}),message:`Deleted app config ${key}`}}};async function mustGetByKey(appCode,key){const item=await withAppConfigApiBoundary("get",{appCode:appCode,key:key},()=>getAppConfigByKey(appCode,key));if(!item){throw CliErrors.validation(`App config key not found: ${key}`,`appCode: ${appCode}`)}return item}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{getAppConfigByKey}from"../../core/api-client.js";import{CliErrors}from"../../errors.js";import{APPCODE_FLAG_OPTIONAL}from"../../commands/common/flags.js";import{KEY_ARG,projectAppConfig,readKeyArg,REVEAL_FLAG,withAppConfigApiBoundary}from"../../commands/app-config/shared.js";export const appConfigGet={service:"app-config",command:"get",description:"Inspect one runtime app-config key; value is redacted unless --reveal is used",risk:"read",args:[KEY_ARG],flags:[APPCODE_FLAG_OPTIONAL,REVEAL_FLAG],async validate(ctx){readKeyArg(ctx)},async execute(ctx){const key=readKeyArg(ctx);const item=await withAppConfigApiBoundary("get",{appCode:ctx.appCode,key:key},()=>getAppConfigByKey(ctx.appCode,key));if(!item){throw CliErrors.validation(`App config key not found: ${key}`,`appCode: ${ctx.appCode}`)}const config=projectAppConfig(item,{reveal:ctx.bool("reveal")});return{ok:true,data:{config:config},
|
|
2
|
+
message:ctx.bool("reveal")?`Loaded app config ${key} with value revealed`:`Loaded app config ${key} with value redacted`}}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{appConfigList}from"../../commands/app-config/list.js";import{appConfigGet}from"../../commands/app-config/get.js";import{appConfigSet}from"../../commands/app-config/set.js";import{appConfigDelete}from"../../commands/app-config/delete.js";export const appConfigDefinitions=[appConfigList,appConfigGet,appConfigSet,appConfigDelete];
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{listAppConfigs}from"../../core/api-client.js";import{APPCODE_FLAG_OPTIONAL}from"../../commands/common/flags.js";import{projectAppConfig,readOptionalTags,TAGS_FLAG,validateKey,withAppConfigApiBoundary}from"../../commands/app-config/shared.js";export const appConfigList={service:"app-config",command:"list",description:"List runtime app-config key metadata without printing values",risk:"read",flags:[APPCODE_FLAG_OPTIONAL,{name:"key",type:"string",description:"Filter by exact config key"},TAGS_FLAG],async validate(ctx){const key=ctx.str("key").trim();if(key)validateKey(key);readOptionalTags(ctx)},async execute(ctx){const key=ctx.str("key").trim()||undefined;const tags=readOptionalTags(ctx);const items=await withAppConfigApiBoundary("list",{appCode:ctx.appCode},()=>listAppConfigs(ctx.appCode,{key:key,tags:tags}));const configs=items.map(item=>projectAppConfig(item));return{ok:true,data:{appCode:ctx.appCode,count:configs.length,configs:configs},
|
|
2
|
+
message:`Found ${configs.length} app config(s)`}}};
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import{createAppConfig,getAppConfigByKey,updateAppConfig}from"../../core/api-client.js";import{APPCODE_FLAG_OPTIONAL}from"../../commands/common/flags.js";import{assertSingleValueSource,assertValueSourceReadable,asAppConfigDryRunResult,buildMutationData,FROM_ENV_FLAG,KEY_ARG,plannedAppConfig,projectAppConfig,requireAppConfigId,readAppConfigValue,readKeyArg,readOptionalTags,STDIN_FLAG,TAGS_FLAG,VALUE_ARG,withAppConfigApiBoundary}from"../../commands/app-config/shared.js";const CREATE_PATH="/smartapi/app-config/create";const UPDATE_PATH="/smartapi/app-config/update";export const appConfigSet={service:"app-config",command:"set",description:"Create or update one runtime app-config key",risk:"write",args:[KEY_ARG,VALUE_ARG],flags:[APPCODE_FLAG_OPTIONAL,TAGS_FLAG,STDIN_FLAG,FROM_ENV_FLAG,{name:"file",type:"string",description:"Read config value from file"}],async validate(ctx){readKeyArg(ctx);readOptionalTags(ctx);assertSingleValueSource(ctx)},async dryRun(ctx){const key=readKeyArg(ctx)
|
|
2
|
+
;const tags=readOptionalTags(ctx);const source=assertSingleValueSource(ctx);await assertValueSourceReadable(source);const before=await withAppConfigApiBoundary("get",{appCode:ctx.appCode,key:key},()=>getAppConfigByKey(ctx.appCode,key));if(before)requireAppConfigId(before);const operation=before?"update":"create";const beforeProjection=before?projectAppConfig(before):null;const afterProjection=plannedAppConfig({appCode:ctx.appCode,key:key,tags:tags??before?.tags,hasValue:true});return asAppConfigDryRunResult(buildMutationData({operation:operation,appCode:ctx.appCode,key:key,before:beforeProjection,after:afterProjection,dryRun:true}),{method:"POST",url:operation==="update"?UPDATE_PATH:CREATE_PATH})},async execute(ctx){const key=readKeyArg(ctx);const tags=readOptionalTags(ctx);const before=await withAppConfigApiBoundary("get",{appCode:ctx.appCode,key:key},()=>getAppConfigByKey(ctx.appCode,key));const beforeProjection=before?projectAppConfig(before):null
|
|
3
|
+
;if(before)requireAppConfigId(before);const operation=before?"update":"create";const{value:value,warnings:warnings}=await readAppConfigValue(ctx);const writeInput={appCode:ctx.appCode,key:key,value:value,tags:tags??before?.tags??undefined};await withAppConfigApiBoundary(operation,{appCode:ctx.appCode,key:key},async()=>{if(before){await updateAppConfig({...writeInput,id:requireAppConfigId(before)})}else{await createAppConfig(writeInput)}});const after=await withAppConfigApiBoundary("get",{appCode:ctx.appCode,key:key},()=>getAppConfigByKey(ctx.appCode,key));const afterProjection=after?projectAppConfig(after):plannedAppConfig({appCode:ctx.appCode,key:key,tags:writeInput.tags,hasValue:value!==""});return{ok:true,data:buildMutationData({operation:operation,appCode:ctx.appCode,key:key,before:beforeProjection,after:afterProjection,dryRun:false,warnings:warnings}),message:`${operation==="update"?"Updated":"Created"} app config ${key}`}}};
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import type { AppConfigItem } from "../../core/api-client.js";
|
|
2
2
|
import type { CommandDefinition, DryRunResult, RuntimeContext } from "../../framework/types.js";
|
|
3
3
|
export interface AppConfigProjection {
|
|
4
|
+
id?: number | string;
|
|
5
|
+
description?: string | null;
|
|
6
|
+
operatorId?: number | string | null;
|
|
7
|
+
operatorUsername?: string | null;
|
|
8
|
+
operatorNickname?: string | null;
|
|
4
9
|
appCode: string;
|
|
5
10
|
key: string;
|
|
6
11
|
tags?: string | null;
|
|
7
12
|
hasValue: boolean;
|
|
8
13
|
valueRedacted: boolean;
|
|
9
|
-
gmtCreate?:
|
|
10
|
-
gmtModified?:
|
|
14
|
+
gmtCreate?: number | null;
|
|
15
|
+
gmtModified?: number | null;
|
|
11
16
|
value?: string | null;
|
|
12
17
|
}
|
|
13
18
|
export interface AppConfigMutationData {
|
|
@@ -72,6 +77,8 @@ export declare function validateKey(key: string): void;
|
|
|
72
77
|
export declare function projectAppConfig(item: AppConfigItem, options?: {
|
|
73
78
|
reveal?: boolean;
|
|
74
79
|
}): AppConfigProjection;
|
|
80
|
+
/** Keep the server ID representation; never round a Long before a write. */
|
|
81
|
+
export declare function requireAppConfigId(item: AppConfigItem): number | string;
|
|
75
82
|
export declare function plannedAppConfig(params: {
|
|
76
83
|
appCode: string;
|
|
77
84
|
key: string;
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import{access,readFile}from"node:fs/promises";import{CliErrors}from"../../errors.js";export const KEY_ARG={name:"key",description:"Runtime app-config key",required:true};export const VALUE_ARG={name:"value",description:"Sensitive config value. Prefer --stdin, --from-env, or --file for secrets.",required:false};export const TAGS_FLAG={name:"tags",type:"string",description:"Config tags for filtering/display metadata"};export const STDIN_FLAG={name:"stdin",type:"boolean",description:"Read config value from stdin",default:false};export const FROM_ENV_FLAG={name:"from-env",type:"string",description:"Read config value from the named environment variable"};export const REVEAL_FLAG={name:"reveal",type:"boolean",description:"Reveal the sensitive value for this single key",default:false};export function readKeyArg(ctx){const key=ctx.args[0]?.trim()??"";validateKey(key);return key}export function readOptionalTags(ctx){const tags=ctx.str("tags").trim();if(!tags)return undefined;if(tags.length>32){
|
|
2
|
+
throw CliErrors.validation("App config tags length cannot exceed 32.")}return tags}export function validateKey(key){if(!key){throw CliErrors.validation("Missing app-config key.")}if(key.length>256){throw CliErrors.validation("App config key length cannot exceed 256.")}}export function projectAppConfig(item,options){const hasValue=item.value!==undefined&&item.value!==null&&item.value!=="";const projected={id:item.id,description:item.description,operatorId:item.operatorId,operatorUsername:item.operatorUsername,operatorNickname:item.operatorNickname,appCode:item.appCode,key:item.key,tags:item.tags??undefined,hasValue:hasValue,valueRedacted:hasValue&&!options?.reveal,gmtCreate:item.gmtCreate,gmtModified:item.gmtModified};if(options?.reveal){projected.value=item.value??"";projected.valueRedacted=false}return projected}export function requireAppConfigId(item){const id=item.id;if(typeof id==="string"&&/^[1-9][0-9]*$/.test(id))return id
|
|
3
|
+
;if(typeof id==="number"&&Number.isSafeInteger(id)&&id>0)return id;throw CliErrors.apiError(`App config server id missing or invalid for key=${item.key}, appCode=${item.appCode}`)}export function plannedAppConfig(params){const hasValue=params.hasValue??true;return{appCode:params.appCode,key:params.key,tags:params.tags??undefined,hasValue:hasValue,valueRedacted:hasValue}}export function buildMutationData(params){return{operation:params.operation,selector:{appCode:params.appCode,key:params.key},before:params.before,after:params.after,dryRun:params.dryRun,warnings:params.warnings??[]}}export async function withAppConfigApiBoundary(operation,selector,fn){try{return await fn()}catch{const parts=[`appCode: ${selector.appCode}`];if(selector.key)parts.push(`key: ${selector.key}`);parts.push("value is redacted");throw CliErrors.apiError(`Failed to ${operation} app config.`,`${parts.join("; ")}.`)}}export function asAppConfigDryRunResult(data,backend){return Object.defineProperties(data,{
|
|
4
|
+
method:{value:backend.method,enumerable:false},url:{value:backend.url,enumerable:false}})}export function assertSingleValueSource(ctx){const sources=[];if(ctx.args.length>1){sources.push({kind:"argument",value:ctx.args.slice(1).join(" ")})}const rawValueFlag=ctx.flag("value");if(rawValueFlag!==undefined&&rawValueFlag!==null){sources.push({kind:"argument",value:String(rawValueFlag)})}if(ctx.bool("stdin")){sources.push({kind:"stdin"})}const envName=ctx.str("from-env").trim();if(envName){sources.push({kind:"env",name:envName})}const filePath=ctx.str("file").trim();if(filePath){sources.push({kind:"file",path:filePath})}if(sources.length===0){throw CliErrors.validation("Missing app-config value source.","Use one of: positional <value>, --stdin, --from-env <NAME>, or --file <path>.")}if(sources.length>1){throw CliErrors.validation("App config value source is ambiguous.","Use exactly one of: positional <value>, --stdin, --from-env <NAME>, or --file <path>.")}return sources[0]}
|
|
5
|
+
export async function assertValueSourceReadable(source){if(source.kind==="env"&&!(source.name in process.env)){throw CliErrors.validation(`Environment variable is not set: ${source.name}`)}if(source.kind==="file"){try{await access(source.path)}catch{throw CliErrors.validation(`Value file is not readable: ${source.path}`)}}}export async function readAppConfigValue(ctx){const source=assertSingleValueSource(ctx);const warnings=[];if(source.kind==="argument"){warnings.push("Value was provided as a command argument; prefer --stdin, --from-env, or --file for secrets.");return{value:source.value??"",source:source.kind,warnings:warnings}}if(source.kind==="stdin"){return{value:await readStdin(),source:source.kind,warnings:warnings}}if(source.kind==="env"){if(!(source.name in process.env)){throw CliErrors.validation(`Environment variable is not set: ${source.name}`)}return{value:process.env[source.name]??"",source:source.kind,warnings:warnings}}return{value:await readFile(source.path,"utf8"),
|
|
6
|
+
source:source.kind,warnings:warnings}}function readStdin(){return new Promise((resolve,reject)=>{let data="";process.stdin.setEncoding("utf8");process.stdin.on("data",chunk=>{data+=chunk});process.stdin.once("end",()=>resolve(data));process.stdin.once("error",reject)})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{unlinkSync,existsSync}from"node:fs";import{cookieFile}from"../../auth/constant.js";export const authDefinitions=[{service:"auth",command:"login",description:"Login via browser",risk:"write",requiresAuth:false,requiresAppCode:false,hasFormat:false,flags:[{name:"yes",type:"boolean",description:"Skip login confirmation and start browser auth immediately",default:false}],async execute(ctx){const{runAuthServer:runAuthServer}=await(import("../../auth/auth-server-ui.js"));await runAuthServer({autoYes:ctx.bool("yes"),nonInteractive:ctx.nonInteractive});return{ok:true}}},{service:"auth",command:"logout",description:"Clear login session",risk:"write",requiresAuth:false,requiresAppCode:false,hasFormat:false,flags:[],async execute(_ctx){if(existsSync(cookieFile)){unlinkSync(cookieFile);console.log("✓ Logged out")}else{console.log("! Not logged in")}return{ok:true}}}];
|
|
@@ -1 +1,11 @@
|
|
|
1
|
-
const a37_0x375ddc=a37_0x3547;(function(_0x431f4a,_0x59d52f){const _0x3ae49f=a37_0x3547,_0x72f072=_0x431f4a();while(!![]){try{const _0x4819d7=-parseInt(_0x3ae49f(0x152))/0x1+-parseInt(_0x3ae49f(0x162))/0x2*(-parseInt(_0x3ae49f(0x14b))/0x3)+-parseInt(_0x3ae49f(0x183))/0x4+-parseInt(_0x3ae49f(0x185))/0x5*(-parseInt(_0x3ae49f(0x180))/0x6)+parseInt(_0x3ae49f(0x1ae))/0x7*(-parseInt(_0x3ae49f(0x14e))/0x8)+-parseInt(_0x3ae49f(0x18d))/0x9*(parseInt(_0x3ae49f(0x197))/0xa)+parseInt(_0x3ae49f(0x198))/0xb*(parseInt(_0x3ae49f(0x19a))/0xc);if(_0x4819d7===_0x59d52f)break;else _0x72f072['push'](_0x72f072['shift']());}catch(_0x2858dd){_0x72f072['push'](_0x72f072['shift']());}}}(a37_0x3f05,0xe0c9b));import{createInterface}from'node:readline';import{mkdir,writeFile}from'node:fs/promises';import{dirname,join}from'node:path';import{listDatasets,listBffDatasetOperations}from'../../core/api-client.js';import{loadAliasMap,resolveAlias}from'../../core/alias-resolver.js';function a37_0x3547(_0x498833,_0x471839){_0x498833=_0x498833-0x143;const _0x3f0556=a37_0x3f05();let _0x3547d5=_0x3f0556[_0x498833];return _0x3547d5;}import{resolveApiModelSource}from'../../api/model-source.js';import{loadBffProjectConfig}from'../../core/bff/config.js';import{fileExists}from'../../core/bff/file-system.js';import{DEFAULT_BFF_SCRIPT_DESCRIPTION,isValidBffFunctionName,normalizeHookFunctionNode}from'../../core/bff/utils.js';import{CliErrors}from'../../errors.js';import{CLI_BIN_NAME}from'../../constant/cli.js';function a37_0x3f05(){const _0x5a471d=['No\x20operation\x20types\x20found\x20for\x20dataset\x20','9584okbFKc','datasetCode','\x0a\x20*\x0a\x20*\x20[脚本类型]\x20ENDPOINT\x0a\x20*\x20[脚本名称]\x20','map','1196161WeQOKF','description','Select\x20operation\x20type:','Select\x20trigger\x20node:','name','修改后的请求参数','datasetcode','Alias\x20\x22','str','Invalid\x20dataset\x20selection.','keys','当前响应结果','HOOK\x20requires\x20alias/operation/node\x20options.','Scaffold\x20a\x20new\x20Backend\x20Function\x20script\x20from\x20template','HOOK','Operation\x20type\x20\x22','109248HjkpmS','length','bff','stdin','alias','tableName','/**\x0a\x20*\x20','/ENDPOINT/','.js\x0a\x20*\x20[触发节点]\x20','appCode','\x0a\x20*\x20[参数字段]\x20按实际输入为\x20params.<字段名>\x20补充\x20JSDoc\x20参数标签;无字段时仅保留根参数\x0a\x20*\x20[异常说明]\x20无;显式抛出异常时补充异常类型与触发条件\x0a\x20*\x0a\x20*\x20@param\x20{Object}\x20params\x20请求参数\x0a\x20*\x20@param\x20{Object}\x20context\x20平台注入的执行上下文\x0a\x20*\x20@returns\x20{Promise<Object>}\x20TODO:\x20补充返回数据结构\x0a\x20*/\x0aexport\x20default\x20async\x20function\x20','/data/backend-function\x0a\x20*\x20[本地路径]\x20.rabetbase/bff/','nonInteractive','operationType','--operation-type\x20is\x20required\x20for\x20HOOK\x20in\x20non-interactive\x20mode.','datasetId','--function-node\x20must\x20be\x20\x27before\x27\x20or\x20\x27after\x27.','Operation\x20type\x20(HOOK\x20only)','\x20api\x20pull`\x20first,\x20or\x20use\x20--datasetcode\x20instead.','\x0a\x20*\x20@param\x20{Object}\x20context\x20平台注入的执行上下文\x0a\x20*\x20@returns\x20{Promise<Object>}\x20','write','Function\x20name\x20(valid\x20JS\x20identifier)','profileName','operation-type','before','\x0a\x20*/\x0aexport\x20default\x20async\x20function\x20','defaultApp','currentApp','string','--alias\x20or\x20--datasetcode\x20is\x20required\x20for\x20HOOK\x20in\x20non-interactive\x20mode.','6VqTtuK','HOOK\x20requires\x20hookOptions\x20for\x20template\x20generation.','Select\x20dataset:','2011260ulaOHR','Available:\x20','9149465BWevSA','Available\x20aliases:\x20','\x22.\x20Must\x20be\x20a\x20valid\x20JS\x20identifier\x20(e.g.\x20createOrder,\x20beforeFilter).','\x20*\x20[依赖数据集]\x20无(如有依赖,DB_TABLE\x20填物理表名;METADATA\x20填数据集编码与用途)\x0a\x20*\x20[调用\x20BF]\x20无(如有调用,填写脚本名称与用途)\x0a\x20*\x20[执行\x20SQL]\x20无(如有执行,填写\x20SQL\x20名称与用途)\x0a\x20*\x20[副作用]\x20无(如有通知或外部调用,说明影响与失败策略)','includes','\x20api\x20pull`\x20to\x20refresh.','/COMMON/','validation','819333lcYuaZ','after','functionNode','Trigger\x20node\x20(HOOK\x20only)','question','type','COMMON','Created\x20','scriptsRootDir','.js\x0a\x20*\x20[调用方式]\x20context.client.bff.execute({\x20scriptName:\x20\x22','30wGkrMJ','8481121DQAoOx','\x0a\x20*\x20[接口路径]\x20POST\x20/api/endpoint/','12GOfyIV','find','utf8','File\x20already\x20exists:\x20','Dataset\x20code\x20(HOOK\x20only,\x20fallback\x20when\x20alias\x20unavailable)','No\x20datasets\x20found\x20for\x20this\x20app.','code','apiDir','filePath','join','Invalid\x20function\x20name\x20\x22','--function-node\x20is\x20required\x20for\x20HOOK\x20in\x20non-interactive\x20mode.','mergedCli','ENDPOINT','stderr','create','\x22\x20not\x20found.\x20','\x22,\x20params\x20})\x0a','read','(params,\x20context)\x20{\x0a\x20\x20return\x20params;\x0a}\x0a','8827OVPPHJ','\x22\x20not\x20found\x20for\x20dataset\x20','isInteger','function-node','trim','.js\x0a','entries','\x22.\x20','\x0a\x20*\x20[平台配置]\x20','parseInt','99CelkqT','No\x20model\x20aliases\x20found.\x20Run\x20`'];a37_0x3f05=function(){return _0x5a471d;};return a37_0x3f05();}import{getAppBaseUrl}from'../../constant/domain.js';export const bffCreate={'service':a37_0x375ddc(0x164),'command':a37_0x375ddc(0x1a9),'description':a37_0x375ddc(0x15f),'risk':a37_0x375ddc(0x1ac),'flags':[{'name':a37_0x375ddc(0x192),'type':'string','required':!![],'enum':[a37_0x375ddc(0x193),'ENDPOINT','HOOK'],'description':'Script\x20type'},{'name':a37_0x375ddc(0x156),'type':'string','required':!![],'description':a37_0x375ddc(0x177)},{'name':a37_0x375ddc(0x153),'type':a37_0x375ddc(0x17e),'description':'Script\x20description'},{'name':a37_0x375ddc(0x166),'type':'string','description':'Dataset\x20alias\x20from\x20api.ts\x20(HOOK\x20only,\x20preferred)'},{'name':a37_0x375ddc(0x158),'type':a37_0x375ddc(0x17e),'description':a37_0x375ddc(0x19e)},{'name':'operation-type','type':a37_0x375ddc(0x17e),'description':a37_0x375ddc(0x173)},{'name':a37_0x375ddc(0x144),'type':a37_0x375ddc(0x17e),'description':a37_0x375ddc(0x190),'enum':[a37_0x375ddc(0x17a),a37_0x375ddc(0x18e)]}],async 'validate'(_0x190592){const _0x5cc46c=a37_0x375ddc,_0xfd5fee=_0x190592['str']('name');if(!isValidBffFunctionName(_0xfd5fee))throw CliErrors[_0x5cc46c(0x18c)](_0x5cc46c(0x1a4)+_0xfd5fee+_0x5cc46c(0x187));},async 'execute'(_0x948594){const _0x10e562=a37_0x375ddc,_0xd56d3e=loadBffProjectConfig(_0x948594[_0x10e562(0x16b)]),_0x86db9c=_0x948594[_0x10e562(0x15a)](_0x10e562(0x192)),_0x27c04c=_0x948594['str'](_0x10e562(0x156)),_0x1aa74c=_0x948594[_0x10e562(0x15a)]('description')||undefined,_0x36d3b3=_0x86db9c===_0x10e562(0x160)?await resolveHookOptions(_0xd56d3e,_0x948594):undefined,_0x214059=buildFilePath(_0xd56d3e,_0x86db9c,_0x27c04c,_0x36d3b3);if(await fileExists(_0x214059))throw CliErrors[_0x10e562(0x18c)](_0x10e562(0x19d)+_0x214059);await mkdir(dirname(_0x214059),{'recursive':!![]});const _0x44b3a4=generateTemplate(_0x86db9c,_0x27c04c,_0x948594['appCode'],_0x1aa74c,_0x36d3b3);await writeFile(_0x214059,_0x44b3a4,_0x10e562(0x19c));const _0x1e0314={'type':_0x86db9c,'name':_0x27c04c,'path':_0x214059};if(_0x1aa74c)_0x1e0314[_0x10e562(0x153)]=_0x1aa74c;if(_0x36d3b3){if(_0x36d3b3[_0x10e562(0x166)])_0x1e0314[_0x10e562(0x166)]=_0x36d3b3[_0x10e562(0x166)];_0x1e0314[_0x10e562(0x14f)]=_0x36d3b3[_0x10e562(0x14f)],_0x1e0314[_0x10e562(0x16f)]=_0x36d3b3[_0x10e562(0x16f)],_0x1e0314[_0x10e562(0x18f)]=_0x36d3b3[_0x10e562(0x18f)];}return{'ok':!![],'data':_0x1e0314,'message':_0x10e562(0x194)+_0x86db9c+'\x20function:\x20'+_0x27c04c};}};async function resolveHookOptions(_0xc5219a,_0xfc09f4){const _0x12d3b8=a37_0x375ddc,_0x4602a7=resolveApiModelSource(_0xfc09f4[_0x12d3b8(0x1a1)],_0xfc09f4[_0x12d3b8(0x16b)],_0xfc09f4['selectedAppName']||_0xfc09f4[_0x12d3b8(0x1a6)]?.[_0x12d3b8(0x17d)]||_0xfc09f4['mergedCli']?.[_0x12d3b8(0x17c)]),_0x56f79d=loadAliasMap(_0xfc09f4[_0x12d3b8(0x1a1)],undefined,_0x4602a7['filePath'],_0x4602a7['profileName']),_0x54efef=_0x56f79d[_0x12d3b8(0x163)]>0x0;let _0x2e7ddf,_0x695677,_0x58e043;const _0x10dca5=_0xfc09f4[_0x12d3b8(0x15a)](_0x12d3b8(0x166)),_0xc6f9d5=_0xfc09f4[_0x12d3b8(0x15a)](_0x12d3b8(0x158));if(_0x10dca5){const _0x23fa9d=resolveAlias(_0xfc09f4[_0x12d3b8(0x1a1)],_0x10dca5,undefined,_0x4602a7[_0x12d3b8(0x1a2)],_0x4602a7[_0x12d3b8(0x178)]);if(!_0x23fa9d){const _0x21bb8b=_0x54efef?_0x12d3b8(0x186)+_0x56f79d['map'](_0x24ddbe=>_0x24ddbe[_0x12d3b8(0x166)])[_0x12d3b8(0x1a3)](',\x20'):_0x12d3b8(0x14c)+CLI_BIN_NAME+_0x12d3b8(0x174);throw CliErrors[_0x12d3b8(0x18c)](_0x12d3b8(0x159)+_0x10dca5+_0x12d3b8(0x1aa)+_0x21bb8b);}_0x2e7ddf=_0x10dca5,_0x695677=_0x23fa9d;}else{if(_0xc6f9d5){_0x695677=_0xc6f9d5;const _0x51e3e8=_0x56f79d['find'](_0x496e28=>_0x496e28[_0x12d3b8(0x14f)]===_0xc6f9d5);_0x2e7ddf=_0x51e3e8?.[_0x12d3b8(0x166)];}else{if(_0xfc09f4[_0x12d3b8(0x16e)])throw CliErrors['validation'](_0x12d3b8(0x17f));else{if(_0x54efef){const _0x1ec463=_0x56f79d['map'](_0x57e0e5=>_0x57e0e5['alias']+'\x20('+_0x57e0e5[_0x12d3b8(0x167)]+')'),_0x2b2886=await promptSelect(_0x12d3b8(0x182),_0x1ec463),_0x3f3435=_0x56f79d[_0x2b2886];if(!_0x3f3435)throw CliErrors[_0x12d3b8(0x18c)](_0x12d3b8(0x15b));_0x2e7ddf=_0x3f3435['alias'],_0x695677=_0x3f3435[_0x12d3b8(0x14f)];}else{const _0x29437a=await listDatasets(_0xfc09f4[_0x12d3b8(0x16b)]);if(_0x29437a[_0x12d3b8(0x163)]===0x0)throw CliErrors[_0x12d3b8(0x18c)](_0x12d3b8(0x19f));const _0xaa256c=_0x29437a[_0x12d3b8(0x151)](_0x56bb21=>_0x56bb21[_0x12d3b8(0x156)]+'\x20['+(_0x56bb21['source']??'UNKNOWN')+']\x20('+_0x56bb21[_0x12d3b8(0x1a0)]+')'),_0x42fa70=await promptSelect(_0x12d3b8(0x182),_0xaa256c),_0x1556c4=_0x29437a[_0x42fa70];if(!_0x1556c4)throw CliErrors[_0x12d3b8(0x18c)](_0x12d3b8(0x15b));_0x695677=_0x1556c4['code'],_0x2e7ddf=undefined;}}}}const _0xed5883=await listDatasets(_0xfc09f4[_0x12d3b8(0x16b)]),_0x23094b=_0xed5883[_0x12d3b8(0x19b)](_0x2533f3=>_0x2533f3[_0x12d3b8(0x1a0)]===_0x695677);if(!_0x23094b)throw CliErrors[_0x12d3b8(0x18c)]('Dataset\x20not\x20found\x20for\x20code\x20\x22'+_0x695677+_0x12d3b8(0x148)+(_0x2e7ddf?'The\x20generated\x20model\x20facts\x20may\x20be\x20stale\x20—\x20run\x20`'+CLI_BIN_NAME+_0x12d3b8(0x18a):''));_0x58e043=_0x23094b['id'];const _0xe010ea=_0x2e7ddf??_0x695677,_0x4030b4=await listBffDatasetOperations(_0xfc09f4[_0x12d3b8(0x16b)],_0x58e043),_0x504e0e=_0x4030b4?Object[_0x12d3b8(0x15c)](_0x4030b4):[];if(_0x504e0e[_0x12d3b8(0x163)]===0x0)throw CliErrors[_0x12d3b8(0x18c)](_0x12d3b8(0x14d)+_0xe010ea+'.');let _0x35d0bc;const _0x3b085a=_0xfc09f4[_0x12d3b8(0x15a)](_0x12d3b8(0x179));if(_0x3b085a){if(!_0x504e0e[_0x12d3b8(0x189)](_0x3b085a))throw CliErrors['validation'](_0x12d3b8(0x161)+_0x3b085a+_0x12d3b8(0x1af)+_0xe010ea+'.\x20'+(_0x12d3b8(0x184)+_0x504e0e[_0x12d3b8(0x1a3)](',\x20')));_0x35d0bc=_0x3b085a;}else{if(_0xfc09f4[_0x12d3b8(0x16e)])throw CliErrors['validation'](_0x12d3b8(0x170));const _0x13f9d3=await promptSelect(_0x12d3b8(0x154),_0x504e0e);_0x35d0bc=_0x504e0e[_0x13f9d3]??_0x504e0e[0x0];}let _0x596fb1=normalizeHookFunctionNode(_0xfc09f4[_0x12d3b8(0x15a)](_0x12d3b8(0x144)));if(!_0x596fb1){if(_0xfc09f4['str'](_0x12d3b8(0x144)))throw CliErrors[_0x12d3b8(0x18c)](_0x12d3b8(0x172));if(_0xfc09f4[_0x12d3b8(0x16e)])throw CliErrors[_0x12d3b8(0x18c)](_0x12d3b8(0x1a5));const _0x5506e3=await promptSelect(_0x12d3b8(0x155),[_0x12d3b8(0x17a),_0x12d3b8(0x18e)]);_0x596fb1=['before',_0x12d3b8(0x18e)][_0x5506e3]??'before';}return{'alias':_0x2e7ddf,'datasetCode':_0x695677,'datasetId':_0x58e043,'operationType':_0x35d0bc,'functionNode':_0x596fb1};}async function promptSelect(_0x2b29b9,_0x3ed7c3){const _0x368f13=a37_0x375ddc;if(_0x3ed7c3['length']===0x1)return 0x0;for(const [_0x3b300f,_0x4287c7]of _0x3ed7c3[_0x368f13(0x147)]()){process[_0x368f13(0x1a8)][_0x368f13(0x176)]('\x20\x20'+(_0x3b300f+0x1)+'.\x20'+_0x4287c7+'\x0a');}const _0x21da03=createInterface({'input':process[_0x368f13(0x165)],'output':process[_0x368f13(0x1a8)]});while(!![]){const _0x4d7418=await new Promise(_0x469c97=>{const _0x3f57d2=_0x368f13;_0x21da03[_0x3f57d2(0x191)](_0x2b29b9+'\x20',_0x469c97);}),_0x519859=Number[_0x368f13(0x14a)](_0x4d7418[_0x368f13(0x145)](),0xa);if(Number[_0x368f13(0x143)](_0x519859)&&_0x519859>=0x1&&_0x519859<=_0x3ed7c3['length'])return _0x21da03['close'](),_0x519859-0x1;process[_0x368f13(0x1a8)][_0x368f13(0x176)]('\x20\x20Enter\x20a\x20number\x20between\x201\x20and\x20'+_0x3ed7c3[_0x368f13(0x163)]+'.\x0a');}}function buildFilePath(_0x2ca260,_0x5ed5fd,_0x4518fe,_0x4a67f7){const _0x13f6c2=a37_0x375ddc;if(_0x5ed5fd===_0x13f6c2(0x160)){if(!_0x4a67f7)throw CliErrors[_0x13f6c2(0x18c)](_0x13f6c2(0x15e));const _0x38ad59=_0x4a67f7[_0x13f6c2(0x166)]??_0x4a67f7[_0x13f6c2(0x14f)];return join(_0x2ca260[_0x13f6c2(0x195)],_0x13f6c2(0x160),_0x38ad59,_0x4a67f7[_0x13f6c2(0x16f)],_0x4a67f7[_0x13f6c2(0x18f)],_0x4518fe+'.js');}return join(_0x2ca260[_0x13f6c2(0x195)],_0x5ed5fd,_0x4518fe+'.js');}export function generateTemplate(_0x5cf6bb,_0x277d63,_0x35d16b,_0x54b6e1,_0x1ba2e9){const _0x147392=a37_0x375ddc,_0x4a0c8f=_0x54b6e1?.[_0x147392(0x145)]()||DEFAULT_BFF_SCRIPT_DESCRIPTION,_0x137000=getAppBaseUrl(_0x35d16b),_0x2d2739=_0x147392(0x188);if(_0x5cf6bb===_0x147392(0x193))return _0x147392(0x168)+_0x4a0c8f+'\x0a\x20*\x0a\x20*\x20[脚本类型]\x20COMMON\x0a\x20*\x20[脚本名称]\x20'+_0x277d63+_0x147392(0x149)+_0x137000+_0x147392(0x16d)+_0x35d16b+_0x147392(0x18b)+_0x277d63+_0x147392(0x196)+_0x277d63+_0x147392(0x1ab)+_0x2d2739+_0x147392(0x16c)+_0x277d63+'(params,\x20context)\x20{\x0a\x20\x20return\x20params;\x0a}\x0a';if(_0x5cf6bb===_0x147392(0x1a7))return _0x147392(0x168)+_0x4a0c8f+_0x147392(0x150)+_0x277d63+_0x147392(0x199)+_0x35d16b+'/'+_0x277d63+_0x147392(0x149)+_0x137000+_0x147392(0x16d)+_0x35d16b+_0x147392(0x169)+_0x277d63+_0x147392(0x146)+_0x2d2739+'\x0a\x20*\x20[参数字段]\x20按实际请求体为\x20params.<字段名>\x20补充\x20JSDoc\x20参数标签;无字段时仅保留根参数\x0a\x20*\x20[异常说明]\x20无;显式抛出异常时补充异常类型与触发条件\x0a\x20*\x0a\x20*\x20@param\x20{Object}\x20params\x20HTTP\x20请求体参数\x0a\x20*\x20@param\x20{Object}\x20context\x20平台注入的执行上下文\x0a\x20*\x20@returns\x20{Promise<Object>}\x20TODO:\x20补充业务返回数据结构\x0a\x20*/\x0aexport\x20default\x20async\x20function\x20'+_0x277d63+_0x147392(0x1ad);if(!_0x1ba2e9)throw CliErrors['validation'](_0x147392(0x181));const _0x152de3=_0x1ba2e9[_0x147392(0x166)]??_0x1ba2e9[_0x147392(0x14f)],_0x381e4f=_0x1ba2e9[_0x147392(0x18f)]===_0x147392(0x17a)?'当前请求参数':_0x147392(0x15d),_0x180edd=_0x1ba2e9['functionNode']===_0x147392(0x17a)?_0x147392(0x157):'修改后的响应结果';return _0x147392(0x168)+_0x4a0c8f+'\x0a\x20*\x0a\x20*\x20[脚本类型]\x20HOOK\x0a\x20*\x20[脚本名称]\x20'+_0x277d63+'\x0a\x20*\x20[接口路径]\x20POST\x20/api/'+_0x35d16b+'/'+_0x1ba2e9['datasetCode']+'/'+_0x1ba2e9[_0x147392(0x16f)]+_0x147392(0x149)+_0x137000+'/data/dataset/'+_0x1ba2e9[_0x147392(0x171)]+'#api-list\x0a\x20*\x20[本地路径]\x20.rabetbase/bff/'+_0x35d16b+'/HOOK/'+_0x152de3+'/'+_0x1ba2e9['operationType']+'/'+_0x1ba2e9[_0x147392(0x18f)]+'/'+_0x277d63+_0x147392(0x16a)+_0x1ba2e9['functionNode']+'\x0a'+_0x2d2739+'\x0a\x20*\x20[参数字段]\x20按实际输入为\x20params.<字段名>\x20补充\x20JSDoc\x20参数标签;无字段时仅保留根参数\x0a\x20*\x20[异常说明]\x20无;显式抛出异常时补充异常类型与触发条件\x0a\x20*\x0a\x20*\x20@param\x20{Object}\x20params\x20'+_0x381e4f+_0x147392(0x175)+_0x180edd+_0x147392(0x17b)+_0x277d63+_0x147392(0x1ad);}
|
|
1
|
+
import{createInterface}from"node:readline";import{mkdir,writeFile}from"node:fs/promises";import{dirname,join}from"node:path";import{listDatasets,listBffDatasetOperations}from"../../core/api-client.js";import{loadAliasMap,resolveAlias}from"../../core/alias-resolver.js";import{resolveApiModelSource}from"../../api/model-source.js";import{loadBffProjectConfig}from"../../core/bff/config.js";import{fileExists}from"../../core/bff/file-system.js";import{DEFAULT_BFF_SCRIPT_DESCRIPTION,isValidBffFunctionName,normalizeHookFunctionNode}from"../../core/bff/utils.js";import{CliErrors}from"../../errors.js";import{CLI_BIN_NAME}from"../../constant/cli.js";import{getAppBaseUrl}from"../../constant/domain.js";export const bffCreate={service:"bff",command:"create",description:"Scaffold a new Backend Function script from template",risk:"read",flags:[{name:"type",type:"string",required:true,enum:["COMMON","ENDPOINT","HOOK"],description:"Script type"},{name:"name",type:"string",required:true,
|
|
2
|
+
description:"Function name (valid JS identifier)"},{name:"description",type:"string",description:"Script description"},{name:"alias",type:"string",description:"Dataset alias from api.ts (HOOK only, preferred)"},{name:"datasetcode",type:"string",description:"Dataset code (HOOK only, fallback when alias unavailable)"},{name:"operation-type",type:"string",description:"Operation type (HOOK only)"},{name:"function-node",type:"string",description:"Trigger node (HOOK only)",enum:["before","after"]}],async validate(ctx){const functionName=ctx.str("name");if(!isValidBffFunctionName(functionName)){throw CliErrors.validation(`Invalid function name "${functionName}". Must be a valid JS identifier (e.g. createOrder, beforeFilter).`)}},async execute(ctx){const config=loadBffProjectConfig(ctx.appCode);const scriptType=ctx.str("type");const functionName=ctx.str("name");const description=ctx.str("description")||undefined
|
|
3
|
+
;const hookOptions=scriptType==="HOOK"?await resolveHookOptions(config,ctx):undefined;const targetFilePath=buildFilePath(config,scriptType,functionName,hookOptions);if(await fileExists(targetFilePath)){throw CliErrors.validation(`File already exists: ${targetFilePath}`)}await mkdir(dirname(targetFilePath),{recursive:true});const template=generateTemplate(scriptType,functionName,ctx.appCode,description,hookOptions);await writeFile(targetFilePath,template,"utf8");const data={type:scriptType,name:functionName,path:targetFilePath};if(description)data["description"]=description;if(hookOptions){if(hookOptions.alias)data["alias"]=hookOptions.alias;data["datasetCode"]=hookOptions.datasetCode;data["operationType"]=hookOptions.operationType;data["functionNode"]=hookOptions.functionNode}return{ok:true,data:data,message:`Created ${scriptType} function: ${functionName}`}}};async function resolveHookOptions(config,ctx){
|
|
4
|
+
const source=resolveApiModelSource(ctx.apiDir,ctx.appCode,ctx.selectedAppName||ctx.mergedCli?.currentApp||ctx.mergedCli?.defaultApp);const aliasEntries=loadAliasMap(ctx.apiDir,undefined,source.filePath,source.profileName);const hasAliasMap=aliasEntries.length>0;let selectedAlias;let selectedDatasetCode;let selectedDatasetId;const aliasFlag=ctx.str("alias");const datasetcodeFlag=ctx.str("datasetcode");if(aliasFlag){const datasetCode=resolveAlias(ctx.apiDir,aliasFlag,undefined,source.filePath,source.profileName);if(!datasetCode){const hint=hasAliasMap?`Available aliases: ${aliasEntries.map(e=>e.alias).join(", ")}`:`No model aliases found. Run \`${CLI_BIN_NAME} api pull\` first, or use --datasetcode instead.`;throw CliErrors.validation(`Alias "${aliasFlag}" not found. ${hint}`)}selectedAlias=aliasFlag;selectedDatasetCode=datasetCode}else if(datasetcodeFlag){selectedDatasetCode=datasetcodeFlag;const entry=aliasEntries.find(e=>e.datasetCode===datasetcodeFlag);selectedAlias=entry?.alias
|
|
5
|
+
}else if(ctx.nonInteractive){throw CliErrors.validation("--alias or --datasetcode is required for HOOK in non-interactive mode.")}else if(hasAliasMap){const choices=aliasEntries.map(e=>`${e.alias} (${e.tableName})`);const idx=await promptSelect("Select dataset:",choices);const entry=aliasEntries[idx];if(!entry)throw CliErrors.validation("Invalid dataset selection.");selectedAlias=entry.alias;selectedDatasetCode=entry.datasetCode}else{const datasets=await listDatasets(ctx.appCode);if(datasets.length===0){throw CliErrors.validation("No datasets found for this app.")}const choices=datasets.map(d=>`${d.name} [${d.source??"UNKNOWN"}] (${d.code})`);const idx=await promptSelect("Select dataset:",choices);const ds=datasets[idx];if(!ds)throw CliErrors.validation("Invalid dataset selection.");selectedDatasetCode=ds.code;selectedAlias=undefined}const datasets=await listDatasets(ctx.appCode);const matchedDataset=datasets.find(d=>d.code===selectedDatasetCode);if(!matchedDataset){
|
|
6
|
+
throw CliErrors.validation(`Dataset not found for code "${selectedDatasetCode}". `+(selectedAlias?`The generated model facts may be stale — run \`${CLI_BIN_NAME} api pull\` to refresh.`:""))}selectedDatasetId=matchedDataset.id;const dirName=selectedAlias??selectedDatasetCode;const rawOps=await listBffDatasetOperations(ctx.appCode,selectedDatasetId);const opTypes=rawOps?Object.keys(rawOps):[];if(opTypes.length===0){throw CliErrors.validation(`No operation types found for dataset ${dirName}.`)}let operationType;const opTypeFlag=ctx.str("operation-type");if(opTypeFlag){if(!opTypes.includes(opTypeFlag)){throw CliErrors.validation(`Operation type "${opTypeFlag}" not found for dataset ${dirName}. `+`Available: ${opTypes.join(", ")}`)}operationType=opTypeFlag}else{if(ctx.nonInteractive){throw CliErrors.validation("--operation-type is required for HOOK in non-interactive mode.")}const idx=await promptSelect("Select operation type:",opTypes);operationType=opTypes[idx]??opTypes[0]}
|
|
7
|
+
let functionNode=normalizeHookFunctionNode(ctx.str("function-node"));if(!functionNode){if(ctx.str("function-node")){throw CliErrors.validation("--function-node must be 'before' or 'after'.")}if(ctx.nonInteractive){throw CliErrors.validation("--function-node is required for HOOK in non-interactive mode.")}const idx=await promptSelect("Select trigger node:",["before","after"]);functionNode=["before","after"][idx]??"before"}return{alias:selectedAlias,datasetCode:selectedDatasetCode,datasetId:selectedDatasetId,operationType:operationType,functionNode:functionNode}}async function promptSelect(message,choices){if(choices.length===1)return 0;for(const[i,label]of choices.entries()){process.stderr.write(` ${i+1}. ${label}\n`)}const rl=createInterface({input:process.stdin,output:process.stderr});while(true){const answer=await new Promise(resolve=>{rl.question(`${message} `,resolve)});const idx=Number.parseInt(answer.trim(),10);if(Number.isInteger(idx)&&idx>=1&&idx<=choices.length){rl.close()
|
|
8
|
+
;return idx-1}process.stderr.write(` Enter a number between 1 and ${choices.length}.\n`)}}function buildFilePath(config,scriptType,functionName,hookOptions){if(scriptType==="HOOK"){if(!hookOptions)throw CliErrors.validation("HOOK requires alias/operation/node options.");const dirName=hookOptions.alias??hookOptions.datasetCode;return join(config.scriptsRootDir,"HOOK",dirName,hookOptions.operationType,hookOptions.functionNode,`${functionName}.js`)}return join(config.scriptsRootDir,scriptType,`${functionName}.js`)}export function generateTemplate(scriptType,functionName,appCode,description,hookOptions){const desc=description?.trim()||DEFAULT_BFF_SCRIPT_DESCRIPTION;const platformBaseUrl=getAppBaseUrl(appCode);const dependencyNotes=` * [依赖数据集] 无(如有依赖,DB_TABLE 填物理表名;METADATA 填数据集编码与用途)\n * [调用 BF] 无(如有调用,填写脚本名称与用途)\n * [执行 SQL] 无(如有执行,填写 SQL 名称与用途)\n * [副作用] 无(如有通知或外部调用,说明影响与失败策略)`;if(scriptType==="COMMON"){
|
|
9
|
+
return`/**\n * ${desc}\n *\n * [脚本类型] COMMON\n * [脚本名称] ${functionName}\n * [平台配置] ${platformBaseUrl}/data/backend-function\n * [本地路径] .rabetbase/bff/${appCode}/COMMON/${functionName}.js\n * [调用方式] context.client.bff.execute({ scriptName: "${functionName}", params })\n${dependencyNotes}\n * [参数字段] 按实际输入为 params.<字段名> 补充 JSDoc 参数标签;无字段时仅保留根参数\n * [异常说明] 无;显式抛出异常时补充异常类型与触发条件\n *\n * @param {Object} params 请求参数\n * @param {Object} context 平台注入的执行上下文\n * @returns {Promise<Object>} TODO: 补充返回数据结构\n */\nexport default async function ${functionName}(params, context) {\n return params;\n}\n`}if(scriptType==="ENDPOINT"){
|
|
10
|
+
return`/**\n * ${desc}\n *\n * [脚本类型] ENDPOINT\n * [脚本名称] ${functionName}\n * [接口路径] POST /api/endpoint/${appCode}/${functionName}\n * [平台配置] ${platformBaseUrl}/data/backend-function\n * [本地路径] .rabetbase/bff/${appCode}/ENDPOINT/${functionName}.js\n${dependencyNotes}\n * [参数字段] 按实际请求体为 params.<字段名> 补充 JSDoc 参数标签;无字段时仅保留根参数\n * [异常说明] 无;显式抛出异常时补充异常类型与触发条件\n *\n * @param {Object} params HTTP 请求体参数\n * @param {Object} context 平台注入的执行上下文\n * @returns {Promise<Object>} TODO: 补充业务返回数据结构\n */\nexport default async function ${functionName}(params, context) {\n return params;\n}\n`}if(!hookOptions)throw CliErrors.validation("HOOK requires hookOptions for template generation.");const hookDirName=hookOptions.alias??hookOptions.datasetCode;const hookParamsDescription=hookOptions.functionNode==="before"?"当前请求参数":"当前响应结果";const hookReturnDescription=hookOptions.functionNode==="before"?"修改后的请求参数":"修改后的响应结果"
|
|
11
|
+
;return`/**\n * ${desc}\n *\n * [脚本类型] HOOK\n * [脚本名称] ${functionName}\n * [接口路径] POST /api/${appCode}/${hookOptions.datasetCode}/${hookOptions.operationType}\n * [平台配置] ${platformBaseUrl}/data/dataset/${hookOptions.datasetId}#api-list\n * [本地路径] .rabetbase/bff/${appCode}/HOOK/${hookDirName}/${hookOptions.operationType}/${hookOptions.functionNode}/${functionName}.js\n * [触发节点] ${hookOptions.functionNode}\n${dependencyNotes}\n * [参数字段] 按实际输入为 params.<字段名> 补充 JSDoc 参数标签;无字段时仅保留根参数\n * [异常说明] 无;显式抛出异常时补充异常类型与触发条件\n *\n * @param {Object} params ${hookParamsDescription}\n * @param {Object} context 平台注入的执行上下文\n * @returns {Promise<Object>} ${hookReturnDescription}\n */\nexport default async function ${functionName}(params, context) {\n return params;\n}\n`}
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import{mkdir,readdir,rename,rmdir}from"node:fs/promises";import{dirname,join,relative,resolve,sep}from"node:path";import{deleteBffScript}from"../../core/api-client.js";import{loadBffProjectConfig}from"../../core/bff/config.js";import{fileExists,resolveLocalFilePathFromLockKey}from"../../core/bff/file-system.js";import{ensureLockScope,readBffLockFile,writeBffLockFile}from"../../core/bff/lock.js";import{CliErrors}from"../../errors.js";import{sleep}from"../../utils/sleep.js";export const bffDelete={service:"bff",command:"delete",description:"Delete a Backend Function script from remote and local",risk:"high-risk-write",flags:[{name:"target",type:"string",required:true,description:"Lock key (e.g. ENDPOINT/createOrder) or short function name"}],async validate(ctx){const config=loadBffProjectConfig(ctx.appCode);const lockData=await readBffLockFile(config.lockFilePath);if(!lockData){
|
|
2
|
+
throw CliErrors.validation("Backend Function lock file not found. Run `push` or `pull` first to initialize sync state.")}},async dryRun(ctx){const config=loadBffProjectConfig(ctx.appCode);const lockData=await readBffLockFile(config.lockFilePath);if(!lockData){throw CliErrors.validation("Backend Function lock file not found.")}const{appLock:appLock}=ensureLockScope(lockData,ctx.appCode,config.scriptsRoot,"delete");const targetInput=ctx.str("target");const lockKeys=Object.keys(appLock.functions);const targetKey=resolveDeleteTarget(targetInput,lockKeys);const targetEntry=appLock.functions[targetKey];if(!targetEntry){throw CliErrors.validation(`No lock entry found for "${targetKey}".`)}const localFilePath=resolveLocalFilePathFromLockKey(config,targetKey);const relativePath=relative(config.projectRoot,localFilePath);const trashedPath=join(config.trashDir,"<timestamp>",relativePath);return{method:"POST",url:"/api/management/library/scripts/delete",body:{appCode:ctx.appCode,target:targetKey,
|
|
3
|
+
remoteId:targetEntry.remoteId,localFilePath:localFilePath,trashedPath:trashedPath},description:`Would delete ${targetKey} from remote and move local file to trash`}},async execute(ctx){const config=loadBffProjectConfig(ctx.appCode);const lockDataFromFile=await readBffLockFile(config.lockFilePath);if(!lockDataFromFile){throw CliErrors.validation("Backend Function lock file not found.")}const{lockData:lockData,appLock:appLock}=ensureLockScope(lockDataFromFile,ctx.appCode,config.scriptsRoot,"delete");const nextLockData=JSON.parse(JSON.stringify(lockData));const nextAppLock=nextLockData.apps[ctx.appCode];if(!nextAppLock){throw new Error(`Lock scope for app "${ctx.appCode}" not found after ensureLockScope.`)}const targetInput=ctx.str("target");const lockKeys=Object.keys(nextAppLock.functions);const targetKey=resolveDeleteTarget(targetInput,lockKeys);const targetEntry=nextAppLock.functions[targetKey];if(!targetEntry){throw CliErrors.validation(`No lock entry found for "${targetKey}".`)}
|
|
4
|
+
await deleteBffScript(targetEntry.remoteId);delete nextAppLock.functions[targetKey];nextAppLock.lastSync=(new Date).toISOString();await writeBffLockFile(config.lockFilePath,nextLockData);const localFilePath=resolveLocalFilePathFromLockKey(config,targetKey);let trashedPath;if(await fileExists(localFilePath)){trashedPath=await moveToTrash(config.projectRoot,config.trashDir,localFilePath);await cleanupEmptyDirectories(dirname(localFilePath),config.scriptsRootDir)}await waitForDeleteSettlement(config.lockFilePath,ctx.appCode,targetKey,localFilePath);await sleep(150);const data={deleted:targetKey,remoteId:targetEntry.remoteId};if(trashedPath)data["trashedTo"]=trashedPath;return{ok:true,data:data,message:`Deleted ${targetKey}`+(trashedPath?` (local file moved to trash)`:"")}}};function resolveDeleteTarget(target,lockKeys){if(target.includes("/")){const exact=lockKeys.find(k=>k===target);if(!exact)throw CliErrors.validation(`Function not found: ${target}`);return exact}
|
|
5
|
+
const matches=lockKeys.filter(k=>k.split("/").at(-1)===target);if(matches.length===0){throw CliErrors.validation(`Function not found: ${target}`)}if(matches.length>1){throw CliErrors.validation(`Multiple functions match "${target}". Use the full lock key:\n`+matches.map(k=>` - ${k}`).join("\n"))}return matches[0]}async function moveToTrash(projectRoot,trashDir,localFilePath){const timestamp=(new Date).toISOString().replace(/[:.]/g,"-");const relativePath=relative(projectRoot,localFilePath);const targetPath=join(trashDir,timestamp,relativePath);await mkdir(dirname(targetPath),{recursive:true});await rename(localFilePath,targetPath);return targetPath}async function cleanupEmptyDirectories(startDir,stopDir){let currentDir=resolve(startDir);const normalizedStop=resolve(stopDir);while(currentDir.startsWith(`${normalizedStop}${sep}`)||currentDir===normalizedStop){if(currentDir===normalizedStop)return;try{const entries=await readdir(currentDir);if(entries.length>0)return
|
|
6
|
+
;await rmdir(currentDir)}catch{return}currentDir=dirname(currentDir)}}const DELETE_SETTLE_RETRY_COUNT=20;const DELETE_SETTLE_DELAY_MS=100;async function waitForDeleteSettlement(lockFilePath,appCode,targetKey,localFilePath){for(let i=0;i<DELETE_SETTLE_RETRY_COUNT;i+=1){const latestLock=await readBffLockFile(lockFilePath);const stillInLock=!!latestLock?.apps?.[appCode]?.functions?.[targetKey];const stillHasFile=await fileExists(localFilePath);if(!stillInLock&&!stillHasFile){return}await sleep(DELETE_SETTLE_DELAY_MS)}throw new Error(`Local delete not settled for ${targetKey}.`)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{getBffScriptInfo}from"../../core/api-client.js";export const bffDetail={service:"bff",command:"detail",description:"Get Backend Function script details by ID",risk:"read",flags:[{name:"id",type:"number",required:true,description:"Script ID"},{name:"verbose",type:"boolean",description:"Return full raw script object"}],async execute(ctx){const script=await getBffScriptInfo(ctx.num("id"));const verbose=ctx.bool("verbose");if(verbose){return{ok:true,data:script}}return{ok:true,data:{id:script.id,functionName:script.functionName??"",version:script.version??"",updateUserName:script.updateUserName??"",appCode:script.appCode,scriptType:script.scriptType,description:script.description||"(none)",createdTime:script.createdTime??"",updatedTime:script.updatedTime??"",scriptContent:script.scriptContent??""}}}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{bffList}from"../../commands/bff/list.js";import{bffDetail}from"../../commands/bff/detail.js";import{bffStatus}from"../../commands/bff/status.js";import{bffCreate}from"../../commands/bff/create.js";import{bffPush}from"../../commands/bff/push.js";import{bffPull}from"../../commands/bff/pull.js";import{bffDelete}from"../../commands/bff/delete.js";import{bffLogs}from"../../commands/bff/logs.js";export const bffDefinitions=[bffList,bffDetail,bffLogs,bffStatus,bffCreate,bffPush,bffPull,bffDelete];
|