@harrylabsj/kiwi 0.12.14 → 0.12.16

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.
Files changed (169) hide show
  1. package/dist/a2a/node.d.ts +5 -0
  2. package/dist/a2a/node.js +69 -2
  3. package/dist/a2a/node.js.map +1 -1
  4. package/dist/a2a/server/merchant-handler.d.ts +8 -0
  5. package/dist/a2a/server/merchant-handler.js +105 -14
  6. package/dist/a2a/server/merchant-handler.js.map +1 -1
  7. package/dist/a2a/server/negotiation-advisor.d.ts +54 -0
  8. package/dist/a2a/server/negotiation-advisor.js +107 -0
  9. package/dist/a2a/server/negotiation-advisor.js.map +1 -0
  10. package/dist/a2a/server/negotiation-approvals.d.ts +114 -0
  11. package/dist/a2a/server/negotiation-approvals.js +240 -0
  12. package/dist/a2a/server/negotiation-approvals.js.map +1 -0
  13. package/dist/buyer-core/a2a-knp.d.ts +14 -0
  14. package/dist/buyer-core/a2a-knp.js +24 -0
  15. package/dist/buyer-core/a2a-knp.js.map +1 -1
  16. package/dist/buyer-core/a2a-negotiator.js +66 -11
  17. package/dist/buyer-core/a2a-negotiator.js.map +1 -1
  18. package/dist/buyer-core/protocol-recovery.d.ts +1 -1
  19. package/dist/buyer-core/receive-gate.js +7 -0
  20. package/dist/buyer-core/receive-gate.js.map +1 -1
  21. package/dist/buyer-core/service.d.ts +13 -0
  22. package/dist/buyer-core/service.js +73 -10
  23. package/dist/buyer-core/service.js.map +1 -1
  24. package/dist/cli.js +247 -0
  25. package/dist/cli.js.map +1 -1
  26. package/dist/cloud/bootstrap.js +12 -0
  27. package/dist/cloud/bootstrap.js.map +1 -1
  28. package/dist/http/merchant-management/api.d.ts +3 -0
  29. package/dist/http/merchant-management/api.js +419 -0
  30. package/dist/http/merchant-management/api.js.map +1 -1
  31. package/dist/http/merchant-management/page.js +95 -1
  32. package/dist/http/merchant-management/page.js.map +1 -1
  33. package/dist/mcp/merchant-ops-server.d.ts +38 -0
  34. package/dist/mcp/merchant-ops-server.js +283 -0
  35. package/dist/mcp/merchant-ops-server.js.map +1 -0
  36. package/dist/mcp/merchant-runtime-assembly.js +28 -0
  37. package/dist/mcp/merchant-runtime-assembly.js.map +1 -1
  38. package/dist/mcp/merchant-server.d.ts +16 -0
  39. package/dist/mcp/merchant-server.js +24 -0
  40. package/dist/mcp/merchant-server.js.map +1 -1
  41. package/dist/merchant/application/actor.d.ts +1 -1
  42. package/dist/merchant/application/actor.js +43 -1
  43. package/dist/merchant/application/actor.js.map +1 -1
  44. package/dist/merchant/negotiation-observer.d.ts +35 -0
  45. package/dist/merchant/negotiation-observer.js +159 -51
  46. package/dist/merchant/negotiation-observer.js.map +1 -1
  47. package/dist/merchant/negotiation-ops.d.ts +77 -0
  48. package/dist/merchant/negotiation-ops.js +203 -0
  49. package/dist/merchant/negotiation-ops.js.map +1 -0
  50. package/dist/merchant/quote-calculator.d.ts +7 -0
  51. package/dist/merchant/quote-calculator.js +35 -24
  52. package/dist/merchant/quote-calculator.js.map +1 -1
  53. package/dist/merchant/watch/detect.d.ts +37 -0
  54. package/dist/merchant/watch/detect.js +147 -0
  55. package/dist/merchant/watch/detect.js.map +1 -0
  56. package/dist/merchant/watch/notify.d.ts +48 -0
  57. package/dist/merchant/watch/notify.js +108 -0
  58. package/dist/merchant/watch/notify.js.map +1 -0
  59. package/dist/merchant/watch/service.d.ts +43 -0
  60. package/dist/merchant/watch/service.js +167 -0
  61. package/dist/merchant/watch/service.js.map +1 -0
  62. package/dist/merchant/watch/state.d.ts +49 -0
  63. package/dist/merchant/watch/state.js +68 -0
  64. package/dist/merchant/watch/state.js.map +1 -0
  65. package/dist/merchant/watch/weixin.d.ts +54 -0
  66. package/dist/merchant/watch/weixin.js +271 -0
  67. package/dist/merchant/watch/weixin.js.map +1 -0
  68. package/dist/merchant-core/commercial/calculate.d.ts +18 -0
  69. package/dist/merchant-core/commercial/calculate.js +196 -0
  70. package/dist/merchant-core/commercial/calculate.js.map +1 -0
  71. package/dist/merchant-core/commercial/types.d.ts +91 -0
  72. package/dist/merchant-core/commercial/types.js +17 -0
  73. package/dist/merchant-core/commercial/types.js.map +1 -0
  74. package/dist/merchant-core/contribution/calculate.d.ts +24 -0
  75. package/dist/merchant-core/contribution/calculate.js +172 -0
  76. package/dist/merchant-core/contribution/calculate.js.map +1 -0
  77. package/dist/merchant-core/contribution/repository.d.ts +60 -0
  78. package/dist/merchant-core/contribution/repository.js +121 -0
  79. package/dist/merchant-core/contribution/repository.js.map +1 -0
  80. package/dist/merchant-core/contribution/types.d.ts +97 -0
  81. package/dist/merchant-core/contribution/types.js +24 -0
  82. package/dist/merchant-core/contribution/types.js.map +1 -0
  83. package/dist/merchant-core/followup/lease.d.ts +27 -0
  84. package/dist/merchant-core/followup/lease.js +45 -0
  85. package/dist/merchant-core/followup/lease.js.map +1 -0
  86. package/dist/merchant-core/followup/repository.d.ts +141 -0
  87. package/dist/merchant-core/followup/repository.js +280 -0
  88. package/dist/merchant-core/followup/repository.js.map +1 -0
  89. package/dist/merchant-core/followup/retry.d.ts +27 -0
  90. package/dist/merchant-core/followup/retry.js +61 -0
  91. package/dist/merchant-core/followup/retry.js.map +1 -0
  92. package/dist/merchant-core/followup/service.d.ts +114 -0
  93. package/dist/merchant-core/followup/service.js +191 -0
  94. package/dist/merchant-core/followup/service.js.map +1 -0
  95. package/dist/merchant-core/followup/state.d.ts +25 -0
  96. package/dist/merchant-core/followup/state.js +126 -0
  97. package/dist/merchant-core/followup/state.js.map +1 -0
  98. package/dist/merchant-core/followup/types.d.ts +75 -0
  99. package/dist/merchant-core/followup/types.js +41 -0
  100. package/dist/merchant-core/followup/types.js.map +1 -0
  101. package/dist/merchant-core/metrics/timing.d.ts +63 -0
  102. package/dist/merchant-core/metrics/timing.js +125 -0
  103. package/dist/merchant-core/metrics/timing.js.map +1 -0
  104. package/dist/merchant-core/operating/repository.d.ts +97 -0
  105. package/dist/merchant-core/operating/repository.js +266 -0
  106. package/dist/merchant-core/operating/repository.js.map +1 -0
  107. package/dist/merchant-core/operating/service.d.ts +63 -0
  108. package/dist/merchant-core/operating/service.js +336 -0
  109. package/dist/merchant-core/operating/service.js.map +1 -0
  110. package/dist/merchant-core/operating/types.d.ts +102 -0
  111. package/dist/merchant-core/operating/types.js +24 -0
  112. package/dist/merchant-core/operating/types.js.map +1 -0
  113. package/dist/merchant-core/opportunity/repository.d.ts +128 -0
  114. package/dist/merchant-core/opportunity/repository.js +251 -0
  115. package/dist/merchant-core/opportunity/repository.js.map +1 -0
  116. package/dist/merchant-core/opportunity/service.d.ts +117 -0
  117. package/dist/merchant-core/opportunity/service.js +388 -0
  118. package/dist/merchant-core/opportunity/service.js.map +1 -0
  119. package/dist/merchant-core/opportunity/state.d.ts +33 -0
  120. package/dist/merchant-core/opportunity/state.js +166 -0
  121. package/dist/merchant-core/opportunity/state.js.map +1 -0
  122. package/dist/merchant-core/opportunity/types.d.ts +141 -0
  123. package/dist/merchant-core/opportunity/types.js +42 -0
  124. package/dist/merchant-core/opportunity/types.js.map +1 -0
  125. package/dist/merchant-core/ops/facade.d.ts +159 -0
  126. package/dist/merchant-core/ops/facade.js +213 -0
  127. package/dist/merchant-core/ops/facade.js.map +1 -0
  128. package/dist/merchant-core/ops/schema.d.ts +25 -0
  129. package/dist/merchant-core/ops/schema.js +448 -0
  130. package/dist/merchant-core/ops/schema.js.map +1 -0
  131. package/dist/merchant-core/ops/surface.d.ts +49 -0
  132. package/dist/merchant-core/ops/surface.js +304 -0
  133. package/dist/merchant-core/ops/surface.js.map +1 -0
  134. package/dist/merchant-core/orders/csv.d.ts +36 -0
  135. package/dist/merchant-core/orders/csv.js +173 -0
  136. package/dist/merchant-core/orders/csv.js.map +1 -0
  137. package/dist/merchant-core/orders/model.d.ts +155 -0
  138. package/dist/merchant-core/orders/model.js +237 -0
  139. package/dist/merchant-core/orders/model.js.map +1 -0
  140. package/dist/merchant-core/orders/repository.d.ts +99 -0
  141. package/dist/merchant-core/orders/repository.js +221 -0
  142. package/dist/merchant-core/orders/repository.js.map +1 -0
  143. package/dist/merchant-core/orders/service.d.ts +84 -0
  144. package/dist/merchant-core/orders/service.js +121 -0
  145. package/dist/merchant-core/orders/service.js.map +1 -0
  146. package/dist/merchant-core/orders/shopping-cli-source.d.ts +58 -0
  147. package/dist/merchant-core/orders/shopping-cli-source.js +164 -0
  148. package/dist/merchant-core/orders/shopping-cli-source.js.map +1 -0
  149. package/dist/merchant-core/proposal/engine.d.ts +31 -0
  150. package/dist/merchant-core/proposal/engine.js +348 -0
  151. package/dist/merchant-core/proposal/engine.js.map +1 -0
  152. package/dist/merchant-core/proposal/publish.d.ts +46 -0
  153. package/dist/merchant-core/proposal/publish.js +79 -0
  154. package/dist/merchant-core/proposal/publish.js.map +1 -0
  155. package/dist/merchant-core/proposal/repository.d.ts +60 -0
  156. package/dist/merchant-core/proposal/repository.js +186 -0
  157. package/dist/merchant-core/proposal/repository.js.map +1 -0
  158. package/dist/merchant-core/proposal/service.d.ts +73 -0
  159. package/dist/merchant-core/proposal/service.js +149 -0
  160. package/dist/merchant-core/proposal/service.js.map +1 -0
  161. package/dist/merchant-core/proposal/types.d.ts +163 -0
  162. package/dist/merchant-core/proposal/types.js +25 -0
  163. package/dist/merchant-core/proposal/types.js.map +1 -0
  164. package/dist/merchant-runtime/services.d.ts +0 -8
  165. package/dist/merchant-runtime/services.js +38 -0
  166. package/dist/merchant-runtime/services.js.map +1 -1
  167. package/dist/product-cli.js +5 -0
  168. package/dist/product-cli.js.map +1 -1
  169. package/package.json +1 -1
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Copyright 2026 harrylabsj
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * 销售机会、来源记录与需求快照(v0.2 §6 / FR05–FR07、FR12)。
18
+ *
19
+ * 关键边界:
20
+ * - 来源记录(一次外部询盘)与采购机会(一次采购意图)分开计数;
21
+ * - 同一外部事件重复进入必须幂等;相似文本只提示重复,不自动合并;
22
+ * - 机会状态是业务投影,不反向修改 RFQ/KNP/订单状态;
23
+ * - 需求字段的“客户已确认/模型提取/未知”分别保存,不把推测当确认。
24
+ */
25
+ export declare const OPPORTUNITY_STATUSES: readonly ["NEW", "NEEDS_INFO", "READY_FOR_PROPOSAL", "PENDING_APPROVAL", "WAITING_CUSTOMER", "RESULT_UNVERIFIED", "CLOSED"];
26
+ export type OpportunityStatus = (typeof OPPORTUNITY_STATUSES)[number];
27
+ export type RequirementFieldStatus = "CONFIRMED" | "UNCONFIRMED" | "UNKNOWN";
28
+ export interface RequirementField {
29
+ field: string;
30
+ value: string | number | boolean | null;
31
+ status: RequirementFieldStatus;
32
+ /** 字段来源(manual、model、channel 等);CONFIRMED 时必须有确认者。 */
33
+ source?: string;
34
+ confirmed_by?: string;
35
+ confirmed_at?: string;
36
+ }
37
+ export interface RequirementSnapshot {
38
+ opportunity_id: string;
39
+ revision: number;
40
+ fields: RequirementField[];
41
+ created_at: string;
42
+ created_by: string;
43
+ }
44
+ export interface OpportunitySource {
45
+ source_id: string;
46
+ merchant_id: string;
47
+ source_namespace: string;
48
+ source_account_id: string;
49
+ external_inquiry_id: string;
50
+ raw_excerpt: string;
51
+ received_at: string;
52
+ operator: string;
53
+ parse_version: string;
54
+ revision: number;
55
+ created_at: string;
56
+ updated_at: string;
57
+ }
58
+ export interface OpportunitySourceEvent {
59
+ event_id: string;
60
+ source_id: string;
61
+ external_event_id: string;
62
+ event_kind: string;
63
+ payload_digest: string;
64
+ received_at: string;
65
+ created_at: string;
66
+ }
67
+ export interface SalesOpportunity {
68
+ opportunity_id: string;
69
+ merchant_id: string;
70
+ status: OpportunityStatus;
71
+ owner: string;
72
+ next_action: string | null;
73
+ next_action_due_at: string | null;
74
+ waiting_reason: string | null;
75
+ rfq_case_id: string | null;
76
+ revision: number;
77
+ created_at: string;
78
+ updated_at: string;
79
+ }
80
+ export interface OpportunityLink {
81
+ link_id: string;
82
+ merchant_id: string;
83
+ opportunity_id: string;
84
+ source_id: string;
85
+ status: "LINKED" | "UNLINKED";
86
+ basis: string;
87
+ confirmed_by: string;
88
+ confirmed_at: string;
89
+ revision: number;
90
+ created_at: string;
91
+ updated_at: string;
92
+ }
93
+ export type OpportunityEvent = {
94
+ type: "INGEST";
95
+ complete: boolean;
96
+ } | {
97
+ type: "REQUIREMENT_UPDATED";
98
+ complete: boolean;
99
+ } | {
100
+ type: "SUBMIT_FOR_APPROVAL";
101
+ } | {
102
+ type: "APPROVAL_REJECTED";
103
+ needs_info: boolean;
104
+ } | {
105
+ type: "APPROVAL_GRANTED_AND_SENT";
106
+ } | {
107
+ type: "WAIT_CUSTOMER";
108
+ reason: string;
109
+ } | {
110
+ type: "CUSTOMER_REPLIED";
111
+ needs_info: boolean;
112
+ needs_new_proposal: boolean;
113
+ } | {
114
+ type: "ORDER_CLAIMED";
115
+ } | {
116
+ type: "ORDER_VERIFIED";
117
+ has_open_sales_todo: boolean;
118
+ } | {
119
+ type: "ORDER_NOT_CONFIRMED";
120
+ /** 候选不成立时回到的先前工作状态(已结束/待核实以外的非新建状态)。 */
121
+ resume_status: Exclude<OpportunityStatus, "NEW" | "RESULT_UNVERIFIED" | "CLOSED">;
122
+ } | {
123
+ type: "FACTS_CHANGED";
124
+ needs_info: boolean;
125
+ proposal_stale: boolean;
126
+ } | {
127
+ type: "CLOSE";
128
+ reason: string;
129
+ };
130
+ export interface OpportunityTransition {
131
+ from: OpportunityStatus;
132
+ event: OpportunityEvent["type"];
133
+ to: OpportunityStatus;
134
+ /** 迁移的副作用(取消任务、建立核实任务等),由调用方执行。 */
135
+ side_effects: string[];
136
+ }
137
+ export type OpportunityErrorCode = "validation" | "not_found" | "version_conflict" | "invalid_transition" | "source_conflict" | "idempotency_conflict";
138
+ export declare class OpportunityError extends Error {
139
+ readonly code: OpportunityErrorCode;
140
+ constructor(code: OpportunityErrorCode, message: string);
141
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Copyright 2026 harrylabsj
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * 销售机会、来源记录与需求快照(v0.2 §6 / FR05–FR07、FR12)。
18
+ *
19
+ * 关键边界:
20
+ * - 来源记录(一次外部询盘)与采购机会(一次采购意图)分开计数;
21
+ * - 同一外部事件重复进入必须幂等;相似文本只提示重复,不自动合并;
22
+ * - 机会状态是业务投影,不反向修改 RFQ/KNP/订单状态;
23
+ * - 需求字段的“客户已确认/模型提取/未知”分别保存,不把推测当确认。
24
+ */
25
+ export const OPPORTUNITY_STATUSES = [
26
+ "NEW",
27
+ "NEEDS_INFO",
28
+ "READY_FOR_PROPOSAL",
29
+ "PENDING_APPROVAL",
30
+ "WAITING_CUSTOMER",
31
+ "RESULT_UNVERIFIED",
32
+ "CLOSED",
33
+ ];
34
+ export class OpportunityError extends Error {
35
+ code;
36
+ constructor(code, message) {
37
+ super(message);
38
+ this.name = "OpportunityError";
39
+ this.code = code;
40
+ }
41
+ }
42
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/merchant-core/opportunity/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,KAAK;IACL,YAAY;IACZ,oBAAoB;IACpB,kBAAkB;IAClB,kBAAkB;IAClB,mBAAmB;IACnB,QAAQ;CACA,CAAC;AA8GX,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAChC,IAAI,CAAuB;IACpC,YAAY,IAA0B,EAAE,OAAe;QACrD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Copyright 2026 harrylabsj
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * 商家经营门面(v0.2 §15.1 / §17)。
18
+ *
19
+ * 把经营计划与机会服务装配到同一 `state.sqlite`,并由构造时的认证主体
20
+ * 注入 `merchant_id`——调用方(HTTP/MCP/CLI)不传商家身份,避免信任工具
21
+ * 参数。后续方案/跟进/订单持久化也接到这个门面,保持一个写入口。
22
+ */
23
+ import type { DatabaseSync } from "node:sqlite";
24
+ import { MerchantOperatingPlanService, type CommandOptions } from "../operating/service.js";
25
+ import type { OperatingPlan, OperatingPlanInput, OperatingPlanReadiness, PlanReadinessInput, SwitchPlanVersionInput, UpdateOperatingPlanInput } from "../operating/types.js";
26
+ import { OpportunityService, type CreateOpportunityInput, type IngestSourceInput, type RecordRequirementInput } from "../opportunity/service.js";
27
+ import type { OpportunityEvent, OpportunityStatus, SalesOpportunity } from "../opportunity/types.js";
28
+ import { ProposalService, type SelectProposalInput } from "../proposal/service.js";
29
+ import type { ApprovalBinding, PrepareProposalSetInput, ProposalSet, SelectionRecord } from "../proposal/types.js";
30
+ import { type FollowUpTask } from "../followup/repository.js";
31
+ import { FollowUpService, type ScheduleFollowUpInput } from "../followup/service.js";
32
+ import type { FollowUpStatus } from "../followup/types.js";
33
+ import { MerchantOrderService, type ManualOrderReportInput } from "../orders/service.js";
34
+ import type { OrderRecordV2 } from "../orders/repository.js";
35
+ import type { AttributionInput, RefundFact } from "../orders/model.js";
36
+ import { ContributionRepository } from "../contribution/repository.js";
37
+ import type { ContributionInput } from "../contribution/types.js";
38
+ export interface MerchantOperationsFacadeOptions {
39
+ db: DatabaseSync;
40
+ merchantId: string;
41
+ now?: () => string;
42
+ }
43
+ export declare class MerchantOperationsFacade {
44
+ readonly plans: MerchantOperatingPlanService;
45
+ readonly opportunities: OpportunityService;
46
+ readonly proposals: ProposalService;
47
+ readonly followups: FollowUpService;
48
+ readonly orders: MerchantOrderService;
49
+ readonly contributions: ContributionRepository;
50
+ readonly merchantId: string;
51
+ constructor(options: MerchantOperationsFacadeOptions);
52
+ createPlan(input: Omit<OperatingPlanInput, "merchant_id">, command?: CommandOptions): OperatingPlan;
53
+ updatePlan(input: Omit<UpdateOperatingPlanInput, "merchant_id">, command?: CommandOptions): OperatingPlan;
54
+ switchPlanVersion(input: Omit<SwitchPlanVersionInput, "merchant_id">, command?: CommandOptions): {
55
+ previous: OperatingPlan;
56
+ next: OperatingPlan;
57
+ };
58
+ pausePlan(planId: string, expectedRevision: number, actor?: string): OperatingPlan;
59
+ resumePlan(planId: string, expectedRevision: number, actor?: string): OperatingPlan;
60
+ getEffectivePlan(input: {
61
+ source: string;
62
+ sourceAccountId: string;
63
+ sku: string;
64
+ at?: string;
65
+ }): OperatingPlan | undefined;
66
+ listPlans(filter?: Parameters<MerchantOperatingPlanService["list"]>[1]): OperatingPlan[];
67
+ planReadiness(plan: OperatingPlan, input: PlanReadinessInput): OperatingPlanReadiness;
68
+ ingestSource(input: Omit<IngestSourceInput, "merchant_id">): ReturnType<OpportunityService["ingestSource"]>;
69
+ createOpportunity(input: Omit<CreateOpportunityInput, "merchant_id">, command?: CommandOptions): ReturnType<OpportunityService["createOpportunity"]>;
70
+ recordRequirement(input: Omit<RecordRequirementInput, "merchant_id">, command?: CommandOptions): ReturnType<OpportunityService["recordRequirement"]>;
71
+ advanceOpportunity(input: {
72
+ opportunity_id: string;
73
+ expected_revision: number;
74
+ event: OpportunityEvent;
75
+ actor: string;
76
+ next_action?: string | null;
77
+ next_action_due_at?: string | null;
78
+ waiting_reason?: string | null;
79
+ }, command?: CommandOptions): ReturnType<OpportunityService["advance"]>;
80
+ getOpportunity(opportunityId: string): SalesOpportunity | undefined;
81
+ listOpportunities(filter?: {
82
+ status?: OpportunityStatus;
83
+ owner?: string;
84
+ }): SalesOpportunity[];
85
+ prepareProposal(input: Omit<PrepareProposalSetInput, "merchant_id">, command?: CommandOptions): ProposalSet;
86
+ selectProposal(input: Omit<SelectProposalInput, "merchant_id">, command?: CommandOptions): SelectionRecord;
87
+ approveProposal(input: {
88
+ set_id: string;
89
+ option_id: string;
90
+ policy_version: string;
91
+ expires_at: string;
92
+ now: string;
93
+ }, command?: CommandOptions): ApprovalBinding;
94
+ verifyProposalApproval(input: {
95
+ approval_id: string;
96
+ option_id: string;
97
+ policy_version: string;
98
+ now: string;
99
+ }): ApprovalBinding;
100
+ markProposalStale(input: {
101
+ set_id: string;
102
+ expected_revision: number;
103
+ reason: string;
104
+ now: string;
105
+ }, command?: CommandOptions): ProposalSet;
106
+ withdrawProposal(input: {
107
+ set_id: string;
108
+ expected_revision: number;
109
+ now: string;
110
+ }, command?: CommandOptions): ProposalSet;
111
+ getProposal(setId: string): ProposalSet | undefined;
112
+ listProposals(opportunityId: string): ProposalSet[];
113
+ scheduleFollowUp(input: Omit<ScheduleFollowUpInput, "merchant_id">): FollowUpTask;
114
+ listFollowUps(filter?: {
115
+ status?: FollowUpStatus;
116
+ opportunityId?: string;
117
+ }): FollowUpTask[];
118
+ claimFollowUp(taskId: string, workerId: string, leaseMs: number): FollowUpTask;
119
+ finishFollowUp(input: {
120
+ task_id: string;
121
+ fencing_token: number;
122
+ outcome: "succeeded" | "failed" | "unknown";
123
+ receipt?: Record<string, unknown>;
124
+ error_code?: string;
125
+ }): FollowUpTask;
126
+ stopFollowUp(taskId: string, inFlight: boolean): FollowUpTask;
127
+ recoverFollowUps(): FollowUpTask[];
128
+ listOrders(): OrderRecordV2[];
129
+ getOrder(recordId: string): OrderRecordV2 | undefined;
130
+ recordManualOrder(input: Omit<ManualOrderReportInput, "identity"> & {
131
+ source_namespace: string;
132
+ source_account_id: string;
133
+ external_order_id: string;
134
+ }): OrderRecordV2;
135
+ recordCsvOrderReport(input: {
136
+ csv: string;
137
+ reportedBy: string;
138
+ observedAtFallback: string;
139
+ }): OrderRecordV2[];
140
+ attributeOrder(recordId: string, allocations: AttributionInput[]): ReturnType<MerchantOrderService["attribute"]>;
141
+ recordOrderRefund(recordId: string, refund: RefundFact): {
142
+ status: string;
143
+ totalMinor: number;
144
+ };
145
+ assessOrderContribution(recordId: string, contribution: ContributionInput, costSnapshotId?: string): ReturnType<MerchantOrderService["assessContribution"]>;
146
+ linkOpportunitySource(input: {
147
+ opportunity_id: string;
148
+ source_id: string;
149
+ basis: string;
150
+ operator: string;
151
+ }): ReturnType<OpportunityService["linkSource"]>;
152
+ unlinkOpportunitySource(input: {
153
+ source_id: string;
154
+ basis: string;
155
+ operator: string;
156
+ }): ReturnType<OpportunityService["unlinkSource"]>;
157
+ }
158
+ /** 打开门面;数据库缺迁移时先补到当前版本(幂等)。 */
159
+ export declare function openMerchantOperationsFacade(options: MerchantOperationsFacadeOptions): MerchantOperationsFacade;
@@ -0,0 +1,213 @@
1
+ /**
2
+ * Copyright 2026 harrylabsj
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { migrateMerchantOpsSchema } from "./schema.js";
17
+ import { MerchantOperatingPlanRepository } from "../operating/repository.js";
18
+ import { MerchantOperatingPlanService, } from "../operating/service.js";
19
+ import { OpportunityRepository } from "../opportunity/repository.js";
20
+ import { OpportunityService, } from "../opportunity/service.js";
21
+ import { ProposalService, } from "../proposal/service.js";
22
+ import { ProposalRepository } from "../proposal/repository.js";
23
+ import { FollowUpRepository } from "../followup/repository.js";
24
+ import { FollowUpService } from "../followup/service.js";
25
+ import { MerchantOrderService } from "../orders/service.js";
26
+ import { OrderRepository } from "../orders/repository.js";
27
+ import { ContributionRepository } from "../contribution/repository.js";
28
+ export class MerchantOperationsFacade {
29
+ plans;
30
+ opportunities;
31
+ proposals;
32
+ followups;
33
+ orders;
34
+ contributions;
35
+ merchantId;
36
+ constructor(options) {
37
+ if (typeof options.merchantId !== "string" || options.merchantId.trim() === "") {
38
+ throw new Error("merchantId must be a non-empty string");
39
+ }
40
+ this.merchantId = options.merchantId;
41
+ const now = options.now ?? (() => new Date().toISOString());
42
+ this.plans = new MerchantOperatingPlanService({
43
+ repository: new MerchantOperatingPlanRepository({ db: options.db, now }),
44
+ now,
45
+ });
46
+ this.opportunities = new OpportunityService({
47
+ repository: new OpportunityRepository({ db: options.db, now }),
48
+ now,
49
+ });
50
+ this.proposals = new ProposalService({
51
+ repository: new ProposalRepository({ db: options.db, now }),
52
+ now,
53
+ });
54
+ this.followups = new FollowUpService({
55
+ repository: new FollowUpRepository({ db: options.db, now }),
56
+ now,
57
+ });
58
+ this.contributions = new ContributionRepository({ db: options.db, now });
59
+ this.orders = new MerchantOrderService({
60
+ orders: new OrderRepository({ db: options.db, now }),
61
+ contributions: this.contributions,
62
+ });
63
+ }
64
+ createPlan(input, command = {}) {
65
+ return this.plans.create({ ...input, merchant_id: this.merchantId }, command);
66
+ }
67
+ updatePlan(input, command = {}) {
68
+ return this.plans.update({ ...input, merchant_id: this.merchantId }, command);
69
+ }
70
+ switchPlanVersion(input, command = {}) {
71
+ return this.plans.switchVersion({ ...input, merchant_id: this.merchantId }, command);
72
+ }
73
+ pausePlan(planId, expectedRevision, actor) {
74
+ return this.plans.pause({
75
+ merchant_id: this.merchantId,
76
+ plan_id: planId,
77
+ expected_revision: expectedRevision,
78
+ ...(actor !== undefined ? { actor } : {}),
79
+ }, actor !== undefined ? { actor } : {});
80
+ }
81
+ resumePlan(planId, expectedRevision, actor) {
82
+ return this.plans.resume({
83
+ merchant_id: this.merchantId,
84
+ plan_id: planId,
85
+ expected_revision: expectedRevision,
86
+ ...(actor !== undefined ? { actor } : {}),
87
+ }, actor !== undefined ? { actor } : {});
88
+ }
89
+ getEffectivePlan(input) {
90
+ return this.plans.getEffective({ merchantId: this.merchantId, ...input });
91
+ }
92
+ listPlans(filter = {}) {
93
+ return this.plans.list(this.merchantId, filter);
94
+ }
95
+ planReadiness(plan, input) {
96
+ return this.plans.readiness(plan, input);
97
+ }
98
+ ingestSource(input) {
99
+ return this.opportunities.ingestSource({ ...input, merchant_id: this.merchantId });
100
+ }
101
+ createOpportunity(input, command = {}) {
102
+ return this.opportunities.createOpportunity({ ...input, merchant_id: this.merchantId }, command);
103
+ }
104
+ recordRequirement(input, command = {}) {
105
+ return this.opportunities.recordRequirement({ ...input, merchant_id: this.merchantId }, command);
106
+ }
107
+ advanceOpportunity(input, command = {}) {
108
+ return this.opportunities.advance({ ...input, merchant_id: this.merchantId }, command);
109
+ }
110
+ getOpportunity(opportunityId) {
111
+ return this.opportunities.getOpportunity(this.merchantId, opportunityId);
112
+ }
113
+ listOpportunities(filter = {}) {
114
+ return this.opportunities.listOpportunities(this.merchantId, filter);
115
+ }
116
+ prepareProposal(input, command = {}) {
117
+ return this.proposals.prepare({ ...input, merchant_id: this.merchantId }, command);
118
+ }
119
+ selectProposal(input, command = {}) {
120
+ return this.proposals.select({ ...input, merchant_id: this.merchantId }, command);
121
+ }
122
+ approveProposal(input, command = {}) {
123
+ return this.proposals.approve({ ...input, merchant_id: this.merchantId }, command);
124
+ }
125
+ verifyProposalApproval(input) {
126
+ return this.proposals.verifyApproval({ ...input, merchant_id: this.merchantId });
127
+ }
128
+ markProposalStale(input, command = {}) {
129
+ return this.proposals.markStale({ ...input, merchant_id: this.merchantId }, command);
130
+ }
131
+ withdrawProposal(input, command = {}) {
132
+ return this.proposals.withdraw({ ...input, merchant_id: this.merchantId }, command);
133
+ }
134
+ getProposal(setId) {
135
+ return this.proposals.get(this.merchantId, setId);
136
+ }
137
+ listProposals(opportunityId) {
138
+ return this.proposals.listForOpportunity(this.merchantId, opportunityId);
139
+ }
140
+ scheduleFollowUp(input) {
141
+ return this.followups.schedule({ ...input, merchant_id: this.merchantId }).task;
142
+ }
143
+ listFollowUps(filter = {}) {
144
+ return this.followups.list(this.merchantId, filter);
145
+ }
146
+ claimFollowUp(taskId, workerId, leaseMs) {
147
+ return this.followups.claim({
148
+ merchant_id: this.merchantId,
149
+ task_id: taskId,
150
+ worker_id: workerId,
151
+ lease_ms: leaseMs,
152
+ }).task;
153
+ }
154
+ finishFollowUp(input) {
155
+ return this.followups.finish({ ...input, merchant_id: this.merchantId });
156
+ }
157
+ stopFollowUp(taskId, inFlight) {
158
+ return this.followups.stop({
159
+ merchant_id: this.merchantId,
160
+ task_id: taskId,
161
+ in_flight: inFlight,
162
+ });
163
+ }
164
+ recoverFollowUps() {
165
+ return this.followups.recoverExpiredLeases(this.merchantId);
166
+ }
167
+ listOrders() {
168
+ return this.orders.listOrders(this.merchantId);
169
+ }
170
+ getOrder(recordId) {
171
+ return this.orders.getOrder(this.merchantId, recordId);
172
+ }
173
+ recordManualOrder(input) {
174
+ return this.orders.recordManualReport({
175
+ ...input,
176
+ identity: {
177
+ merchant_id: this.merchantId,
178
+ source_namespace: input.source_namespace,
179
+ source_account_id: input.source_account_id,
180
+ external_order_id: input.external_order_id,
181
+ },
182
+ });
183
+ }
184
+ recordCsvOrderReport(input) {
185
+ return this.orders.recordCsvReport({ merchantId: this.merchantId, ...input });
186
+ }
187
+ attributeOrder(recordId, allocations) {
188
+ return this.orders.attribute(this.merchantId, recordId, allocations);
189
+ }
190
+ recordOrderRefund(recordId, refund) {
191
+ return this.orders.recordRefund({ merchantId: this.merchantId, recordId, refund });
192
+ }
193
+ assessOrderContribution(recordId, contribution, costSnapshotId) {
194
+ return this.orders.assessContribution({
195
+ merchantId: this.merchantId,
196
+ recordId,
197
+ contribution,
198
+ ...(costSnapshotId !== undefined ? { costSnapshotId } : {}),
199
+ });
200
+ }
201
+ linkOpportunitySource(input) {
202
+ return this.opportunities.linkSource({ ...input, merchant_id: this.merchantId });
203
+ }
204
+ unlinkOpportunitySource(input) {
205
+ return this.opportunities.unlinkSource({ ...input, merchant_id: this.merchantId });
206
+ }
207
+ }
208
+ /** 打开门面;数据库缺迁移时先补到当前版本(幂等)。 */
209
+ export function openMerchantOperationsFacade(options) {
210
+ migrateMerchantOpsSchema(options.db);
211
+ return new MerchantOperationsFacade(options);
212
+ }
213
+ //# sourceMappingURL=facade.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facade.js","sourceRoot":"","sources":["../../../src/merchant-core/ops/facade.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAYH,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,+BAA+B,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EACL,4BAA4B,GAE7B,MAAM,yBAAyB,CAAC;AASjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EACL,kBAAkB,GAInB,MAAM,2BAA2B,CAA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AC,KAIvB;QACC,OAAO,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE,GAAG,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IACrF,CAAC;CACF;AAED,+BAA+B;AAC/B,MAAM,UAAU,4BAA4B,CAC1C,OAAwC;IAExC,wBAAwB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACrC,OAAO,IAAI,wBAAwB,CAAC,OAAO,CAAC,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Copyright 2026 harrylabsj
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * 商家持续经营 schema(v0.2 §16/§18)。
18
+ *
19
+ * 与通用 memory schema 分账:买家运行时不应出现商家经营/订单表。商家宿主
20
+ * (cloud bootstrap / merchant runtime)在打开门面时单独迁移本 schema,
21
+ * 使用自己的 `merchant_ops_schema_migrations` 版本账本。
22
+ */
23
+ import type { DatabaseSync } from "node:sqlite";
24
+ export declare const MERCHANT_OPS_SCHEMA_VERSION = 1;
25
+ export declare function migrateMerchantOpsSchema(db: DatabaseSync, targetVersion?: number): void;