@huawei-iac-tools/landingzone-workbench 0.0.0-stage → 0.0.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/LICENSE +201 -0
- package/README.md +85 -2
- package/cordis.patch.yml +21 -0
- package/knowledge/account-qualification.md +128 -0
- package/knowledge/blueprints/_base/blueprint.json +481 -0
- package/knowledge/blueprints/_base/defaults.json +127 -0
- package/knowledge/blueprints/foundation-lz/blueprint.json +43 -0
- package/knowledge/blueprints/foundation-lz/defaults.json +47 -0
- package/knowledge/blueprints/full-lz/blueprint.json +11 -0
- package/knowledge/blueprints/full-lz/defaults.json +8 -0
- package/knowledge/config.json +43 -0
- package/knowledge/error-rules.json +14 -0
- package/knowledge/ic-policies.json +21 -0
- package/knowledge/modules/account-structure.md +101 -0
- package/knowledge/modules/compliance/config-rms.md +212 -0
- package/knowledge/modules/compliance/cts.md +179 -0
- package/knowledge/modules/compliance/obs-lts.md +155 -0
- package/knowledge/modules/ic-policies.json +21 -0
- package/knowledge/modules/identity-center.md +603 -0
- package/knowledge/modules/module-layers.md +169 -0
- package/knowledge/modules/network/er.md +222 -0
- package/knowledge/modules/network/nat-eip.md +123 -0
- package/knowledge/modules/network/ram-share.md +92 -0
- package/knowledge/modules/network/vpc-subnet.md +142 -0
- package/knowledge/modules/organization-security/scp.md +122 -0
- package/knowledge/modules/organizations.md +212 -0
- package/knowledge/modules/recommended-config.md +157 -0
- package/knowledge/modules/recommended-rules.json +175 -0
- package/knowledge/modules/scp-policies.json +111 -0
- package/knowledge/modules/security/aad.md +94 -0
- package/knowledge/modules/security/cfw.md +105 -0
- package/knowledge/modules/security/waf.md +110 -0
- package/knowledge/param-mappings.json +133 -0
- package/knowledge/prompts.md +83 -0
- package/knowledge/resource-types.json +1162 -0
- package/knowledge/scp-policies.json +111 -0
- package/knowledge/state-machine.md +33 -0
- package/lib/client.js +21 -0
- package/lib/index.js +28592 -0
- package/lib/types/account-role.d.ts +19 -0
- package/lib/types/account-scope.d.ts +10 -0
- package/lib/types/agency.d.ts +38 -0
- package/lib/types/client/DropdownSelect.d.ts +49 -0
- package/lib/types/client/LoginGate.d.ts +20 -0
- package/lib/types/client/PanelIcon.d.ts +11 -0
- package/lib/types/client/WorkbenchShell.d.ts +21 -0
- package/lib/types/client/account-role.d.ts +15 -0
- package/lib/types/client/credential-status.d.ts +15 -0
- package/lib/types/client/huawei-mark.d.ts +37 -0
- package/lib/types/client/index.d.ts +26 -0
- package/lib/types/client/layout-ref.d.ts +23 -0
- package/lib/types/client/pages/ConfigPage/AdviceCard.d.ts +26 -0
- package/lib/types/client/pages/ConfigPage/AuditBar.d.ts +21 -0
- package/lib/types/client/pages/ConfigPage/ChangeSummaryCard.d.ts +22 -0
- package/lib/types/client/pages/ConfigPage/ChangesCard.d.ts +27 -0
- package/lib/types/client/pages/ConfigPage/ComplianceDetail.d.ts +25 -0
- package/lib/types/client/pages/ConfigPage/ComplianceSummaryCard.d.ts +31 -0
- package/lib/types/client/pages/ConfigPage/FindingsCard.d.ts +21 -0
- package/lib/types/client/pages/ConfigPage/GlossaryDrawer.d.ts +17 -0
- package/lib/types/client/pages/ConfigPage/OrgComplianceDetail.d.ts +15 -0
- package/lib/types/client/pages/ConfigPage/Pager.d.ts +32 -0
- package/lib/types/client/pages/ConfigPage/ResourceDrawer.d.ts +26 -0
- package/lib/types/client/pages/ConfigPage/ResourcesTable.d.ts +35 -0
- package/lib/types/client/pages/ConfigPage/RollupPanel.d.ts +17 -0
- package/lib/types/client/pages/ConfigPage/RuleDetailDrawer.d.ts +23 -0
- package/lib/types/client/pages/ConfigPage/StatusCards.d.ts +26 -0
- package/lib/types/client/pages/ConfigPage/UncoveredDialog.d.ts +22 -0
- package/lib/types/client/pages/ConfigPage/config-api.d.ts +101 -0
- package/lib/types/client/pages/ConfigPage/config-store.d.ts +57 -0
- package/lib/types/client/pages/ConfigPage/index.d.ts +21 -0
- package/lib/types/client/pages/ConfigPage/paging.d.ts +46 -0
- package/lib/types/client/pages/ConfigPage/scope-options.d.ts +51 -0
- package/lib/types/client/pages/CostPage/AccountAllocation.d.ts +24 -0
- package/lib/types/client/pages/CostPage/AccountBars.d.ts +20 -0
- package/lib/types/client/pages/CostPage/AccountColumns.d.ts +24 -0
- package/lib/types/client/pages/CostPage/AccountDonut.d.ts +18 -0
- package/lib/types/client/pages/CostPage/AccountSwitcher.d.ts +25 -0
- package/lib/types/client/pages/CostPage/AdviceCard.d.ts +43 -0
- package/lib/types/client/pages/CostPage/AdviceFindings.d.ts +43 -0
- package/lib/types/client/pages/CostPage/BillingPanels.d.ts +23 -0
- package/lib/types/client/pages/CostPage/BudgetCard.d.ts +36 -0
- package/lib/types/client/pages/CostPage/GlossaryDrawer.d.ts +16 -0
- package/lib/types/client/pages/CostPage/KpiRow.d.ts +23 -0
- package/lib/types/client/pages/CostPage/MarkdownBlock.d.ts +16 -0
- package/lib/types/client/pages/CostPage/ReportView.d.ts +17 -0
- package/lib/types/client/pages/CostPage/ResourceColumns.d.ts +19 -0
- package/lib/types/client/pages/CostPage/ResourceDonut.d.ts +18 -0
- package/lib/types/client/pages/CostPage/ResourcesCard.d.ts +40 -0
- package/lib/types/client/pages/CostPage/RuleDetailDrawer.d.ts +23 -0
- package/lib/types/client/pages/CostPage/SavingView.d.ts +38 -0
- package/lib/types/client/pages/CostPage/ServiceDonut.d.ts +17 -0
- package/lib/types/client/pages/CostPage/TrendChart.d.ts +24 -0
- package/lib/types/client/pages/CostPage/budget-input.d.ts +30 -0
- package/lib/types/client/pages/CostPage/cost-api.d.ts +266 -0
- package/lib/types/client/pages/CostPage/cost-store.d.ts +25 -0
- package/lib/types/client/pages/CostPage/format.d.ts +37 -0
- package/lib/types/client/pages/CostPage/index.d.ts +34 -0
- package/lib/types/client/pages/CostPage/trend-fold.d.ts +32 -0
- package/lib/types/client/pages/CostPage/useEcharts.d.ts +70 -0
- package/lib/types/client/pages/OrgStructurePage/AccountStatsCard.d.ts +22 -0
- package/lib/types/client/pages/OrgStructurePage/CoreAccountsCard.d.ts +18 -0
- package/lib/types/client/pages/OrgStructurePage/CreateAccountDialog.d.ts +28 -0
- package/lib/types/client/pages/OrgStructurePage/ManageUsersDialog.d.ts +28 -0
- package/lib/types/client/pages/OrgStructurePage/MemberAccountsTable.d.ts +32 -0
- package/lib/types/client/pages/OrgStructurePage/MoveAccountDialog.d.ts +29 -0
- package/lib/types/client/pages/OrgStructurePage/OrgGlossaryDrawer.d.ts +13 -0
- package/lib/types/client/pages/OrgStructurePage/OrgTreeCard.d.ts +31 -0
- package/lib/types/client/pages/OrgStructurePage/index.d.ts +21 -0
- package/lib/types/client/pages/OrgStructurePage/org-api.d.ts +166 -0
- package/lib/types/client/pages/OverviewPage/AnchorRow.d.ts +24 -0
- package/lib/types/client/pages/OverviewPage/AttentionList.d.ts +29 -0
- package/lib/types/client/pages/OverviewPage/OverviewCharts.d.ts +79 -0
- package/lib/types/client/pages/OverviewPage/OverviewGlossaryDrawer.d.ts +15 -0
- package/lib/types/client/pages/OverviewPage/index.d.ts +22 -0
- package/lib/types/client/pages/OverviewPage/overview-api.d.ts +115 -0
- package/lib/types/client/pages/ResourcePage/AccountResourceList.d.ts +21 -0
- package/lib/types/client/pages/ResourcePage/components/GlossaryDrawer.d.ts +20 -0
- package/lib/types/client/pages/ResourcePage/components/MetricCards.d.ts +19 -0
- package/lib/types/client/pages/ResourcePage/components/MultiSelect.d.ts +27 -0
- package/lib/types/client/pages/ResourcePage/components/PanelPager.d.ts +26 -0
- package/lib/types/client/pages/ResourcePage/components/RankBars.d.ts +25 -0
- package/lib/types/client/pages/ResourcePage/components/ScopeSelect.d.ts +27 -0
- package/lib/types/client/pages/ResourcePage/components/SourceConfigModal.d.ts +21 -0
- package/lib/types/client/pages/ResourcePage/components/SyncControls.d.ts +18 -0
- package/lib/types/client/pages/ResourcePage/components/TrendChart.d.ts +14 -0
- package/lib/types/client/pages/ResourcePage/components/useColumnWidths.d.ts +12 -0
- package/lib/types/client/pages/ResourcePage/format.d.ts +9 -0
- package/lib/types/client/pages/ResourcePage/index.d.ts +20 -0
- package/lib/types/client/pages/ResourcePage/summary-api.d.ts +205 -0
- package/lib/types/client/pages/SetupPage/AskPanel.d.ts +21 -0
- package/lib/types/client/pages/SetupPage/ChatEmbed.d.ts +40 -0
- package/lib/types/client/pages/SetupPage/ChatTab.d.ts +17 -0
- package/lib/types/client/pages/SetupPage/FormTab.d.ts +12 -0
- package/lib/types/client/pages/SetupPage/FormTabV2.d.ts +14 -0
- package/lib/types/client/pages/SetupPage/ProgressTreeView.d.ts +15 -0
- package/lib/types/client/pages/SetupPage/StageFlow.d.ts +16 -0
- package/lib/types/client/pages/SetupPage/index.d.ts +10 -0
- package/lib/types/client/pages/SetupPage/progress-types.d.ts +36 -0
- package/lib/types/client/pages/SetupPage/session-binding.d.ts +38 -0
- package/lib/types/client/pages/SetupPage/session-store.d.ts +57 -0
- package/lib/types/client/pages/SetupPage/sessions-ref.d.ts +5 -0
- package/lib/types/client/pages/SetupPage/setup-replan.d.ts +13 -0
- package/lib/types/client/pages/SetupPage/wb-api.d.ts +192 -0
- package/lib/types/client/pages/list-preview.d.ts +36 -0
- package/lib/types/client/permission-mode.d.ts +53 -0
- package/lib/types/client/store.d.ts +22 -0
- package/lib/types/collect.d.ts +78 -0
- package/lib/types/config/account-scope.d.ts +61 -0
- package/lib/types/config/advice-findings.d.ts +31 -0
- package/lib/types/config/advice-prompt.d.ts +60 -0
- package/lib/types/config/advice.d.ts +116 -0
- package/lib/types/config/cts.d.ts +30 -0
- package/lib/types/config/evidence/rules.d.ts +31 -0
- package/lib/types/config/evidence/types.d.ts +103 -0
- package/lib/types/config/failure-note.d.ts +46 -0
- package/lib/types/config/fingerprint-cache.d.ts +45 -0
- package/lib/types/config/identity.d.ts +67 -0
- package/lib/types/config/query.d.ts +49 -0
- package/lib/types/config/rms.d.ts +412 -0
- package/lib/types/config/routes.d.ts +32 -0
- package/lib/types/config/types.d.ts +785 -0
- package/lib/types/config/views.d.ts +158 -0
- package/lib/types/cost/accounts.d.ts +29 -0
- package/lib/types/cost/advice-findings.d.ts +77 -0
- package/lib/types/cost/advice-model.d.ts +19 -0
- package/lib/types/cost/advice-prompt.d.ts +73 -0
- package/lib/types/cost/advice-subagent-types.d.ts +6 -0
- package/lib/types/cost/advice-subagent.d.ts +116 -0
- package/lib/types/cost/advice-types.d.ts +63 -0
- package/lib/types/cost/advice.d.ts +125 -0
- package/lib/types/cost/aggregate.d.ts +157 -0
- package/lib/types/cost/assume.d.ts +43 -0
- package/lib/types/cost/bss.d.ts +166 -0
- package/lib/types/cost/budget-overview.d.ts +38 -0
- package/lib/types/cost/budget.d.ts +56 -0
- package/lib/types/cost/cache.d.ts +58 -0
- package/lib/types/cost/caliber.d.ts +40 -0
- package/lib/types/cost/console-links.d.ts +27 -0
- package/lib/types/cost/credentials.d.ts +38 -0
- package/lib/types/cost/data-window.d.ts +38 -0
- package/lib/types/cost/evidence/catalog.d.ts +35 -0
- package/lib/types/cost/evidence/index.d.ts +70 -0
- package/lib/types/cost/evidence/inventory.d.ts +44 -0
- package/lib/types/cost/evidence/pricing.d.ts +72 -0
- package/lib/types/cost/evidence/projects.d.ts +18 -0
- package/lib/types/cost/evidence/rules.d.ts +66 -0
- package/lib/types/cost/evidence/state.d.ts +38 -0
- package/lib/types/cost/evidence/thresholds.d.ts +68 -0
- package/lib/types/cost/evidence/types.d.ts +288 -0
- package/lib/types/cost/evidence/utilization.d.ts +37 -0
- package/lib/types/cost/history.d.ts +36 -0
- package/lib/types/cost/ledger.d.ts +97 -0
- package/lib/types/cost/normalize.d.ts +37 -0
- package/lib/types/cost/period-projection.d.ts +57 -0
- package/lib/types/cost/plan-check.d.ts +102 -0
- package/lib/types/cost/plan-db.d.ts +73 -0
- package/lib/types/cost/plan-types.d.ts +183 -0
- package/lib/types/cost/plan.d.ts +63 -0
- package/lib/types/cost/quote.d.ts +45 -0
- package/lib/types/cost/report.d.ts +136 -0
- package/lib/types/cost/resources.d.ts +108 -0
- package/lib/types/cost/routes.d.ts +38 -0
- package/lib/types/cost/scope.d.ts +42 -0
- package/lib/types/cost/types.d.ts +335 -0
- package/lib/types/cost/unit-prices-derive.d.ts +19 -0
- package/lib/types/cost/unit-prices.d.ts +23 -0
- package/lib/types/db.d.ts +228 -0
- package/lib/types/host-log.d.ts +7 -0
- package/lib/types/http.d.ts +42 -0
- package/lib/types/index.d.ts +30 -0
- package/lib/types/inventory.d.ts +286 -0
- package/lib/types/obs.d.ts +16 -0
- package/lib/types/org/aggregate.d.ts +36 -0
- package/lib/types/org/churn.d.ts +10 -0
- package/lib/types/org/orgs.d.ts +258 -0
- package/lib/types/org/routes.d.ts +28 -0
- package/lib/types/org-types.d.ts +156 -0
- package/lib/types/per-service.d.ts +39 -0
- package/lib/types/setup/blueprint-loader.d.ts +81 -0
- package/lib/types/setup/caller.d.ts +105 -0
- package/lib/types/setup/engine.d.ts +41 -0
- package/lib/types/setup/form-store.d.ts +13 -0
- package/lib/types/setup/nodes/n1-check.d.ts +14 -0
- package/lib/types/setup/nodes/n10-governance.d.ts +6 -0
- package/lib/types/setup/nodes/n11-infra.d.ts +6 -0
- package/lib/types/setup/nodes/n12-reconcile.d.ts +6 -0
- package/lib/types/setup/nodes/n2-region.d.ts +6 -0
- package/lib/types/setup/nodes/n3-blueprint.d.ts +6 -0
- package/lib/types/setup/nodes/n4-modules.d.ts +6 -0
- package/lib/types/setup/nodes/n5-details.d.ts +6 -0
- package/lib/types/setup/nodes/n6-plan.d.ts +6 -0
- package/lib/types/setup/nodes/n7-verify.d.ts +6 -0
- package/lib/types/setup/nodes/n8-approve.d.ts +6 -0
- package/lib/types/setup/nodes/n9-buildmode.d.ts +6 -0
- package/lib/types/setup/plan-state.d.ts +10 -0
- package/lib/types/setup/prompt-loader.d.ts +16 -0
- package/lib/types/setup/routes.d.ts +22 -0
- package/lib/types/setup/session-notify.d.ts +30 -0
- package/lib/types/setup/tools.d.ts +19 -0
- package/lib/types/setup/types.d.ts +157 -0
- package/lib/types/sse-bus.d.ts +23 -0
- package/lib/types/tools/config-facts.d.ts +16 -0
- package/lib/types/tools/cost-facts.d.ts +10 -0
- package/lib/types/tools/register.d.ts +18 -0
- package/lib/types/wb-conventions.d.ts +140 -0
- package/package.json +77 -4
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { AdviceStructured } from './advice-types.ts';
|
|
2
|
+
import type { FindingsResult } from './evidence/types.ts';
|
|
3
|
+
export type { AdviceItem, AdviceStructured } from './advice-types.ts';
|
|
4
|
+
export { RISK_LABEL, normalizeStructured, parseAdviceOutput } from './advice-types.ts';
|
|
5
|
+
/** 一份建议的口径。 */
|
|
6
|
+
export interface AdviceScope {
|
|
7
|
+
readonly cycle: string;
|
|
8
|
+
/** null = 主账号(全组织)视角。 */
|
|
9
|
+
readonly account_id: string | null;
|
|
10
|
+
readonly account_name: string | null;
|
|
11
|
+
}
|
|
12
|
+
/** 一份建议。 */
|
|
13
|
+
export interface AdviceRecord {
|
|
14
|
+
readonly scope: AdviceScope;
|
|
15
|
+
readonly generated_at: string;
|
|
16
|
+
readonly status: 'ready' | 'failed';
|
|
17
|
+
/** markdown 正文(status=failed 时为空串)。 */
|
|
18
|
+
readonly markdown: string;
|
|
19
|
+
/** 结构化条目;解析不出来时为 null,卡片退回显示 markdown。 */
|
|
20
|
+
readonly structured: AdviceStructured | null;
|
|
21
|
+
/**
|
|
22
|
+
* 生成时算出的**资源级发现**(新版记录有,老存档没有)。
|
|
23
|
+
*
|
|
24
|
+
* 为什么和 structured 分开存:structured 是模型的叙述,findings 是规则算的
|
|
25
|
+
* 事实。卡片把两者分开渲染 —— 数字永远来自 findings,模型改不动。
|
|
26
|
+
*/
|
|
27
|
+
readonly findings?: FindingsResult | null;
|
|
28
|
+
/** 生成它的会话 id,便于"看依据"。 */
|
|
29
|
+
readonly session_id: string | null;
|
|
30
|
+
readonly model: string | null;
|
|
31
|
+
/** 生成时那一刻的数据指纹(服务端算的,见 fingerprintOf)。 */
|
|
32
|
+
readonly fingerprint: string;
|
|
33
|
+
/** 生成时数据的截止时间。 */
|
|
34
|
+
readonly facts_as_of: string;
|
|
35
|
+
readonly last_stat_date: string | null;
|
|
36
|
+
/** status=failed 时的原因。 */
|
|
37
|
+
readonly error?: string;
|
|
38
|
+
/**
|
|
39
|
+
* 模型那一层失败的原因 —— 规则部分仍然齐全,所以存档照写(模板版)。
|
|
40
|
+
*
|
|
41
|
+
* 与 `AdviceError` 的区别:那个是"整次生成失败、没有新结果";这里生成本身是
|
|
42
|
+
* 成功的(金额/证据/条目都在),只是叙述没拿到。卡片用一句轻提示标出来,
|
|
43
|
+
* 不能再像以前那样静默降级 —— 否则模板版会被当成模型给的结论。
|
|
44
|
+
*/
|
|
45
|
+
readonly model_error?: {
|
|
46
|
+
readonly at: string;
|
|
47
|
+
readonly message: string;
|
|
48
|
+
} | null;
|
|
49
|
+
/** 旧版本,按时间倒序。 */
|
|
50
|
+
readonly history?: readonly AdviceHistoryEntry[];
|
|
51
|
+
}
|
|
52
|
+
/** 一个历史版本。 */
|
|
53
|
+
export interface AdviceHistoryEntry {
|
|
54
|
+
readonly generated_at: string;
|
|
55
|
+
readonly markdown: string;
|
|
56
|
+
readonly fingerprint: string;
|
|
57
|
+
readonly structured?: AdviceStructured | null;
|
|
58
|
+
}
|
|
59
|
+
/** 一次失败记录(与建议正文分开存)。 */
|
|
60
|
+
export interface AdviceError {
|
|
61
|
+
readonly at: string;
|
|
62
|
+
readonly error: string;
|
|
63
|
+
}
|
|
64
|
+
/** 失败记录的路径(与正文同目录,扩展名不同)。 */
|
|
65
|
+
export declare function adviceErrorPath(cycle: string, accountId?: string | null): Promise<string>;
|
|
66
|
+
/** 读取上一次失败(没有则为 null)。 */
|
|
67
|
+
export declare function readAdviceError(cycle: string, accountId?: string | null): Promise<AdviceError | null>;
|
|
68
|
+
/**
|
|
69
|
+
* 记一次失败。
|
|
70
|
+
*
|
|
71
|
+
* **不覆盖已有建议**:生成失败是常态(模型超时、会话断了),而用户手里那份
|
|
72
|
+
* 建议可能正是他在执行的版本 —— 用一次失败把它抹掉,等于让他白等一场。
|
|
73
|
+
* 所以失败单独存一个文件,页面上作为"提示"出现。
|
|
74
|
+
*/
|
|
75
|
+
export declare function recordAdviceError(cycle: string, accountId: string | null | undefined, error: string): Promise<AdviceError>;
|
|
76
|
+
/** 成功生成后清掉旧失败记录。 */
|
|
77
|
+
export declare function clearAdviceError(cycle: string, accountId?: string | null): Promise<void>;
|
|
78
|
+
/** 页面读到的东西:建议本体 + 是否已过期 + 当前指纹 + 上次失败。 */
|
|
79
|
+
export interface AdviceView {
|
|
80
|
+
readonly advice: AdviceRecord | null;
|
|
81
|
+
/** advice 存在且其指纹与当前数据不一致 → true。 */
|
|
82
|
+
readonly stale: boolean;
|
|
83
|
+
/** 当前数据(这一刻)的指纹;advice 为 null 时也要给,方便页面比对。 */
|
|
84
|
+
readonly fingerprint: string;
|
|
85
|
+
/** 当前数据的截止时间,用于提示"建议基于 11-02 的数据"。 */
|
|
86
|
+
readonly facts_as_of: string;
|
|
87
|
+
/** 上一次生成失败的原因(成功生成后会清掉)。 */
|
|
88
|
+
readonly last_error: AdviceError | null;
|
|
89
|
+
}
|
|
90
|
+
/** 存档目录(按登录账号隔离,2026-11-20 用户定稿——与 SQLite 同一逻辑)。 */
|
|
91
|
+
export declare function adviceDir(): Promise<string>;
|
|
92
|
+
/** 某口径的存档路径:`advice/all-2026-11-ORIGINAL_COST.json`、`advice/01a0…-2026-11-AMORTIZED_COST.json`。 */
|
|
93
|
+
export declare function advicePath(cycle: string, accountId?: string | null): Promise<string>;
|
|
94
|
+
/** 读一份建议;文件不存在或坏掉都当作没有(不抛错到页面)。 */
|
|
95
|
+
export declare function readAdvice(cycle: string, accountId?: string | null): Promise<AdviceRecord | null>;
|
|
96
|
+
/**
|
|
97
|
+
* 写一份建议(原子写:先写临时文件再 rename,断电不会留下半个 JSON)。
|
|
98
|
+
*
|
|
99
|
+
* 旧版本进 history:重新生成不该让人丢掉上一版 —— 优化建议这种东西,
|
|
100
|
+
* 上一版往往才是你正在执行的那一版。
|
|
101
|
+
*/
|
|
102
|
+
/** 存一份**成功**的建议。失败请走 `recordAdviceError`,不要用空正文覆盖。 */
|
|
103
|
+
export declare function writeAdvice(record: AdviceRecord): Promise<AdviceRecord>;
|
|
104
|
+
/** 指纹的输入:只放"变了就该重新生成"的数字。 */
|
|
105
|
+
export interface AdviceFingerprintInput {
|
|
106
|
+
readonly cycle: string;
|
|
107
|
+
readonly account_id: string | null;
|
|
108
|
+
readonly total: number;
|
|
109
|
+
readonly elapsed_days: number;
|
|
110
|
+
readonly last_stat_date: string | null;
|
|
111
|
+
readonly services: readonly {
|
|
112
|
+
code: string;
|
|
113
|
+
amount: number;
|
|
114
|
+
}[];
|
|
115
|
+
readonly budget_status: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 算数据指纹。
|
|
119
|
+
*
|
|
120
|
+
* 放进去的是"如果它变了,结论就可能变"的东西:总额、已过天数、数据截止日、
|
|
121
|
+
* 前几名服务与金额、预算状态。不放时间戳、不放 data_as_of —— 否则每次取数
|
|
122
|
+
* 都变成"已过期",那条提醒就没人信了。
|
|
123
|
+
*/
|
|
124
|
+
export declare function fingerprintOf(input: AdviceFingerprintInput): string;
|
|
125
|
+
//# sourceMappingURL=advice.d.ts.map
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 费用域的聚合与编排:凭据 → BSS → 缓存 → 视图对象。
|
|
3
|
+
*
|
|
4
|
+
* 这里是"口径"落地的地方。三条规矩:
|
|
5
|
+
* 1. 成本 / 账单 / 账户三族**各自独立**,任何 total 都只在一个族内相加;
|
|
6
|
+
* 2. 推演值(预测)必须带 `forecast: true`,不能伪装成账单事实;
|
|
7
|
+
* 3. 每条结果都带 `data_as_of`,让页面能说清"这个数是几点的"。
|
|
8
|
+
*
|
|
9
|
+
* @module @huaweidevtools/landingzone-workbench/cost/aggregate
|
|
10
|
+
*/
|
|
11
|
+
import { type BssContext } from './bss.ts';
|
|
12
|
+
import { type AccountBalanceView, type CostByAccount, type CostByService, type YearOverview, type PeriodOverview, type CostCapability, type CostCapabilityKey, type CostMeta, type CostOverview, type CostRow, type CostTrend, type MonthlySumView, type TrendGranularity } from './types.ts';
|
|
13
|
+
/** 各粒度的默认点数(与看板一致)。 */
|
|
14
|
+
export declare const DEFAULT_POINTS: Readonly<Record<TrendGranularity, number>>;
|
|
15
|
+
/** 低于这个天数就不做月底推演(两天数据推一个月是噪声,不是预测)。 */
|
|
16
|
+
export declare const MIN_FORECAST_DAYS = 3;
|
|
17
|
+
/** 一次取数的结果:带数据截止时间与来源。 */
|
|
18
|
+
export interface Fetched<T> {
|
|
19
|
+
readonly rows: readonly T[];
|
|
20
|
+
readonly dataAsOf: string;
|
|
21
|
+
readonly source: 'live' | 'cache';
|
|
22
|
+
readonly capability?: CostCapability;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 丢掉凭据库句柄缓存(刷新按钮 / 凭据变更后调)。
|
|
26
|
+
*
|
|
27
|
+
* 注意这里缓存的是**句柄**而不是凭据值(见 credentials.ts):值每次现读,
|
|
28
|
+
* 所以换账号不会出现"页面作用域已换、取数还在用旧 AK"的串号窗口。
|
|
29
|
+
*/
|
|
30
|
+
export declare function forgetCredentials(): void;
|
|
31
|
+
/** 拿一个可用的 BSS 上下文;没有凭据时返回能力状态。 */
|
|
32
|
+
export declare function resolveBssContext(): Promise<{
|
|
33
|
+
ok: true;
|
|
34
|
+
ctx: BssContext;
|
|
35
|
+
} | {
|
|
36
|
+
ok: false;
|
|
37
|
+
capability: CostCapability;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* 取某个月的日粒度成本(优先缓存)。
|
|
41
|
+
*
|
|
42
|
+
* @param cycle 账期 YYYY-MM。
|
|
43
|
+
* @param force 忽略缓存强制重拉。
|
|
44
|
+
*/
|
|
45
|
+
export declare function getDailyRows(cycle: string, force?: boolean, accountId?: string): Promise<Fetched<CostRow>>;
|
|
46
|
+
/**
|
|
47
|
+
* 探测六个接口当前能不能用。
|
|
48
|
+
*
|
|
49
|
+
* 权限类错误会被翻译成 `permission` + 缺失的权限码,页面据此提示而不是报红。
|
|
50
|
+
* 结果缓存 10 分钟,避免每开一次页面就打 6 个请求。
|
|
51
|
+
*/
|
|
52
|
+
export declare function getCapabilities(force?: boolean): Promise<Record<CostCapabilityKey, CostCapability>>;
|
|
53
|
+
/** 丢掉能力缓存(强制刷新或凭据变更后调)。 */
|
|
54
|
+
export declare function forgetCapabilities(): void;
|
|
55
|
+
/** 汇总 /api/wb/cost/meta 的载荷。 */
|
|
56
|
+
export declare function getMeta(force?: boolean): Promise<CostMeta>;
|
|
57
|
+
/** 计算总览 KPI。 */
|
|
58
|
+
export declare function computeOverview(cycle: string, force?: boolean, accountId?: string): Promise<{
|
|
59
|
+
overview: CostOverview | null;
|
|
60
|
+
dataAsOf: string;
|
|
61
|
+
source: 'live' | 'cache';
|
|
62
|
+
capability?: CostCapability;
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* 计算趋势。
|
|
66
|
+
*
|
|
67
|
+
* month 粒度:末尾对当月补一个 `forecast: true` 的点(用当月日均 × 天数),
|
|
68
|
+
* 这与看板的行为一致;day/week 全部是实际值,不造预测点。
|
|
69
|
+
*/
|
|
70
|
+
/**
|
|
71
|
+
* 年视图的 KPI 数字。
|
|
72
|
+
*
|
|
73
|
+
* 走的还是日粒度事实(与月视图同源):这样"本年累计"与"某月累计"能对上账,
|
|
74
|
+
* 不会因为月粒度接口的分别取整而差几分钱。
|
|
75
|
+
*/
|
|
76
|
+
export declare function computeYearOverview(year: number, accountId?: string, options?: {
|
|
77
|
+
/**
|
|
78
|
+
* 是否连去年一起取(只服务「同比」)。
|
|
79
|
+
*
|
|
80
|
+
* 预算只要「本年累计 + 年末推算」,不需要同比 —— 传 false 可以省掉去年 8 个月的
|
|
81
|
+
* ListCosts(19 次 → 11 次)。KPI 的同比仍然传 true。
|
|
82
|
+
*/
|
|
83
|
+
readonly includePrevYear?: boolean;
|
|
84
|
+
}): Promise<{
|
|
85
|
+
view: YearOverview | null;
|
|
86
|
+
dataAsOf: string;
|
|
87
|
+
source: 'live' | 'cache';
|
|
88
|
+
capability?: CostCapability;
|
|
89
|
+
}>;
|
|
90
|
+
/**
|
|
91
|
+
* 日 / 周粒度的 KPI。
|
|
92
|
+
*
|
|
93
|
+
* 锚点用"所选账期里最后有数据的一天",不是日历上的今天:成本数据天然滞后一两天,
|
|
94
|
+
* 按今天切会得到一个空窗口,那不是数据有问题,是选错了窗口。
|
|
95
|
+
*/
|
|
96
|
+
export declare function computePeriodOverview(granularity: 'day' | 'week', cycle: string, accountId?: string): Promise<{
|
|
97
|
+
view: PeriodOverview | null;
|
|
98
|
+
dataAsOf: string;
|
|
99
|
+
source: 'live' | 'cache';
|
|
100
|
+
capability?: CostCapability;
|
|
101
|
+
}>;
|
|
102
|
+
export declare function computeTrend(granularity: TrendGranularity, points?: number, accountId?: string): Promise<{
|
|
103
|
+
trend: CostTrend | null;
|
|
104
|
+
dataAsOf: string;
|
|
105
|
+
source: 'live' | 'cache';
|
|
106
|
+
capability?: CostCapability;
|
|
107
|
+
}>;
|
|
108
|
+
/** 服务构成的统计窗口:跟随趋势图的日/周/月。 */
|
|
109
|
+
export interface ByServiceOptions {
|
|
110
|
+
/** 取前几名,1~10。 */
|
|
111
|
+
readonly topN?: number | undefined;
|
|
112
|
+
/** month = 整月;day = 最近有数据的一天;week = 那一档所在的 ISO 周。 */
|
|
113
|
+
readonly granularity?: TrendGranularity | undefined;
|
|
114
|
+
readonly force?: boolean | undefined;
|
|
115
|
+
readonly accountId?: string | undefined;
|
|
116
|
+
}
|
|
117
|
+
/** 服务构成(成本口径)。 */
|
|
118
|
+
export declare function computeByService(cycle: string, options?: ByServiceOptions): Promise<{
|
|
119
|
+
byService: CostByService | null;
|
|
120
|
+
dataAsOf: string;
|
|
121
|
+
source: 'live' | 'cache';
|
|
122
|
+
capability?: CostCapability;
|
|
123
|
+
}>;
|
|
124
|
+
/**
|
|
125
|
+
* 按账号分摊(2026-11-23 用户定稿:不再有 OU 维度)。
|
|
126
|
+
*
|
|
127
|
+
* 只回答"钱是哪个账号花的"。窗口跟随趋势粒度(day/week/month/year),
|
|
128
|
+
* 与"服务构成"共用同一套取数,保证同一屏只有一个时间口径。
|
|
129
|
+
*/
|
|
130
|
+
/** 分摊的取数选项。 */
|
|
131
|
+
export interface ByAccountOptions {
|
|
132
|
+
/** day = 最近一天;week = 最近一周;month = 账期全月;year = 全年至今。 */
|
|
133
|
+
readonly granularity?: TrendGranularity | undefined;
|
|
134
|
+
readonly force?: boolean | undefined;
|
|
135
|
+
readonly accountId?: string | undefined;
|
|
136
|
+
}
|
|
137
|
+
export declare function computeByAccount(cycle: string, options?: ByAccountOptions): Promise<{
|
|
138
|
+
byAccount: CostByAccount | null;
|
|
139
|
+
dataAsOf: string;
|
|
140
|
+
source: 'live' | 'cache';
|
|
141
|
+
capability?: CostCapability;
|
|
142
|
+
}>;
|
|
143
|
+
/** 账户余额(账户口径)。 */
|
|
144
|
+
export declare function computeBalance(assumed?: BssContext): Promise<{
|
|
145
|
+
view: AccountBalanceView | null;
|
|
146
|
+
dataAsOf: string;
|
|
147
|
+
source: 'live' | 'cache';
|
|
148
|
+
capability?: CostCapability;
|
|
149
|
+
}>;
|
|
150
|
+
/** 月度汇总(账单口径)。 */
|
|
151
|
+
export declare function computeMonthlySum(cycle: string, assumed?: BssContext): Promise<{
|
|
152
|
+
view: MonthlySumView | null;
|
|
153
|
+
dataAsOf: string;
|
|
154
|
+
source: 'live' | 'cache';
|
|
155
|
+
capability?: CostCapability;
|
|
156
|
+
}>;
|
|
157
|
+
//# sourceMappingURL=aggregate.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 用委托换临时凭据(assume)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么账单/余额必须走这条路:`monthly-sum` 与账户余额都是**主账号视角**的接口,
|
|
5
|
+
* 想按子账号看,只能拿一个"属于那个子账号的临时凭据"去调。否则要么看不到,
|
|
6
|
+
* 要么就得把主账号的数字挂在子账号名下 —— 后者是绝对不能做的事。
|
|
7
|
+
*
|
|
8
|
+
* 依赖的两件组织侧配置(缺一不可):
|
|
9
|
+
* 1. 目标子账号里存在委托(Organizations 给"组织内创建"的账号自动建
|
|
10
|
+
* `OrganizationAccountAccessAgency`,信任主账号);
|
|
11
|
+
* 2. 调用方 IAM 用户被授予 `iam:tokens:assume`(身份策略,任何 *ReadOnly
|
|
12
|
+
* 系统策略都不含它)。
|
|
13
|
+
*
|
|
14
|
+
* 换到的临时凭据只在内存里缓存到过期前 5 分钟,不落盘、不打印。
|
|
15
|
+
*
|
|
16
|
+
* @module @huaweidevtools/landingzone-workbench/cost/assume
|
|
17
|
+
*/
|
|
18
|
+
import type { BssContext } from './bss.ts';
|
|
19
|
+
import type { CostCapability } from './types.ts';
|
|
20
|
+
/** 失败态(ok:false 的那半边);用它做返回类型,调用方拿 .message 不用再窄化。 */
|
|
21
|
+
type CapabilityFailure = Extract<CostCapability, {
|
|
22
|
+
readonly ok: false;
|
|
23
|
+
}>;
|
|
24
|
+
/** Organizations 为"组织内创建"的账号自动创建的委托名(可用环境变量覆盖)。 */
|
|
25
|
+
export declare function agencyName(): string;
|
|
26
|
+
/** 清缓存(刷新按钮/凭据变更时用)。 */
|
|
27
|
+
export declare function forgetAssumed(domainId?: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* 换取目标子账号的临时凭据。
|
|
30
|
+
*
|
|
31
|
+
* @param ctx 调用方(主账号)凭据上下文。
|
|
32
|
+
* @param domainId 目标子账号的 domainId。
|
|
33
|
+
* @param agency 委托名,缺省取 `agencyName()`。
|
|
34
|
+
*/
|
|
35
|
+
export declare function assumeInto(ctx: BssContext, domainId: string, agency?: string): Promise<{
|
|
36
|
+
readonly ok: true;
|
|
37
|
+
readonly ctx: BssContext;
|
|
38
|
+
} | {
|
|
39
|
+
readonly ok: false;
|
|
40
|
+
readonly capability: CapabilityFailure;
|
|
41
|
+
}>;
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=assume.d.ts.map
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BSS(费用中心 / 账单 / 余额)的最小 REST 客户端。
|
|
3
|
+
*
|
|
4
|
+
* 为什么不走 `aishell-dsh-ops-deploy` 的 `openapi_request` 工具:那条路要经过
|
|
5
|
+
* 工具呈现与审批管线,每刷一次图表都要过一次;而它内部的实现其实也是
|
|
6
|
+
* "读凭据库 → 官方签名 → fetch",所以这里直接照同一套做,得到确定性。
|
|
7
|
+
*
|
|
8
|
+
* 路径与 query 词表全部取自官方 SDK(huaweicloudsdkbss/v2/bss_client.py),
|
|
9
|
+
* 不是猜的 —— `partner-bills` 那条 401 `domain_id has no access` 就是凭这个查清的。
|
|
10
|
+
*
|
|
11
|
+
* @module @huaweidevtools/landingzone-workbench/cost/bss
|
|
12
|
+
*/
|
|
13
|
+
import type { HuaweiPair, SignFn } from './credentials.ts';
|
|
14
|
+
import type { CostCapability } from './types.ts';
|
|
15
|
+
/** 费用中心(成本、账单、余额)都走这个域名。 */
|
|
16
|
+
export declare const BSS_HOST = "bss.myhuaweicloud.com";
|
|
17
|
+
/** 各接口的路径(与 SDK 一致)。 */
|
|
18
|
+
export declare const BSS_PATHS: {
|
|
19
|
+
/** ListCosts:成本分析。POST + body。 */
|
|
20
|
+
readonly costs: "/v4/costs/cost-analysed-bills/query";
|
|
21
|
+
/** ShowCustomerAccountBalances:账户余额。 */
|
|
22
|
+
readonly balance: "/v2/accounts/customer-accounts/balances";
|
|
23
|
+
/** ShowCustomerMonthlySum:主账号月度汇总。 */
|
|
24
|
+
readonly monthlySum: "/v2/bills/customer-bills/monthly-sum";
|
|
25
|
+
/** ListSubcustomerMonthlyBills:伙伴/子客户月度账单(普通企业账号 401)。 */
|
|
26
|
+
readonly subCustomerBills: "/v2/bills/partner-bills/subcustomer-bills/monthly-sum";
|
|
27
|
+
/** ListEnterpriseSubCustomers:企业子客户。 */
|
|
28
|
+
readonly subCustomers: "/v2/enterprises/multi-accounts/sub-customers";
|
|
29
|
+
/** ListEnterpriseOrganizations:企业组织。 */
|
|
30
|
+
readonly organizations: "/v2/enterprises/multi-accounts/enterprise-organizations";
|
|
31
|
+
};
|
|
32
|
+
/** 单页上限(ListCosts 按"分组"分页,不是按行)。 */
|
|
33
|
+
export declare const PAGE_SIZE = 1000;
|
|
34
|
+
/** 一次调用的结果。失败时带一个可直接展示的能力状态,而不是抛异常。 */
|
|
35
|
+
export type BssOutcome<T> = {
|
|
36
|
+
readonly ok: true;
|
|
37
|
+
readonly data: T;
|
|
38
|
+
readonly ms: number;
|
|
39
|
+
} | {
|
|
40
|
+
readonly ok: false;
|
|
41
|
+
readonly capability: CostCapability;
|
|
42
|
+
readonly ms: number;
|
|
43
|
+
};
|
|
44
|
+
/** 调用上下文。 */
|
|
45
|
+
export interface BssContext {
|
|
46
|
+
readonly pair: HuaweiPair;
|
|
47
|
+
readonly sign: SignFn;
|
|
48
|
+
}
|
|
49
|
+
/** 华为云的错误体(只取我们用得到的字段)。 */
|
|
50
|
+
interface BssErrorBody {
|
|
51
|
+
readonly error_code?: string;
|
|
52
|
+
readonly error_msg?: string;
|
|
53
|
+
readonly message?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 把一次非 2xx 响应翻译成能力状态。
|
|
57
|
+
*
|
|
58
|
+
* 401 有两种完全不同的含义,必须分开:签名错(要改凭据)与账号类型不够
|
|
59
|
+
* (改凭据也没用)。这是 P0 实测出来的区别,不是推测。
|
|
60
|
+
*/
|
|
61
|
+
export declare function classifyHttpError(status: number, body: BssErrorBody | undefined, rawText: string): CostCapability;
|
|
62
|
+
/**
|
|
63
|
+
* 发一个签名过的 BSS 请求。
|
|
64
|
+
*
|
|
65
|
+
* @param ctx 凭据与签名器。
|
|
66
|
+
* @param method HTTP 方法。
|
|
67
|
+
* @param path 路径(不带 query)。
|
|
68
|
+
* @param query query 参数(会参与签名)。
|
|
69
|
+
* @param payload JSON body;GET 传 undefined。
|
|
70
|
+
* @param host 目标 host;默认费用中心,组织/资源类接口传自己的 host。
|
|
71
|
+
*/
|
|
72
|
+
export declare function bssCall<T>(ctx: BssContext, method: 'GET' | 'POST', path: string, query: Record<string, string>, payload?: unknown, host?: string): Promise<BssOutcome<T>>;
|
|
73
|
+
/** ListCosts 请求体。 */
|
|
74
|
+
export interface ListCostsParams {
|
|
75
|
+
readonly begin: string;
|
|
76
|
+
readonly end: string;
|
|
77
|
+
/** 1 = 日,2 = 月。 */
|
|
78
|
+
readonly timeMeasureId?: 1 | 2;
|
|
79
|
+
readonly groupby?: readonly {
|
|
80
|
+
type: string;
|
|
81
|
+
key: string;
|
|
82
|
+
}[];
|
|
83
|
+
readonly costType?: string;
|
|
84
|
+
readonly amountType?: string;
|
|
85
|
+
/**
|
|
86
|
+
* 只看这些关联账号(ASSOCIATED_ACCOUNT 维度)。
|
|
87
|
+
*
|
|
88
|
+
* 形状必须是 `{operator, filter_factor:{key,value[]}}` —— 按 SDK 的 FilterV2/FilterFactor
|
|
89
|
+
* 来。写成 `{key,value,operator:'equal'}` 服务端会直接 400 `Parameter is not valid`。
|
|
90
|
+
*/
|
|
91
|
+
readonly accountIds?: readonly string[];
|
|
92
|
+
}
|
|
93
|
+
/** ListCosts 原始响应。 */
|
|
94
|
+
export interface ListCostsResponse {
|
|
95
|
+
readonly currency?: string;
|
|
96
|
+
readonly total_count?: number;
|
|
97
|
+
readonly cost_data?: readonly {
|
|
98
|
+
readonly dimensions?: readonly {
|
|
99
|
+
key?: string;
|
|
100
|
+
value?: string;
|
|
101
|
+
}[];
|
|
102
|
+
readonly costs?: readonly {
|
|
103
|
+
readonly time_dimension_value?: string;
|
|
104
|
+
readonly time_measure_id?: number;
|
|
105
|
+
readonly amount?: string;
|
|
106
|
+
readonly official_amount?: string;
|
|
107
|
+
}[];
|
|
108
|
+
}[];
|
|
109
|
+
}
|
|
110
|
+
/** 翻完所有页,返回合并后的原始分组。 */
|
|
111
|
+
export declare function listCostsAll(ctx: BssContext, params: ListCostsParams): Promise<BssOutcome<{
|
|
112
|
+
currency: string;
|
|
113
|
+
groups: NonNullable<ListCostsResponse['cost_data']>;
|
|
114
|
+
}>>;
|
|
115
|
+
/** 账户余额原始响应(字段名来自实测:account_balances / debt_amount / measure_id / currency)。 */
|
|
116
|
+
export interface BalanceResponse {
|
|
117
|
+
readonly currency?: string;
|
|
118
|
+
readonly measure_id?: number;
|
|
119
|
+
readonly debt_amount?: string | number;
|
|
120
|
+
readonly account_balances?: readonly {
|
|
121
|
+
readonly amount?: string;
|
|
122
|
+
readonly designited_amount?: string;
|
|
123
|
+
}[];
|
|
124
|
+
}
|
|
125
|
+
/** 主账号月度汇总原始响应。 */
|
|
126
|
+
export interface MonthlySumResponse {
|
|
127
|
+
readonly currency?: string;
|
|
128
|
+
readonly total_count?: number;
|
|
129
|
+
readonly consume_amount?: string | number;
|
|
130
|
+
readonly cash_amount?: string | number;
|
|
131
|
+
readonly debt_amount?: string | number;
|
|
132
|
+
readonly coupon_amount?: string | number;
|
|
133
|
+
readonly bill_sums?: readonly {
|
|
134
|
+
readonly service_type_code?: string;
|
|
135
|
+
readonly resource_type_code?: string;
|
|
136
|
+
readonly charging_mode?: number;
|
|
137
|
+
readonly consume_amount?: string | number;
|
|
138
|
+
readonly cash_amount?: string | number;
|
|
139
|
+
readonly coupon_amount?: string | number;
|
|
140
|
+
readonly debt_amount?: string | number;
|
|
141
|
+
}[];
|
|
142
|
+
}
|
|
143
|
+
/** 查询账户余额。 */
|
|
144
|
+
export declare function fetchBalance(ctx: BssContext): Promise<BssOutcome<BalanceResponse>>;
|
|
145
|
+
/** 查询主账号月度汇总。 */
|
|
146
|
+
/**
|
|
147
|
+
* 月度汇总(账单口径)——**翻完所有页**。
|
|
148
|
+
*
|
|
149
|
+
* 这个接口的 bill_sums 粒度是「账号 × 资源类型 × 计费模式」,一个月的行数轻松过百
|
|
150
|
+
* (实测 2026-10 是 268 行)。只取第一页会漏掉排在后面的行,其中还包括退款/降配的
|
|
151
|
+
* 负数行 —— 于是"各行之和"反而大于接口给的消费金额。所以必须翻页取全再聚合。
|
|
152
|
+
*/
|
|
153
|
+
export declare function fetchMonthlySum(ctx: BssContext, cycle: string): Promise<BssOutcome<MonthlySumResponse>>;
|
|
154
|
+
/** 企业子客户列表(需要 bss:enterpriseOrganization:view)。 */
|
|
155
|
+
export declare function fetchSubCustomers(ctx: BssContext, limit?: number): Promise<BssOutcome<unknown>>;
|
|
156
|
+
/**
|
|
157
|
+
* 企业组织(需要 bss:enterpriseOrganization:view)。
|
|
158
|
+
*
|
|
159
|
+
* 不传参数:SDK 里的 `recursive_query` 被服务端判定为非法参数(P0 实测 400),
|
|
160
|
+
* 真实合法参数要等权限到位后才能确认,届时再补。
|
|
161
|
+
*/
|
|
162
|
+
export declare function fetchOrganizations(ctx: BssContext): Promise<BssOutcome<unknown>>;
|
|
163
|
+
/** 伙伴/子客户月度账单(普通企业账号恒为 401,保留接口是为了能力探测能如实报告)。 */
|
|
164
|
+
export declare function fetchSubCustomerBills(ctx: BssContext, cycle: string): Promise<BssOutcome<unknown>>;
|
|
165
|
+
export {};
|
|
166
|
+
//# sourceMappingURL=bss.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { CostCapability } from './types.ts';
|
|
2
|
+
/** 一行:一个账号在本月的预算执行状态。 */
|
|
3
|
+
export interface BudgetOverviewRow {
|
|
4
|
+
/** '*' = 主账号(全组织)视角,否则为子账号 domain_id。 */
|
|
5
|
+
readonly account_id: string;
|
|
6
|
+
/** 月预算(= 年度预算 ÷ 12,派生值)。 */
|
|
7
|
+
readonly amount: number;
|
|
8
|
+
/** 年度预算原值(前端 tooltip/对账用)。 */
|
|
9
|
+
readonly annual_amount: number;
|
|
10
|
+
readonly alert_ratio: number;
|
|
11
|
+
/** 本月已花(成本口径)。 */
|
|
12
|
+
readonly used: number;
|
|
13
|
+
/** 已用 / 月预算。 */
|
|
14
|
+
readonly ratio: number | null;
|
|
15
|
+
/** 月底推算;数据不足时为 null。 */
|
|
16
|
+
readonly forecast: number | null;
|
|
17
|
+
readonly forecast_ratio: number | null;
|
|
18
|
+
readonly status: 'ok' | 'warn' | 'over';
|
|
19
|
+
}
|
|
20
|
+
export interface BudgetOverviewResult {
|
|
21
|
+
readonly cycle: string;
|
|
22
|
+
readonly rows: readonly BudgetOverviewRow[];
|
|
23
|
+
/** 各账号数据截至时间的最大值。 */
|
|
24
|
+
readonly dataAsOf: string | null;
|
|
25
|
+
/** 本月时间进度(0~1)——前端画"时间进度"参考线。 */
|
|
26
|
+
readonly elapsedRatio: number;
|
|
27
|
+
readonly capability?: CostCapability;
|
|
28
|
+
}
|
|
29
|
+
/** 本月时间进度:当天(含)÷ 当月天数。本地时区——与账期(本地月)同一口径。 */
|
|
30
|
+
export declare function monthElapsedRatio(now?: Date): number;
|
|
31
|
+
/**
|
|
32
|
+
* 批量计算"本月哪些账号预算不够"。
|
|
33
|
+
*
|
|
34
|
+
* @param cycle 当前月账期("2026-11")。年度预算键取 cycle 前 4 位。
|
|
35
|
+
* @param force 绕过 6 小时盘缓存。
|
|
36
|
+
*/
|
|
37
|
+
export declare function computeBudgetOverview(cycle: string, force?: boolean): Promise<BudgetOverviewResult>;
|
|
38
|
+
//# sourceMappingURL=budget-overview.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** 一个账期的预算。 */
|
|
2
|
+
export interface CycleBudget {
|
|
3
|
+
readonly cycle: string;
|
|
4
|
+
/** 月度预算金额(元)。 */
|
|
5
|
+
readonly amount: number;
|
|
6
|
+
/** 告警线:已用达到这个比例开始提示,默认 0.8。 */
|
|
7
|
+
readonly alert_ratio: number;
|
|
8
|
+
readonly updated_at: string;
|
|
9
|
+
}
|
|
10
|
+
/** 预算相对实际花费的状态。 */
|
|
11
|
+
export interface BudgetStatus {
|
|
12
|
+
readonly budget: CycleBudget | null;
|
|
13
|
+
/** 已花金额(成本口径)。 */
|
|
14
|
+
readonly used: number;
|
|
15
|
+
/** 已用 / 预算。 */
|
|
16
|
+
readonly ratio: number | null;
|
|
17
|
+
/** 月底推算金额(成本口径);数据不足时为 null。 */
|
|
18
|
+
readonly forecast: number | null;
|
|
19
|
+
/** 月底推算 / 预算;无推算时为 null。 */
|
|
20
|
+
readonly forecast_ratio: number | null;
|
|
21
|
+
readonly status: 'unset' | 'ok' | 'warn' | 'over';
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 读某个账期的预算。
|
|
25
|
+
* @param cycle 账期。
|
|
26
|
+
* @param accountId 账号;空表示主账号视角。
|
|
27
|
+
*/
|
|
28
|
+
export declare function getBudget(cycle: string, accountId?: string): Promise<CycleBudget | null>;
|
|
29
|
+
/**
|
|
30
|
+
* 枚举某账期的**全部**账号预算(含主账号 '*'),供"谁超了/谁快超"的批量
|
|
31
|
+
* 预算总览用。金额非法的条目直接跳过(与 getBudget 同一判定)。
|
|
32
|
+
*/
|
|
33
|
+
export declare function listBudgets(cycle: string): Promise<readonly {
|
|
34
|
+
accountId: string;
|
|
35
|
+
budget: CycleBudget;
|
|
36
|
+
}[]>;
|
|
37
|
+
/**
|
|
38
|
+
* 写某个账期的预算。
|
|
39
|
+
*
|
|
40
|
+
* @param cycle 账期 YYYY-MM。
|
|
41
|
+
* @param amount 月度预算,必须 > 0。
|
|
42
|
+
* @param alertRatio 告警线 (0,1],缺省 0.8。
|
|
43
|
+
*/
|
|
44
|
+
export declare function setBudget(cycle: string, amount: number, alertRatio?: number, accountId?: string): Promise<CycleBudget>;
|
|
45
|
+
/**
|
|
46
|
+
* 计算预算状态。
|
|
47
|
+
*
|
|
48
|
+
* @param budget 预算;null 表示未设置。
|
|
49
|
+
* @param used 已花金额。
|
|
50
|
+
* @param forecast 月底/年末推算;null 表示数据不足无法推算。
|
|
51
|
+
* @param elapsedRatio 时间进度(0~1,已过天数/周期天数)。给了就启用"超速"判定:
|
|
52
|
+
* 已花比例 > 时间进度 × 1.1 即 warn —— 每天 2 万花 1 万的预算,第 1 天就该亮黄,
|
|
53
|
+
* 而不是等到 80% 告警线(12 天后才触发、月底注定 200%)。1.1 容差防零星抖动。
|
|
54
|
+
*/
|
|
55
|
+
export declare function budgetStatus(budget: CycleBudget | null, used: number, forecast: number | null, elapsedRatio?: number): BudgetStatus;
|
|
56
|
+
//# sourceMappingURL=budget.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** 缓存有效期:6 小时。 */
|
|
2
|
+
export declare const CACHE_TTL_MS: number;
|
|
3
|
+
/** 缓存条目。 */
|
|
4
|
+
export interface CacheEntry<T> {
|
|
5
|
+
/** 事实行。 */
|
|
6
|
+
readonly rows: readonly T[];
|
|
7
|
+
/** 这批数据是什么时候从华为云拉下来的(ISO 8601)。 */
|
|
8
|
+
readonly dataAsOf: string;
|
|
9
|
+
/** 距今毫秒数。 */
|
|
10
|
+
readonly ageMs: number;
|
|
11
|
+
/** 是否已过期(过期不等于不能用,调用方决定要不要先展示再刷新)。 */
|
|
12
|
+
readonly expired: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 缓存根目录。
|
|
16
|
+
*
|
|
17
|
+
* @param space 并列的业务域(默认 `cost`;配置审计用 `config`)。
|
|
18
|
+
*
|
|
19
|
+
* 为什么要参数化:配置审计的资源清单也是"账号级持续观测",与费用同性质,
|
|
20
|
+
* 但两者的数据来源完全不同,混在一个目录里既不利于手动清理,也会让
|
|
21
|
+
* "清费用缓存"顺手把配置数据删掉。分目录、共用同一套读写逻辑。
|
|
22
|
+
*/
|
|
23
|
+
export declare function cacheRoot(space?: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* 读缓存。
|
|
26
|
+
*
|
|
27
|
+
* @param name 逻辑名(例如 `daily-2026-11`)。
|
|
28
|
+
* @param space 业务域(默认 `cost`)。
|
|
29
|
+
* @returns 条目;不存在或读坏时 undefined(当作没有缓存,重新拉)。
|
|
30
|
+
*/
|
|
31
|
+
export declare function readEntry<T>(name: string, space?: string, ttlMs?: number): Promise<CacheEntry<T> | undefined>;
|
|
32
|
+
/**
|
|
33
|
+
* 写缓存。先写临时文件再 rename,避免读到半个 JSON。
|
|
34
|
+
*
|
|
35
|
+
* 临时文件名必须**每次唯一**。第一版是 `${target}.${pid}.tmp` —— 同一个 key
|
|
36
|
+
* 的两个并发写会落成同一个临时文件:第一个 rename 把它搬走,第二个 rename
|
|
37
|
+
* 就 ENOENT("no such file or directory, rename … .tmp")。而这个并发不是
|
|
38
|
+
* 理论上的:生成建议时总览与服务构成同时取同一份日粒度数据就会撞上。
|
|
39
|
+
*
|
|
40
|
+
* @param name 逻辑名。
|
|
41
|
+
* @param rows 事实行。
|
|
42
|
+
* @param space 业务域(默认 `cost`)。
|
|
43
|
+
*/
|
|
44
|
+
export declare function writeEntry<T>(name: string, rows: readonly T[], space?: string): Promise<CacheEntry<T>>;
|
|
45
|
+
/** 丢掉进程内缓存(强制刷新用)。 */
|
|
46
|
+
export declare function forget(name: string, space?: string): void;
|
|
47
|
+
/** 丢掉全部内存缓存(可按业务域)。 */
|
|
48
|
+
export declare function forgetAll(space?: string): void;
|
|
49
|
+
/**
|
|
50
|
+
* 删掉磁盘上的缓存文件。
|
|
51
|
+
*
|
|
52
|
+
* 强制刷新必须连盘一起清:只清内存的话,`readEntry` 还能从 6 小时内的文件
|
|
53
|
+
* 读回来,用户按了"刷新"看到的还是旧数 —— 这种"按了没反应"比报错更糟。
|
|
54
|
+
*
|
|
55
|
+
* 顺手清 `.tmp`:写入中途失败留下的临时文件没人会再用,留着只是垃圾。
|
|
56
|
+
*/
|
|
57
|
+
export declare function clearCacheFiles(space?: string): Promise<number>;
|
|
58
|
+
//# sourceMappingURL=cache.d.ts.map
|