@lovrabet/rabetbase-cli 2.5.13 → 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_0x36e2fb=a22_0xb2c2;(function(_0x3bb56d,_0x58d325){const _0x74ec24=a22_0xb2c2,_0x173433=_0x3bb56d();while(!![]){try{const _0xe2f2c1=parseInt(_0x74ec24(0x15a))/0x1+parseInt(_0x74ec24(0x192))/0x2+-parseInt(_0x74ec24(0x1a5))/0x3*(-parseInt(_0x74ec24(0x168))/0x4)+-parseInt(_0x74ec24(0x17e))/0x5+-parseInt(_0x74ec24(0x172))/0x6*(-parseInt(_0x74ec24(0x193))/0x7)+parseInt(_0x74ec24(0x157))/0x8+-parseInt(_0x74ec24(0x184))/0x9*(parseInt(_0x74ec24(0x158))/0xa);if(_0xe2f2c1===_0x58d325)break;else _0x173433['push'](_0x173433['shift']());}catch(_0x3983c0){_0x173433['push'](_0x173433['shift']());}}}(a22_0x5dea,0x7f18b));import a22_0x38a16e from'ora';import{getEnv}from'../../constant/env.js';import{fetchModelList}from'../../core/api-client.js';function a22_0x5dea(){const _0x831522=['Pull\x20dataset\x20facts\x20and\x20refresh\x20the\x20generated\x20SDK\x20model\x20registry\x20(','overwritten','project','\x20model(s)','find','4473hymztu','app','push','modelCount','configName','start','Pulling\x20API\x20config\x20for\x20','length','\x20dataset\x20fact(s)\x20and\x20replaced\x20the\x20TypeScript\x20scaffold\x20with\x20','cookie','AppCode\x20\x22','\x22\x20belongs\x20to\x20multiple\x20app\x20profiles:\x20','slice','needsProjectUpgrade','\x20\x20•\x20','\x20dataset\x20fact(s)\x20and\x20wrote\x20a\x20scaffold\x20with\x20','Internal\x20error:\x20API\x20layout\x20for\x20app\x20profile\x20\x22','\x20dataset\x20fact(s)\x20and\x20refreshed\x20model\x20profile\x20\x22','Verify\x20the\x20selected\x20profile\x20and\x20review\x20legacy\x20generated\x20files,\x20then\x20rerun\x20with\x20--force\x20--yes.','7092216mBbMbc','1180QOZwfR','pull','367283kcokLs','\x22\x20was\x20not\x20resolved.','modelProfile','\x20succeeded,\x20','defaultApp','isDefault','output','values','NOT-SET','merged','outputDir','modelRegistryPath','none','default','1512ktBFOe','validation',';\x20created\x20the\x20stable\x20TypeScript\x20entrypoints','sdkRouting','clientFilePath','exists','\x20app(s)\x20failed','fail','hasAppCode','appCode','993918mvJpCn','bool','boolean','\x20failed','currentApp','action','basename','rawFlags','read','includes','Failed:\x20','selectedAppName','3748535SMChsi','api','mergedCli',';\x20replaced\x20the\x20stable\x20TypeScript\x20entrypoints','apiFilePath','map','78066YIeohD','name','force','appcode','client','Done:\x20','env','succeed','--force\x20requires\x20--yes\x20because\x20it\x20may\x20remove\x20existing\x20model\x20facts\x20or\x20replace\x20a\x20legacy\x20generated\x20scaffold.','message','Select\x20the\x20target\x20explicitly\x20with\x20--app\x20<profile>.','needsAgentMerge','join','filter','290224VbFDVq','14xtVoDf','sdkConfigPath','string','Fetched\x20','global','size','files','has','Pulling\x20','\x20does\x20not\x20contain\x20AppCode\x20\x22','isUnboundTemplate','modelRuntimePath','\x20is\x20not\x20a\x20valid\x20Rabetbase\x20generated\x20file.\x20Move\x20or\x20repair\x20it\x20before\x20pulling\x20models\x20again.'];a22_0x5dea=function(){return _0x831522;};return a22_0x5dea();}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 a22_0x5dfcf1 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='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`.';function inspectModelRegistry(_0x5f334b,_0xe82687){const _0xe4dd1d=a22_0xb2c2,_0x2cb96a=a22_0x5dfcf1[_0xe4dd1d(0x190)](_0x5f334b,MODEL_REGISTRY_FILE_NAME),_0x342e0c=existsSync(_0x2cb96a);if(!_0x342e0c)return{'exists':![],'hasAppCode':![],'isUnboundTemplate':![]};const _0x20efce=readModelRegistry(_0x2cb96a);if(!_0x20efce)throw new Error(MODEL_REGISTRY_FILE_NAME+_0xe4dd1d(0x19f));const _0x5b85e0=new Set(Object[_0xe4dd1d(0x161)](_0x20efce['profiles'])[_0xe4dd1d(0x183)](_0x33d37d=>_0x33d37d[_0xe4dd1d(0x171)])[_0xe4dd1d(0x191)](_0x4544eb=>_0x4544eb!==_0xe4dd1d(0x162)));return{'exists':!![],'hasAppCode':!!_0xe82687&&_0x5b85e0[_0xe4dd1d(0x19a)](_0xe82687),'isUnboundTemplate':_0x5b85e0[_0xe4dd1d(0x198)]===0x0};}function a22_0xb2c2(_0x58a03a,_0x3e6da5){_0x58a03a=_0x58a03a-0x154;const _0x5dea87=a22_0x5dea();let _0xb2c241=_0x5dea87[_0x58a03a];return _0xb2c241;}function toPullData(_0x52db96){const _0x3b71c1=a22_0xb2c2;return{'appCode':_0x52db96[_0x3b71c1(0x171)],'configName':_0x52db96[_0x3b71c1(0x1a9)],'isDefaultConfig':_0x52db96['isDefaultConfig'],'models':_0x52db96['models'],'sdkRouting':_0x52db96[_0x3b71c1(0x16b)],'files':_0x52db96['files'],'needsAgentMerge':_0x52db96[_0x3b71c1(0x18f)],'needsProjectUpgrade':_0x52db96[_0x3b71c1(0x1b2)],'apiFilePath':_0x52db96[_0x3b71c1(0x182)],'clientFilePath':_0x52db96[_0x3b71c1(0x16c)],'sdkConfigPath':_0x52db96[_0x3b71c1(0x194)],'modelRegistryPath':_0x52db96['modelRegistryPath'],'modelRuntimePath':_0x52db96['modelRuntimePath'],'modelProfile':_0x52db96['modelProfile'],'datasetCount':_0x52db96[_0x3b71c1(0x1a8)],'modelCount':_0x52db96['modelCount']};}function describePull(_0x468340){const _0x19dba4=a22_0xb2c2,_0xd309d9=a22_0x5dfcf1[_0x19dba4(0x178)](_0x468340['sdkConfigPath']);if(_0x468340[_0x19dba4(0x15c)]){const _0x241961=_0x19dba4(0x196)+_0x468340[_0x19dba4(0x1a8)]+_0x19dba4(0x155)+_0x468340[_0x19dba4(0x15c)]+'\x22';if(_0x468340['needsAgentMerge'])return _0x241961+'.\x20'+EXISTING_TS_HINT;if(_0x468340[_0x19dba4(0x199)][_0x19dba4(0x17f)][_0x19dba4(0x177)]===_0x19dba4(0x1a1)||_0x468340[_0x19dba4(0x199)][_0x19dba4(0x188)]['action']===_0x19dba4(0x1a1))return _0x241961+_0x19dba4(0x181);if(_0x468340[_0x19dba4(0x199)][_0x19dba4(0x17f)]['action']==='created'||_0x468340[_0x19dba4(0x199)][_0x19dba4(0x188)][_0x19dba4(0x177)]==='created')return _0x241961+_0x19dba4(0x16a);return _0x241961+';\x20preserved\x20the\x20stable\x20TypeScript\x20entrypoints';}if(_0x468340[_0x19dba4(0x18f)])return _0x19dba4(0x196)+_0x468340[_0x19dba4(0x1a8)]+'\x20dataset\x20fact(s)\x20and\x20refreshed\x20'+_0xd309d9+'.\x20'+EXISTING_TS_HINT;if(_0x468340[_0x19dba4(0x199)][_0x19dba4(0x17f)]['action']===_0x19dba4(0x1a1)||_0x468340[_0x19dba4(0x199)][_0x19dba4(0x188)][_0x19dba4(0x177)]===_0x19dba4(0x1a1))return _0x19dba4(0x196)+_0x468340['modelCount']+_0x19dba4(0x1ad)+_0x468340['modelCount']+_0x19dba4(0x1a3);return'Fetched\x20'+_0x468340[_0x19dba4(0x1a8)]+_0x19dba4(0x1b4)+_0x468340['modelCount']+'\x20model(s)';}export const apiPull={'service':'api','command':a22_0x36e2fb(0x159),'description':a22_0x36e2fb(0x1a0)+DEFAULT_API_DIR+'/)','risk':a22_0x36e2fb(0x17a),'requiresAppCode':!![],'hasFormat':!![],'flags':[{...APPCODE_FLAG_OPTIONAL,'hidden':!![]},{'name':a22_0x36e2fb(0x160),'type':a22_0x36e2fb(0x195),'description':'Output\x20directory\x20(default:\x20'+DEFAULT_API_DIR+'/)'},{'name':a22_0x36e2fb(0x197),'type':a22_0x36e2fb(0x174),'description':'Resolve\x20apps\x20from\x20merged\x20global+project\x20config\x20(default:\x20project\x20apps\x20only)','default':![]},{'name':a22_0x36e2fb(0x186),'type':a22_0x36e2fb(0x174),'description':'Accept\x20an\x20empty\x20model\x20result,\x20or\x20replace\x20a\x20legacy\x20prefixed\x20scaffold;\x20requires\x20--yes','default':![]}],async 'validate'(_0x149eea){const _0x25b590=a22_0x36e2fb;if(_0x149eea[_0x25b590(0x173)](_0x25b590(0x186))&&!_0x149eea[_0x25b590(0x173)]('yes'))throw CliErrors[_0x25b590(0x169)](_0x25b590(0x18c),_0x25b590(0x156));},async 'execute'(_0x1395d8){const _0x11e4c2=a22_0x36e2fb,_0x2f67ca=_0x1395d8['rawFlags']['appcode']?String(_0x1395d8[_0x11e4c2(0x179)][_0x11e4c2(0x187)]):undefined,_0x3c8204=_0x1395d8['str']('output')||undefined,_0x116908=_0x1395d8[_0x11e4c2(0x173)](_0x11e4c2(0x186)),_0x1c2d2e=resolveTargetApps(_0x1395d8,_0x2f67ca),_0x577f65=_0x1395d8[_0x11e4c2(0x173)](_0x11e4c2(0x197))?_0x11e4c2(0x163):_0x11e4c2(0x1a2),_0x406711=getMultiAppConfigs(_0x577f65),_0x50f258=_0x5801b4=>_0x5801b4['apiDir']||_0x3c8204||_0x1395d8['apiDir']||DEFAULT_API_DIR,_0x52235e=_0x406711?resolveApiProfileLayouts(_0x406711,_0x50f258):undefined;let _0x355300=_0x1c2d2e;if(!_0x355300&&_0x406711){const _0x410ba4=_0x1395d8[_0x11e4c2(0x17d)]?_0x406711[_0x11e4c2(0x1a4)](_0x141fad=>_0x141fad[_0x11e4c2(0x185)]===_0x1395d8[_0x11e4c2(0x17d)]):undefined,_0x474650=_0x406711[_0x11e4c2(0x191)](_0x3ecc55=>_0x3ecc55[_0x11e4c2(0x187)]===_0x1395d8[_0x11e4c2(0x171)]);if(!_0x410ba4&&_0x474650[_0x11e4c2(0x1ac)]>0x1)throw CliErrors['validation'](_0x11e4c2(0x1af)+_0x1395d8['appCode']+_0x11e4c2(0x1b0)+_0x474650['map'](_0x4df7d5=>_0x4df7d5[_0x11e4c2(0x185)])[_0x11e4c2(0x190)](',\x20')+'.',_0x11e4c2(0x18e));const _0x290888=_0x410ba4??_0x474650[0x0];if(_0x290888)_0x355300=[_0x290888];}if(_0x355300){let _0x122e30=0x0,_0x3ffeaf=0x0;const _0x4b1ed1=[],_0x599fef=_0x52235e??resolveApiProfileLayouts(_0x355300,_0x50f258);for(const _0xb3b8c of _0x355300){const _0x2e61f9=_0xb3b8c[_0x11e4c2(0x1ae)]||_0x1395d8[_0x11e4c2(0x1ae)],_0x14f993=_0xb3b8c[_0x11e4c2(0x18a)]||'production';await initMultiAppEnvironment(_0xb3b8c);const _0x395f1d=_0x599fef[_0x11e4c2(0x1a4)](_0x4ea616=>_0x4ea616[_0x11e4c2(0x1a6)][_0x11e4c2(0x185)]===_0xb3b8c[_0x11e4c2(0x185)]);if(!_0x395f1d)throw new Error(_0x11e4c2(0x154)+_0xb3b8c[_0x11e4c2(0x185)]+_0x11e4c2(0x15b));const _0x2425ae=getRegistryGroup(_0x599fef,_0x395f1d),_0x27c0d9=_0x395f1d[_0x11e4c2(0x164)],_0x4c2270=_0x2425ae?'':_0xb3b8c[_0x11e4c2(0x15f)]?'':_0xb3b8c[_0x11e4c2(0x185)]||_0xb3b8c[_0x11e4c2(0x187)],_0x155a39=_0x2425ae?.[_0x11e4c2(0x1a4)](_0x1e67fb=>_0x1e67fb[_0x11e4c2(0x1a6)][_0x11e4c2(0x15f)])??_0x2425ae?.[0x0];if(_0x2425ae)inspectModelRegistry(_0x27c0d9);const _0x53b21d=a22_0x38a16e(_0x11e4c2(0x19b)+_0xb3b8c[_0x11e4c2(0x185)]+'\x20('+_0xb3b8c[_0x11e4c2(0x187)]+')...')[_0x11e4c2(0x1aa)]();try{const {configArray:_0x252f61}=await fetchModelList(_0xb3b8c[_0x11e4c2(0x187)],_0x2e61f9),_0x111923=await generateApiFile(_0x252f61,_0x4c2270,_0xb3b8c[_0x11e4c2(0x187)],_0xb3b8c[_0x11e4c2(0x15f)],_0x14f993,_0x27c0d9,_0xb3b8c[_0x11e4c2(0x185)],getSdkClientRoutingConfig(),{'overwriteTypescript':_0x2425ae?![]:_0x116908,'allowEmptyModelReplacement':_0x2425ae?_0x116908:undefined,'scaffoldMode':_0x2425ae?_0x11e4c2(0x166):undefined,..._0x2425ae?{'modelProfile':{'name':_0xb3b8c[_0x11e4c2(0x185)],'defaultName':_0x155a39[_0x11e4c2(0x1a6)][_0x11e4c2(0x185)],'runtimeDomain':getRuntimeDomain()}}:{}});_0x53b21d[_0x11e4c2(0x18b)](_0xb3b8c['name']+':\x20'+describePull(_0x111923)),writeCliSideChannelLine('\x20\x20•\x20'+_0x111923[_0x11e4c2(0x194)]),writeCliSideChannelLine(_0x11e4c2(0x1b3)+_0x111923[_0x11e4c2(0x182)]),writeCliSideChannelLine(_0x11e4c2(0x1b3)+_0x111923[_0x11e4c2(0x16c)]),_0x111923[_0x11e4c2(0x165)]&&writeCliSideChannelLine(_0x11e4c2(0x1b3)+_0x111923[_0x11e4c2(0x165)]),_0x111923[_0x11e4c2(0x19e)]&&writeCliSideChannelLine('\x20\x20•\x20'+_0x111923[_0x11e4c2(0x19e)]),_0x4b1ed1[_0x11e4c2(0x1a7)](toPullData(_0x111923)),_0x122e30++;}catch(_0x2055aa){_0x53b21d[_0x11e4c2(0x16f)](_0xb3b8c[_0x11e4c2(0x185)]+':\x20'+(_0x2055aa instanceof Error?_0x2055aa[_0x11e4c2(0x18d)]:String(_0x2055aa))),_0x3ffeaf++;}}writeCliSideChannelLine('');if(_0x3ffeaf>0x0)writeCliSideChannelLine('!\x20'+_0x3ffeaf+_0x11e4c2(0x16e));return{'ok':_0x3ffeaf===0x0,'message':_0x11e4c2(0x189)+_0x122e30+_0x11e4c2(0x15d)+_0x3ffeaf+_0x11e4c2(0x175),'data':{'apps':_0x4b1ed1,'succeeded':_0x122e30,'failed':_0x3ffeaf}};}const _0x529dea=_0x2f67ca&&_0x2f67ca[_0x11e4c2(0x17b)]('-')?_0x2f67ca['split']('-')[_0x11e4c2(0x1b1)](0x1)[_0x11e4c2(0x190)]('-'):'',_0x148077=_0x3c8204||_0x1395d8['apiDir']||DEFAULT_API_DIR,_0x527b84=!_0x2f67ca,_0x217a0e=inspectModelRegistry(_0x148077,_0x1395d8['appCode']),_0x5f419d=_0x1395d8[_0x11e4c2(0x17d)]||_0x1395d8[_0x11e4c2(0x180)]?.[_0x11e4c2(0x176)]||_0x1395d8['mergedCli']?.['defaultApp']||_0x11e4c2(0x167);if(_0x217a0e[_0x11e4c2(0x16d)]&&!_0x217a0e[_0x11e4c2(0x170)]&&!_0x217a0e[_0x11e4c2(0x19d)])throw CliErrors[_0x11e4c2(0x169)](MODEL_REGISTRY_FILE_NAME+_0x11e4c2(0x19c)+_0x1395d8['appCode']+'\x22.','Select\x20a\x20configured\x20app\x20profile\x20or\x20use\x20a\x20separate\x20apiDir.');const _0x453528=a22_0x38a16e(_0x11e4c2(0x1ab)+_0x1395d8[_0x11e4c2(0x171)]+'...')[_0x11e4c2(0x1aa)]();try{const {configArray:_0x477abc}=await fetchModelList(_0x1395d8[_0x11e4c2(0x171)],_0x1395d8['cookie']),_0x452f6b=await generateApiFile(_0x477abc,_0x529dea,_0x1395d8[_0x11e4c2(0x171)],_0x527b84,getEnv(),_0x148077,undefined,getSdkClientRoutingConfig(),{'overwriteTypescript':_0x217a0e[_0x11e4c2(0x16d)]?![]:_0x116908,'allowEmptyModelReplacement':_0x217a0e['exists']?_0x116908:undefined,'scaffoldMode':_0x217a0e[_0x11e4c2(0x16d)]?'none':undefined,..._0x217a0e[_0x11e4c2(0x170)]||_0x217a0e[_0x11e4c2(0x19d)]||!_0x217a0e[_0x11e4c2(0x16d)]&&_0x116908?{'modelProfile':{'name':_0x5f419d,'defaultName':_0x1395d8[_0x11e4c2(0x180)]?.[_0x11e4c2(0x15e)]??_0x5f419d,'runtimeDomain':getRuntimeDomain()}}:{}});return _0x453528['succeed'](describePull(_0x452f6b)),writeCliSideChannelLine(_0x11e4c2(0x1b3)+_0x452f6b[_0x11e4c2(0x194)]),writeCliSideChannelLine(_0x11e4c2(0x1b3)+_0x452f6b[_0x11e4c2(0x182)]),writeCliSideChannelLine(_0x11e4c2(0x1b3)+_0x452f6b['clientFilePath']),_0x452f6b[_0x11e4c2(0x165)]&&writeCliSideChannelLine(_0x11e4c2(0x1b3)+_0x452f6b[_0x11e4c2(0x165)]),_0x452f6b['modelRuntimePath']&&writeCliSideChannelLine(_0x11e4c2(0x1b3)+_0x452f6b[_0x11e4c2(0x19e)]),{'ok':!![],'message':describePull(_0x452f6b),'data':toPullData(_0x452f6b)};}catch(_0x4b1d20){_0x453528[_0x11e4c2(0x16f)](_0x11e4c2(0x17c)+(_0x4b1d20 instanceof Error?_0x4b1d20[_0x11e4c2(0x18d)]:String(_0x4b1d20)));throw _0x4b1d20;}}};
|
|
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_0x54fa13=a37_0x27ed;(function(_0x18f634,_0x166681){const _0x36a682=a37_0x27ed,_0x183a20=_0x18f634();while(!![]){try{const _0x27b77a=parseInt(_0x36a682(0x206))/0x1*(parseInt(_0x36a682(0x1fc))/0x2)+parseInt(_0x36a682(0x237))/0x3*(-parseInt(_0x36a682(0x22d))/0x4)+parseInt(_0x36a682(0x238))/0x5*(-parseInt(_0x36a682(0x239))/0x6)+parseInt(_0x36a682(0x20b))/0x7+parseInt(_0x36a682(0x23a))/0x8*(-parseInt(_0x36a682(0x1f1))/0x9)+-parseInt(_0x36a682(0x222))/0xa+parseInt(_0x36a682(0x209))/0xb*(parseInt(_0x36a682(0x1f6))/0xc);if(_0x27b77a===_0x166681)break;else _0x183a20['push'](_0x183a20['shift']());}catch(_0x311475){_0x183a20['push'](_0x183a20['shift']());}}}(a37_0x3fea,0xeb48c));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':a37_0x54fa13(0x244),'command':a37_0x54fa13(0x1f8),'description':a37_0x54fa13(0x203),'risk':a37_0x54fa13(0x243),'flags':[{'name':a37_0x54fa13(0x213),'type':a37_0x54fa13(0x220),'required':!![],'enum':[a37_0x54fa13(0x24c),a37_0x54fa13(0x20d),a37_0x54fa13(0x1fa)],'description':a37_0x54fa13(0x205)},{'name':'name','type':'string','required':!![],'description':a37_0x54fa13(0x21d)},{'name':a37_0x54fa13(0x208),'type':a37_0x54fa13(0x220),'description':a37_0x54fa13(0x249)},{'name':a37_0x54fa13(0x214),'type':a37_0x54fa13(0x220),'description':a37_0x54fa13(0x224)},{'name':a37_0x54fa13(0x219),'type':a37_0x54fa13(0x220),'description':a37_0x54fa13(0x217)},{'name':a37_0x54fa13(0x204),'type':a37_0x54fa13(0x220),'description':a37_0x54fa13(0x1e6)},{'name':a37_0x54fa13(0x22e),'type':a37_0x54fa13(0x220),'description':a37_0x54fa13(0x241),'enum':[a37_0x54fa13(0x1ea),'after']}],async 'validate'(_0x2fcc27){const _0x2951c2=a37_0x54fa13,_0x1fa14c=_0x2fcc27['str'](_0x2951c2(0x23f));if(!isValidBffFunctionName(_0x1fa14c))throw CliErrors['validation'](_0x2951c2(0x1ff)+_0x1fa14c+_0x2951c2(0x22b));},async 'execute'(_0x1f28be){const _0x245bc8=a37_0x54fa13,_0x2a7519=loadBffProjectConfig(_0x1f28be[_0x245bc8(0x20e)]),_0x4aca08=_0x1f28be['str'](_0x245bc8(0x213)),_0x4855c7=_0x1f28be['str']('name'),_0x11d894=_0x1f28be['str'](_0x245bc8(0x208))||undefined,_0x5200ed=_0x4aca08===_0x245bc8(0x1fa)?await resolveHookOptions(_0x2a7519,_0x1f28be):undefined,_0x312bab=buildFilePath(_0x2a7519,_0x4aca08,_0x4855c7,_0x5200ed);if(await fileExists(_0x312bab))throw CliErrors[_0x245bc8(0x1e5)](_0x245bc8(0x207)+_0x312bab);await mkdir(dirname(_0x312bab),{'recursive':!![]});const _0x3f4266=generateTemplate(_0x4aca08,_0x4855c7,_0x1f28be[_0x245bc8(0x20e)],_0x11d894,_0x5200ed);await writeFile(_0x312bab,_0x3f4266,_0x245bc8(0x210));const _0xfa525f={'type':_0x4aca08,'name':_0x4855c7,'path':_0x312bab};if(_0x11d894)_0xfa525f[_0x245bc8(0x208)]=_0x11d894;if(_0x5200ed){if(_0x5200ed['alias'])_0xfa525f['alias']=_0x5200ed['alias'];_0xfa525f[_0x245bc8(0x229)]=_0x5200ed[_0x245bc8(0x229)],_0xfa525f[_0x245bc8(0x20c)]=_0x5200ed[_0x245bc8(0x20c)],_0xfa525f[_0x245bc8(0x226)]=_0x5200ed[_0x245bc8(0x226)];}return{'ok':!![],'data':_0xfa525f,'message':_0x245bc8(0x215)+_0x4aca08+'\x20function:\x20'+_0x4855c7};}};function a37_0x3fea(){const _0x168731=['\x0a\x20*\x20[平台配置]\x20','write','datasetCode','\x0a\x20*\x0a\x20*\x20[脚本类型]\x20ENDPOINT\x0a\x20*\x20[脚本名称]\x20','\x22.\x20Must\x20be\x20a\x20valid\x20JS\x20identifier\x20(e.g.\x20createOrder,\x20beforeFilter).','isInteger','223136aMHNls','function-node','/**\x0a\x20*\x20','\x0a\x20*\x0a\x20*\x20[脚本类型]\x20HOOK\x0a\x20*\x20[脚本名称]\x20','\x0a\x20*\x20[参数字段]\x20按实际输入为\x20params.<字段名>\x20补充\x20JSDoc\x20参数标签;无字段时仅保留根参数\x0a\x20*\x20[异常说明]\x20无;显式抛出异常时补充异常类型与触发条件\x0a\x20*\x0a\x20*\x20@param\x20{Object}\x20params\x20','close','tableName','HOOK\x20requires\x20alias/operation/node\x20options.','(params,\x20context)\x20{\x0a\x20\x20return\x20params;\x0a}\x0a','Dataset\x20not\x20found\x20for\x20code\x20\x22','60WxBGqG','5gUNllV','1460718sTNuuH','16fdtBfY','parseInt','Available:\x20','length','/data/backend-function\x0a\x20*\x20[本地路径]\x20.rabetbase/bff/','name','/HOOK/','Trigger\x20node\x20(HOOK\x20only)','\x20\x20Enter\x20a\x20number\x20between\x201\x20and\x20','read','bff','join','\x22.\x20','--alias\x20or\x20--datasetcode\x20is\x20required\x20for\x20HOOK\x20in\x20non-interactive\x20mode.','No\x20operation\x20types\x20found\x20for\x20dataset\x20','Script\x20description','/ENDPOINT/','\x20*\x20[依赖数据集]\x20无(如有依赖,DB_TABLE\x20填物理表名;METADATA\x20填数据集编码与用途)\x0a\x20*\x20[调用\x20BF]\x20无(如有调用,填写脚本名称与用途)\x0a\x20*\x20[执行\x20SQL]\x20无(如有执行,填写\x20SQL\x20名称与用途)\x0a\x20*\x20[副作用]\x20无(如有通知或外部调用,说明影响与失败策略)','COMMON','filePath','#api-list\x0a\x20*\x20[本地路径]\x20.rabetbase/bff/','--function-node\x20is\x20required\x20for\x20HOOK\x20in\x20non-interactive\x20mode.','stdin','Invalid\x20dataset\x20selection.','validation','Operation\x20type\x20(HOOK\x20only)','keys','\x20api\x20pull`\x20to\x20refresh.','当前响应结果','before','.js','HOOK\x20requires\x20hookOptions\x20for\x20template\x20generation.','\x0a\x20*/\x0aexport\x20default\x20async\x20function\x20','\x0a\x20*\x20@param\x20{Object}\x20context\x20平台注入的执行上下文\x0a\x20*\x20@returns\x20{Promise<Object>}\x20','/data/dataset/','\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','7424316lxbvyk','修改后的请求参数','nonInteractive','scriptsRootDir','str','2436ERCgBB','Alias\x20\x22','create','map','HOOK','\x22,\x20params\x20})\x0a','1545122grkglQ','\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','defaultApp','Invalid\x20function\x20name\x20\x22','profileName','The\x20generated\x20model\x20facts\x20may\x20be\x20stale\x20—\x20run\x20`','stderr','Scaffold\x20a\x20new\x20Backend\x20Function\x20script\x20from\x20template','operation-type','Script\x20type','1rptanJ','File\x20already\x20exists:\x20','description','186197eJYNDp','\x22\x20not\x20found\x20for\x20dataset\x20','4799991wAlfqQ','operationType','ENDPOINT','appCode','find','utf8','includes','修改后的响应结果','type','alias','Created\x20','\x0a\x20*\x20[接口路径]\x20POST\x20/api/endpoint/','Dataset\x20code\x20(HOOK\x20only,\x20fallback\x20when\x20alias\x20unavailable)','Select\x20dataset:','datasetcode','source','mergedCli','question','Function\x20name\x20(valid\x20JS\x20identifier)','--function-node\x20must\x20be\x20\x27before\x27\x20or\x20\x27after\x27.','apiDir','string','\x22\x20not\x20found.\x20','9217500NWFNbg','Select\x20operation\x20type:','Dataset\x20alias\x20from\x20api.ts\x20(HOOK\x20only,\x20preferred)','code','functionNode'];a37_0x3fea=function(){return _0x168731;};return a37_0x3fea();}function a37_0x27ed(_0x165f0a,_0x6df7cb){_0x165f0a=_0x165f0a-0x1e4;const _0x3fea48=a37_0x3fea();let _0x27ed0f=_0x3fea48[_0x165f0a];return _0x27ed0f;}async function resolveHookOptions(_0x4c5144,_0x28cfe6){const _0x338fcd=a37_0x54fa13,_0x2c845a=resolveApiModelSource(_0x28cfe6[_0x338fcd(0x21f)],_0x28cfe6[_0x338fcd(0x20e)],_0x28cfe6['selectedAppName']||_0x28cfe6[_0x338fcd(0x21b)]?.['currentApp']||_0x28cfe6[_0x338fcd(0x21b)]?.[_0x338fcd(0x1fe)]),_0x4f760f=loadAliasMap(_0x28cfe6[_0x338fcd(0x21f)],undefined,_0x2c845a[_0x338fcd(0x24d)],_0x2c845a['profileName']),_0x31d865=_0x4f760f[_0x338fcd(0x23d)]>0x0;let _0x55d321,_0x55556a,_0x28be37;const _0x409c9d=_0x28cfe6[_0x338fcd(0x1f5)](_0x338fcd(0x214)),_0x4c005f=_0x28cfe6[_0x338fcd(0x1f5)](_0x338fcd(0x219));if(_0x409c9d){const _0x4074a6=resolveAlias(_0x28cfe6[_0x338fcd(0x21f)],_0x409c9d,undefined,_0x2c845a[_0x338fcd(0x24d)],_0x2c845a[_0x338fcd(0x200)]);if(!_0x4074a6){const _0x328e64=_0x31d865?'Available\x20aliases:\x20'+_0x4f760f[_0x338fcd(0x1f9)](_0x1834d7=>_0x1834d7[_0x338fcd(0x214)])[_0x338fcd(0x245)](',\x20'):'No\x20model\x20aliases\x20found.\x20Run\x20`'+CLI_BIN_NAME+'\x20api\x20pull`\x20first,\x20or\x20use\x20--datasetcode\x20instead.';throw CliErrors[_0x338fcd(0x1e5)](_0x338fcd(0x1f7)+_0x409c9d+_0x338fcd(0x221)+_0x328e64);}_0x55d321=_0x409c9d,_0x55556a=_0x4074a6;}else{if(_0x4c005f){_0x55556a=_0x4c005f;const _0x5a4ea1=_0x4f760f[_0x338fcd(0x20f)](_0x4f5fed=>_0x4f5fed[_0x338fcd(0x229)]===_0x4c005f);_0x55d321=_0x5a4ea1?.[_0x338fcd(0x214)];}else{if(_0x28cfe6[_0x338fcd(0x1f3)])throw CliErrors['validation'](_0x338fcd(0x247));else{if(_0x31d865){const _0x9cb28c=_0x4f760f[_0x338fcd(0x1f9)](_0x115b87=>_0x115b87[_0x338fcd(0x214)]+'\x20('+_0x115b87[_0x338fcd(0x233)]+')'),_0x4c3713=await promptSelect(_0x338fcd(0x218),_0x9cb28c),_0x2b16e3=_0x4f760f[_0x4c3713];if(!_0x2b16e3)throw CliErrors[_0x338fcd(0x1e5)](_0x338fcd(0x1e4));_0x55d321=_0x2b16e3[_0x338fcd(0x214)],_0x55556a=_0x2b16e3[_0x338fcd(0x229)];}else{const _0x33a532=await listDatasets(_0x28cfe6['appCode']);if(_0x33a532['length']===0x0)throw CliErrors['validation']('No\x20datasets\x20found\x20for\x20this\x20app.');const _0x4d950c=_0x33a532[_0x338fcd(0x1f9)](_0x2ccbf9=>_0x2ccbf9[_0x338fcd(0x23f)]+'\x20['+(_0x2ccbf9[_0x338fcd(0x21a)]??'UNKNOWN')+']\x20('+_0x2ccbf9['code']+')'),_0x521491=await promptSelect(_0x338fcd(0x218),_0x4d950c),_0x1a056c=_0x33a532[_0x521491];if(!_0x1a056c)throw CliErrors[_0x338fcd(0x1e5)]('Invalid\x20dataset\x20selection.');_0x55556a=_0x1a056c[_0x338fcd(0x225)],_0x55d321=undefined;}}}}const _0x514a2c=await listDatasets(_0x28cfe6[_0x338fcd(0x20e)]),_0x3a3dc6=_0x514a2c[_0x338fcd(0x20f)](_0x391dda=>_0x391dda[_0x338fcd(0x225)]===_0x55556a);if(!_0x3a3dc6)throw CliErrors[_0x338fcd(0x1e5)](_0x338fcd(0x236)+_0x55556a+_0x338fcd(0x246)+(_0x55d321?_0x338fcd(0x201)+CLI_BIN_NAME+_0x338fcd(0x1e8):''));_0x28be37=_0x3a3dc6['id'];const _0x50fc02=_0x55d321??_0x55556a,_0x3f959e=await listBffDatasetOperations(_0x28cfe6[_0x338fcd(0x20e)],_0x28be37),_0x4973ae=_0x3f959e?Object[_0x338fcd(0x1e7)](_0x3f959e):[];if(_0x4973ae[_0x338fcd(0x23d)]===0x0)throw CliErrors['validation'](_0x338fcd(0x248)+_0x50fc02+'.');let _0x13dc1c;const _0x48d6a2=_0x28cfe6['str'](_0x338fcd(0x204));if(_0x48d6a2){if(!_0x4973ae[_0x338fcd(0x211)](_0x48d6a2))throw CliErrors[_0x338fcd(0x1e5)]('Operation\x20type\x20\x22'+_0x48d6a2+_0x338fcd(0x20a)+_0x50fc02+'.\x20'+(_0x338fcd(0x23c)+_0x4973ae['join'](',\x20')));_0x13dc1c=_0x48d6a2;}else{if(_0x28cfe6[_0x338fcd(0x1f3)])throw CliErrors['validation']('--operation-type\x20is\x20required\x20for\x20HOOK\x20in\x20non-interactive\x20mode.');const _0x4ec9bb=await promptSelect(_0x338fcd(0x223),_0x4973ae);_0x13dc1c=_0x4973ae[_0x4ec9bb]??_0x4973ae[0x0];}let _0x28a30d=normalizeHookFunctionNode(_0x28cfe6[_0x338fcd(0x1f5)](_0x338fcd(0x22e)));if(!_0x28a30d){if(_0x28cfe6[_0x338fcd(0x1f5)](_0x338fcd(0x22e)))throw CliErrors['validation'](_0x338fcd(0x21e));if(_0x28cfe6[_0x338fcd(0x1f3)])throw CliErrors['validation'](_0x338fcd(0x24f));const _0xff9680=await promptSelect('Select\x20trigger\x20node:',[_0x338fcd(0x1ea),'after']);_0x28a30d=[_0x338fcd(0x1ea),'after'][_0xff9680]??'before';}return{'alias':_0x55d321,'datasetCode':_0x55556a,'datasetId':_0x28be37,'operationType':_0x13dc1c,'functionNode':_0x28a30d};}async function promptSelect(_0x4b79d5,_0x1d60d2){const _0x5d3b08=a37_0x54fa13;if(_0x1d60d2['length']===0x1)return 0x0;for(const [_0x589f32,_0x3edbce]of _0x1d60d2['entries']()){process[_0x5d3b08(0x202)][_0x5d3b08(0x228)]('\x20\x20'+(_0x589f32+0x1)+'.\x20'+_0x3edbce+'\x0a');}const _0x12d784=createInterface({'input':process[_0x5d3b08(0x250)],'output':process['stderr']});while(!![]){const _0x2d6e87=await new Promise(_0x2376eb=>{const _0x4c77f4=_0x5d3b08;_0x12d784[_0x4c77f4(0x21c)](_0x4b79d5+'\x20',_0x2376eb);}),_0x4b1f0e=Number[_0x5d3b08(0x23b)](_0x2d6e87['trim'](),0xa);if(Number[_0x5d3b08(0x22c)](_0x4b1f0e)&&_0x4b1f0e>=0x1&&_0x4b1f0e<=_0x1d60d2[_0x5d3b08(0x23d)])return _0x12d784[_0x5d3b08(0x232)](),_0x4b1f0e-0x1;process[_0x5d3b08(0x202)][_0x5d3b08(0x228)](_0x5d3b08(0x242)+_0x1d60d2[_0x5d3b08(0x23d)]+'.\x0a');}}function buildFilePath(_0x18bec5,_0x4e233c,_0x44ab6d,_0x287716){const _0x35812c=a37_0x54fa13;if(_0x4e233c==='HOOK'){if(!_0x287716)throw CliErrors[_0x35812c(0x1e5)](_0x35812c(0x234));const _0x139982=_0x287716[_0x35812c(0x214)]??_0x287716['datasetCode'];return join(_0x18bec5[_0x35812c(0x1f4)],_0x35812c(0x1fa),_0x139982,_0x287716[_0x35812c(0x20c)],_0x287716[_0x35812c(0x226)],_0x44ab6d+_0x35812c(0x1eb));}return join(_0x18bec5['scriptsRootDir'],_0x4e233c,_0x44ab6d+_0x35812c(0x1eb));}export function generateTemplate(_0x551226,_0x2fa378,_0x14b9b8,_0x17fc4a,_0x48553e){const _0x260b1b=a37_0x54fa13,_0x51e5a5=_0x17fc4a?.['trim']()||DEFAULT_BFF_SCRIPT_DESCRIPTION,_0x318ba5=getAppBaseUrl(_0x14b9b8),_0x2f7d31=_0x260b1b(0x24b);if(_0x551226==='COMMON')return'/**\x0a\x20*\x20'+_0x51e5a5+'\x0a\x20*\x0a\x20*\x20[脚本类型]\x20COMMON\x0a\x20*\x20[脚本名称]\x20'+_0x2fa378+'\x0a\x20*\x20[平台配置]\x20'+_0x318ba5+_0x260b1b(0x23e)+_0x14b9b8+'/COMMON/'+_0x2fa378+'.js\x0a\x20*\x20[调用方式]\x20context.client.bff.execute({\x20scriptName:\x20\x22'+_0x2fa378+_0x260b1b(0x1fb)+_0x2f7d31+_0x260b1b(0x1f0)+_0x2fa378+'(params,\x20context)\x20{\x0a\x20\x20return\x20params;\x0a}\x0a';if(_0x551226===_0x260b1b(0x20d))return _0x260b1b(0x22f)+_0x51e5a5+_0x260b1b(0x22a)+_0x2fa378+_0x260b1b(0x216)+_0x14b9b8+'/'+_0x2fa378+_0x260b1b(0x227)+_0x318ba5+'/data/backend-function\x0a\x20*\x20[本地路径]\x20.rabetbase/bff/'+_0x14b9b8+_0x260b1b(0x24a)+_0x2fa378+'.js\x0a'+_0x2f7d31+_0x260b1b(0x1fd)+_0x2fa378+_0x260b1b(0x235);if(!_0x48553e)throw CliErrors[_0x260b1b(0x1e5)](_0x260b1b(0x1ec));const _0x3e4fa4=_0x48553e[_0x260b1b(0x214)]??_0x48553e[_0x260b1b(0x229)],_0xb0db35=_0x48553e[_0x260b1b(0x226)]===_0x260b1b(0x1ea)?'当前请求参数':_0x260b1b(0x1e9),_0x59e814=_0x48553e[_0x260b1b(0x226)]===_0x260b1b(0x1ea)?_0x260b1b(0x1f2):_0x260b1b(0x212);return _0x260b1b(0x22f)+_0x51e5a5+_0x260b1b(0x230)+_0x2fa378+'\x0a\x20*\x20[接口路径]\x20POST\x20/api/'+_0x14b9b8+'/'+_0x48553e['datasetCode']+'/'+_0x48553e['operationType']+_0x260b1b(0x227)+_0x318ba5+_0x260b1b(0x1ef)+_0x48553e['datasetId']+_0x260b1b(0x24e)+_0x14b9b8+_0x260b1b(0x240)+_0x3e4fa4+'/'+_0x48553e['operationType']+'/'+_0x48553e[_0x260b1b(0x226)]+'/'+_0x2fa378+'.js\x0a\x20*\x20[触发节点]\x20'+_0x48553e[_0x260b1b(0x226)]+'\x0a'+_0x2f7d31+_0x260b1b(0x231)+_0xb0db35+_0x260b1b(0x1ee)+_0x59e814+_0x260b1b(0x1ed)+_0x2fa378+_0x260b1b(0x235);}
|
|
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];
|