@harrylabsj/kiwi 0.12.13 → 0.12.15
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/dist/a2a/node.d.ts +5 -0
- package/dist/a2a/node.js +69 -2
- package/dist/a2a/node.js.map +1 -1
- package/dist/a2a/server/merchant-handler.d.ts +8 -0
- package/dist/a2a/server/merchant-handler.js +105 -14
- package/dist/a2a/server/merchant-handler.js.map +1 -1
- package/dist/a2a/server/negotiation-advisor.d.ts +54 -0
- package/dist/a2a/server/negotiation-advisor.js +107 -0
- package/dist/a2a/server/negotiation-advisor.js.map +1 -0
- package/dist/a2a/server/negotiation-approvals.d.ts +101 -0
- package/dist/a2a/server/negotiation-approvals.js +208 -0
- package/dist/a2a/server/negotiation-approvals.js.map +1 -0
- package/dist/buyer-core/a2a-knp.d.ts +14 -0
- package/dist/buyer-core/a2a-knp.js +24 -0
- package/dist/buyer-core/a2a-knp.js.map +1 -1
- package/dist/buyer-core/a2a-negotiator.js +66 -11
- package/dist/buyer-core/a2a-negotiator.js.map +1 -1
- package/dist/buyer-core/protocol-recovery.d.ts +1 -1
- package/dist/buyer-core/receive-gate.js +7 -0
- package/dist/buyer-core/receive-gate.js.map +1 -1
- package/dist/buyer-core/service.d.ts +13 -0
- package/dist/buyer-core/service.js +73 -10
- package/dist/buyer-core/service.js.map +1 -1
- package/dist/cli.js +59 -0
- package/dist/cli.js.map +1 -1
- package/dist/cloud/bootstrap.js +12 -0
- package/dist/cloud/bootstrap.js.map +1 -1
- package/dist/cloud/merchant-connect.d.ts +8 -0
- package/dist/cloud/merchant-connect.js +3 -0
- package/dist/cloud/merchant-connect.js.map +1 -1
- package/dist/http/merchant-management/api.d.ts +3 -0
- package/dist/http/merchant-management/api.js +419 -0
- package/dist/http/merchant-management/api.js.map +1 -1
- package/dist/http/merchant-management/page.js +95 -1
- package/dist/http/merchant-management/page.js.map +1 -1
- package/dist/merchant/application/actor.d.ts +1 -1
- package/dist/merchant/application/actor.js +43 -1
- package/dist/merchant/application/actor.js.map +1 -1
- package/dist/merchant/quote-calculator.d.ts +7 -0
- package/dist/merchant/quote-calculator.js +35 -24
- package/dist/merchant/quote-calculator.js.map +1 -1
- package/dist/merchant-core/commercial/calculate.d.ts +18 -0
- package/dist/merchant-core/commercial/calculate.js +196 -0
- package/dist/merchant-core/commercial/calculate.js.map +1 -0
- package/dist/merchant-core/commercial/types.d.ts +91 -0
- package/dist/merchant-core/commercial/types.js +17 -0
- package/dist/merchant-core/commercial/types.js.map +1 -0
- package/dist/merchant-core/contribution/calculate.d.ts +24 -0
- package/dist/merchant-core/contribution/calculate.js +172 -0
- package/dist/merchant-core/contribution/calculate.js.map +1 -0
- package/dist/merchant-core/contribution/repository.d.ts +60 -0
- package/dist/merchant-core/contribution/repository.js +121 -0
- package/dist/merchant-core/contribution/repository.js.map +1 -0
- package/dist/merchant-core/contribution/types.d.ts +97 -0
- package/dist/merchant-core/contribution/types.js +24 -0
- package/dist/merchant-core/contribution/types.js.map +1 -0
- package/dist/merchant-core/followup/lease.d.ts +27 -0
- package/dist/merchant-core/followup/lease.js +45 -0
- package/dist/merchant-core/followup/lease.js.map +1 -0
- package/dist/merchant-core/followup/repository.d.ts +141 -0
- package/dist/merchant-core/followup/repository.js +280 -0
- package/dist/merchant-core/followup/repository.js.map +1 -0
- package/dist/merchant-core/followup/retry.d.ts +27 -0
- package/dist/merchant-core/followup/retry.js +61 -0
- package/dist/merchant-core/followup/retry.js.map +1 -0
- package/dist/merchant-core/followup/service.d.ts +114 -0
- package/dist/merchant-core/followup/service.js +191 -0
- package/dist/merchant-core/followup/service.js.map +1 -0
- package/dist/merchant-core/followup/state.d.ts +25 -0
- package/dist/merchant-core/followup/state.js +126 -0
- package/dist/merchant-core/followup/state.js.map +1 -0
- package/dist/merchant-core/followup/types.d.ts +75 -0
- package/dist/merchant-core/followup/types.js +41 -0
- package/dist/merchant-core/followup/types.js.map +1 -0
- package/dist/merchant-core/metrics/timing.d.ts +63 -0
- package/dist/merchant-core/metrics/timing.js +125 -0
- package/dist/merchant-core/metrics/timing.js.map +1 -0
- package/dist/merchant-core/operating/repository.d.ts +97 -0
- package/dist/merchant-core/operating/repository.js +266 -0
- package/dist/merchant-core/operating/repository.js.map +1 -0
- package/dist/merchant-core/operating/service.d.ts +63 -0
- package/dist/merchant-core/operating/service.js +336 -0
- package/dist/merchant-core/operating/service.js.map +1 -0
- package/dist/merchant-core/operating/types.d.ts +102 -0
- package/dist/merchant-core/operating/types.js +24 -0
- package/dist/merchant-core/operating/types.js.map +1 -0
- package/dist/merchant-core/opportunity/repository.d.ts +128 -0
- package/dist/merchant-core/opportunity/repository.js +251 -0
- package/dist/merchant-core/opportunity/repository.js.map +1 -0
- package/dist/merchant-core/opportunity/service.d.ts +117 -0
- package/dist/merchant-core/opportunity/service.js +388 -0
- package/dist/merchant-core/opportunity/service.js.map +1 -0
- package/dist/merchant-core/opportunity/state.d.ts +33 -0
- package/dist/merchant-core/opportunity/state.js +166 -0
- package/dist/merchant-core/opportunity/state.js.map +1 -0
- package/dist/merchant-core/opportunity/types.d.ts +141 -0
- package/dist/merchant-core/opportunity/types.js +42 -0
- package/dist/merchant-core/opportunity/types.js.map +1 -0
- package/dist/merchant-core/ops/facade.d.ts +159 -0
- package/dist/merchant-core/ops/facade.js +213 -0
- package/dist/merchant-core/ops/facade.js.map +1 -0
- package/dist/merchant-core/ops/schema.d.ts +25 -0
- package/dist/merchant-core/ops/schema.js +448 -0
- package/dist/merchant-core/ops/schema.js.map +1 -0
- package/dist/merchant-core/ops/surface.d.ts +49 -0
- package/dist/merchant-core/ops/surface.js +304 -0
- package/dist/merchant-core/ops/surface.js.map +1 -0
- package/dist/merchant-core/orders/csv.d.ts +36 -0
- package/dist/merchant-core/orders/csv.js +173 -0
- package/dist/merchant-core/orders/csv.js.map +1 -0
- package/dist/merchant-core/orders/model.d.ts +155 -0
- package/dist/merchant-core/orders/model.js +237 -0
- package/dist/merchant-core/orders/model.js.map +1 -0
- package/dist/merchant-core/orders/repository.d.ts +99 -0
- package/dist/merchant-core/orders/repository.js +221 -0
- package/dist/merchant-core/orders/repository.js.map +1 -0
- package/dist/merchant-core/orders/service.d.ts +84 -0
- package/dist/merchant-core/orders/service.js +121 -0
- package/dist/merchant-core/orders/service.js.map +1 -0
- package/dist/merchant-core/orders/shopping-cli-source.d.ts +58 -0
- package/dist/merchant-core/orders/shopping-cli-source.js +164 -0
- package/dist/merchant-core/orders/shopping-cli-source.js.map +1 -0
- package/dist/merchant-core/proposal/engine.d.ts +31 -0
- package/dist/merchant-core/proposal/engine.js +348 -0
- package/dist/merchant-core/proposal/engine.js.map +1 -0
- package/dist/merchant-core/proposal/publish.d.ts +46 -0
- package/dist/merchant-core/proposal/publish.js +79 -0
- package/dist/merchant-core/proposal/publish.js.map +1 -0
- package/dist/merchant-core/proposal/repository.d.ts +60 -0
- package/dist/merchant-core/proposal/repository.js +186 -0
- package/dist/merchant-core/proposal/repository.js.map +1 -0
- package/dist/merchant-core/proposal/service.d.ts +73 -0
- package/dist/merchant-core/proposal/service.js +149 -0
- package/dist/merchant-core/proposal/service.js.map +1 -0
- package/dist/merchant-core/proposal/types.d.ts +163 -0
- package/dist/merchant-core/proposal/types.js +25 -0
- package/dist/merchant-core/proposal/types.js.map +1 -0
- package/dist/product-cli.js +5 -0
- package/dist/product-cli.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,251 @@
|
|
|
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.1 / §6.3 / §16)。
|
|
18
|
+
*
|
|
19
|
+
* 写操作使用 `BEGIN IMMEDIATE`;外部事件按 (source_id, external_event_id)
|
|
20
|
+
* 幂等,来源记录按 (merchant, namespace, account, external_inquiry_id) 幂等。
|
|
21
|
+
*/
|
|
22
|
+
import { randomUUID } from "node:crypto";
|
|
23
|
+
import { contentDigest } from "../../negotiation/jcs.js";
|
|
24
|
+
import { OpportunityError, } from "./types.js";
|
|
25
|
+
function sourceToRow(row) {
|
|
26
|
+
return { ...row };
|
|
27
|
+
}
|
|
28
|
+
function eventToRow(row) {
|
|
29
|
+
return { ...row };
|
|
30
|
+
}
|
|
31
|
+
function opportunityToRow(row) {
|
|
32
|
+
return { ...row };
|
|
33
|
+
}
|
|
34
|
+
function linkToRow(row) {
|
|
35
|
+
return { ...row };
|
|
36
|
+
}
|
|
37
|
+
function requirementToRow(row) {
|
|
38
|
+
return {
|
|
39
|
+
opportunity_id: row.opportunity_id,
|
|
40
|
+
revision: row.revision,
|
|
41
|
+
fields: JSON.parse(row.fields_json),
|
|
42
|
+
created_at: row.created_at,
|
|
43
|
+
created_by: row.created_by,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export class OpportunityRepository {
|
|
47
|
+
db;
|
|
48
|
+
now;
|
|
49
|
+
inTx = false;
|
|
50
|
+
constructor(options) {
|
|
51
|
+
this.db = options.db;
|
|
52
|
+
this.now = options.now;
|
|
53
|
+
}
|
|
54
|
+
transaction(work) {
|
|
55
|
+
if (this.inTx)
|
|
56
|
+
return work();
|
|
57
|
+
this.inTx = true;
|
|
58
|
+
this.db.exec("BEGIN IMMEDIATE");
|
|
59
|
+
try {
|
|
60
|
+
const result = work();
|
|
61
|
+
this.db.exec("COMMIT");
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
this.db.exec("ROLLBACK");
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
this.inTx = false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
getSourceByExternalId(input) {
|
|
73
|
+
const row = this.db
|
|
74
|
+
.prepare(`SELECT * FROM opportunity_sources
|
|
75
|
+
WHERE merchant_id = ? AND source_namespace = ? AND source_account_id = ? AND external_inquiry_id = ?`)
|
|
76
|
+
.get(input.merchantId, input.sourceNamespace, input.sourceAccountId, input.externalInquiryId);
|
|
77
|
+
return row === undefined ? undefined : sourceToRow(row);
|
|
78
|
+
}
|
|
79
|
+
getSource(merchantId, sourceId) {
|
|
80
|
+
const row = this.db
|
|
81
|
+
.prepare("SELECT * FROM opportunity_sources WHERE merchant_id = ? AND source_id = ?")
|
|
82
|
+
.get(merchantId, sourceId);
|
|
83
|
+
return row === undefined ? undefined : sourceToRow(row);
|
|
84
|
+
}
|
|
85
|
+
insertSource(input) {
|
|
86
|
+
const sourceId = `src_${randomUUID()}`;
|
|
87
|
+
const now = this.now();
|
|
88
|
+
this.db
|
|
89
|
+
.prepare(`INSERT INTO opportunity_sources
|
|
90
|
+
(source_id, merchant_id, source_namespace, source_account_id, external_inquiry_id,
|
|
91
|
+
raw_excerpt, received_at, operator, parse_version, revision, created_at, updated_at)
|
|
92
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?)`)
|
|
93
|
+
.run(sourceId, input.merchant_id, input.source_namespace, input.source_account_id, input.external_inquiry_id, input.raw_excerpt, input.received_at, input.operator, input.parse_version, now, now);
|
|
94
|
+
return this.getSource(input.merchant_id, sourceId);
|
|
95
|
+
}
|
|
96
|
+
touchSource(merchantId, sourceId) {
|
|
97
|
+
this.db
|
|
98
|
+
.prepare("UPDATE opportunity_sources SET revision = revision + 1, updated_at = ? WHERE merchant_id = ? AND source_id = ?")
|
|
99
|
+
.run(this.now(), merchantId, sourceId);
|
|
100
|
+
return this.getSource(merchantId, sourceId);
|
|
101
|
+
}
|
|
102
|
+
getSourceEvent(sourceId, externalEventId) {
|
|
103
|
+
const row = this.db
|
|
104
|
+
.prepare("SELECT * FROM opportunity_source_events WHERE source_id = ? AND external_event_id = ?")
|
|
105
|
+
.get(sourceId, externalEventId);
|
|
106
|
+
return row === undefined ? undefined : eventToRow(row);
|
|
107
|
+
}
|
|
108
|
+
insertSourceEvent(input) {
|
|
109
|
+
const eventId = `evt_${randomUUID()}`;
|
|
110
|
+
this.db
|
|
111
|
+
.prepare(`INSERT INTO opportunity_source_events
|
|
112
|
+
(event_id, source_id, external_event_id, event_kind, payload_digest, received_at, created_at)
|
|
113
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`)
|
|
114
|
+
.run(eventId, input.sourceId, input.externalEventId, input.eventKind, contentDigest(input.payload ?? {}), input.receivedAt, this.now());
|
|
115
|
+
const row = this.db
|
|
116
|
+
.prepare("SELECT * FROM opportunity_source_events WHERE event_id = ?")
|
|
117
|
+
.get(eventId);
|
|
118
|
+
return eventToRow(row);
|
|
119
|
+
}
|
|
120
|
+
getOpportunity(merchantId, opportunityId) {
|
|
121
|
+
const row = this.db
|
|
122
|
+
.prepare("SELECT * FROM sales_opportunities WHERE merchant_id = ? AND opportunity_id = ?")
|
|
123
|
+
.get(merchantId, opportunityId);
|
|
124
|
+
return row === undefined ? undefined : opportunityToRow(row);
|
|
125
|
+
}
|
|
126
|
+
listOpportunities(merchantId, filter = {}) {
|
|
127
|
+
const where = ["merchant_id = ?"];
|
|
128
|
+
const params = [merchantId];
|
|
129
|
+
if (filter.status !== undefined) {
|
|
130
|
+
where.push("status = ?");
|
|
131
|
+
params.push(filter.status);
|
|
132
|
+
}
|
|
133
|
+
if (filter.owner !== undefined) {
|
|
134
|
+
where.push("owner = ?");
|
|
135
|
+
params.push(filter.owner);
|
|
136
|
+
}
|
|
137
|
+
const rows = this.db
|
|
138
|
+
.prepare(`SELECT * FROM sales_opportunities WHERE ${where.join(" AND ")} ORDER BY updated_at DESC`)
|
|
139
|
+
.all(...params);
|
|
140
|
+
return rows.map(opportunityToRow);
|
|
141
|
+
}
|
|
142
|
+
insertOpportunity(input) {
|
|
143
|
+
const opportunityId = `opp_${randomUUID()}`;
|
|
144
|
+
const now = this.now();
|
|
145
|
+
this.db
|
|
146
|
+
.prepare(`INSERT INTO sales_opportunities
|
|
147
|
+
(opportunity_id, merchant_id, status, owner, next_action, next_action_due_at,
|
|
148
|
+
waiting_reason, rfq_case_id, revision, created_at, updated_at)
|
|
149
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?)`)
|
|
150
|
+
.run(opportunityId, input.merchantId, input.status, input.owner, input.nextAction ?? null, input.nextActionDueAt ?? null, input.waitingReason ?? null, input.rfqCaseId ?? null, now, now);
|
|
151
|
+
return this.getOpportunity(input.merchantId, opportunityId);
|
|
152
|
+
}
|
|
153
|
+
updateOpportunity(input) {
|
|
154
|
+
const current = this.getOpportunity(input.merchantId, input.opportunityId);
|
|
155
|
+
if (current === undefined) {
|
|
156
|
+
throw new OpportunityError("not_found", `opportunity ${input.opportunityId} not found`);
|
|
157
|
+
}
|
|
158
|
+
const result = this.db
|
|
159
|
+
.prepare(`UPDATE sales_opportunities
|
|
160
|
+
SET status = ?, owner = ?, next_action = ?, next_action_due_at = ?, waiting_reason = ?,
|
|
161
|
+
revision = ?, updated_at = ?
|
|
162
|
+
WHERE merchant_id = ? AND opportunity_id = ? AND revision = ?`)
|
|
163
|
+
.run(input.status, input.owner ?? current.owner, input.nextAction !== undefined ? input.nextAction : current.next_action, input.nextActionDueAt !== undefined ? input.nextActionDueAt : current.next_action_due_at, input.waitingReason !== undefined ? input.waitingReason : current.waiting_reason, current.revision + 1, this.now(), input.merchantId, input.opportunityId, input.expectedRevision);
|
|
164
|
+
if (Number(result.changes) !== 1) {
|
|
165
|
+
throw new OpportunityError("version_conflict", "机会已被其他操作修改,请刷新后重试");
|
|
166
|
+
}
|
|
167
|
+
return this.getOpportunity(input.merchantId, input.opportunityId);
|
|
168
|
+
}
|
|
169
|
+
getLinkBySource(sourceId) {
|
|
170
|
+
const row = this.db
|
|
171
|
+
.prepare("SELECT * FROM opportunity_links WHERE source_id = ?")
|
|
172
|
+
.get(sourceId);
|
|
173
|
+
return row === undefined ? undefined : linkToRow(row);
|
|
174
|
+
}
|
|
175
|
+
insertLink(input) {
|
|
176
|
+
const linkId = `lnk_${randomUUID()}`;
|
|
177
|
+
const now = this.now();
|
|
178
|
+
this.db
|
|
179
|
+
.prepare(`INSERT INTO opportunity_links
|
|
180
|
+
(link_id, merchant_id, opportunity_id, source_id, status, basis, confirmed_by,
|
|
181
|
+
confirmed_at, revision, created_at, updated_at)
|
|
182
|
+
VALUES (?, ?, ?, ?, 'LINKED', ?, ?, ?, 1, ?, ?)`)
|
|
183
|
+
.run(linkId, input.merchantId, input.opportunityId, input.sourceId, input.basis, input.confirmedBy, input.confirmedAt, now, now);
|
|
184
|
+
return this.getLink(linkId);
|
|
185
|
+
}
|
|
186
|
+
getLink(linkId) {
|
|
187
|
+
const row = this.db
|
|
188
|
+
.prepare("SELECT * FROM opportunity_links WHERE link_id = ?")
|
|
189
|
+
.get(linkId);
|
|
190
|
+
return row === undefined ? undefined : linkToRow(row);
|
|
191
|
+
}
|
|
192
|
+
updateLink(input) {
|
|
193
|
+
const result = this.db
|
|
194
|
+
.prepare(`UPDATE opportunity_links
|
|
195
|
+
SET opportunity_id = ?, status = ?, basis = ?, confirmed_by = ?, confirmed_at = ?,
|
|
196
|
+
revision = revision + 1, updated_at = ?
|
|
197
|
+
WHERE link_id = ? AND merchant_id = ? AND revision = ?`)
|
|
198
|
+
.run(input.opportunityId, input.status, input.basis, input.confirmedBy, input.confirmedAt, this.now(), input.linkId, input.merchantId, input.expectedRevision);
|
|
199
|
+
if (Number(result.changes) !== 1) {
|
|
200
|
+
throw new OpportunityError("version_conflict", "来源关联已被其他操作修改,请刷新后重试");
|
|
201
|
+
}
|
|
202
|
+
return this.getLink(input.linkId);
|
|
203
|
+
}
|
|
204
|
+
appendLinkEvent(input) {
|
|
205
|
+
this.db
|
|
206
|
+
.prepare(`INSERT INTO opportunity_link_events
|
|
207
|
+
(merchant_id, link_id, opportunity_id, source_id, event, actor, basis, at)
|
|
208
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
209
|
+
.run(input.merchantId, input.linkId, input.opportunityId, input.sourceId, input.event, input.actor, input.basis, this.now());
|
|
210
|
+
}
|
|
211
|
+
getLatestRequirement(merchantId, opportunityId) {
|
|
212
|
+
const row = this.db
|
|
213
|
+
.prepare(`SELECT * FROM opportunity_requirements
|
|
214
|
+
WHERE merchant_id = ? AND opportunity_id = ?
|
|
215
|
+
ORDER BY revision DESC LIMIT 1`)
|
|
216
|
+
.get(merchantId, opportunityId);
|
|
217
|
+
return row === undefined ? undefined : requirementToRow(row);
|
|
218
|
+
}
|
|
219
|
+
insertRequirement(input) {
|
|
220
|
+
this.db
|
|
221
|
+
.prepare(`INSERT INTO opportunity_requirements
|
|
222
|
+
(opportunity_id, revision, merchant_id, fields_json, created_at, created_by)
|
|
223
|
+
VALUES (?, ?, ?, ?, ?, ?)`)
|
|
224
|
+
.run(input.opportunityId, input.revision, input.merchantId, JSON.stringify(input.fields), this.now(), input.createdBy);
|
|
225
|
+
return this.getLatestRequirement(input.merchantId, input.opportunityId);
|
|
226
|
+
}
|
|
227
|
+
appendOpportunityEvent(input) {
|
|
228
|
+
this.db
|
|
229
|
+
.prepare(`INSERT INTO opportunity_events
|
|
230
|
+
(opportunity_id, merchant_id, event, from_status, to_status, actor,
|
|
231
|
+
side_effects_json, detail_json, at)
|
|
232
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
233
|
+
.run(input.opportunityId, input.merchantId, input.event, input.fromStatus, input.toStatus, input.actor, JSON.stringify(input.sideEffects), JSON.stringify(input.detail), this.now());
|
|
234
|
+
}
|
|
235
|
+
readIdempotent(merchantId, key) {
|
|
236
|
+
const row = this.db
|
|
237
|
+
.prepare("SELECT operation, request_digest, result_json FROM merchant_command_idempotency WHERE merchant_id = ? AND idempotency_key = ?")
|
|
238
|
+
.get(merchantId, key);
|
|
239
|
+
return row === undefined
|
|
240
|
+
? undefined
|
|
241
|
+
: { operation: row.operation, requestDigest: row.request_digest, result: row.result_json };
|
|
242
|
+
}
|
|
243
|
+
saveIdempotent(input) {
|
|
244
|
+
this.db
|
|
245
|
+
.prepare(`INSERT INTO merchant_command_idempotency
|
|
246
|
+
(merchant_id, idempotency_key, operation, request_digest, result_json, created_at)
|
|
247
|
+
VALUES (?, ?, ?, ?, ?, ?)`)
|
|
248
|
+
.run(input.merchantId, input.key, input.operation, contentDigest({ operation: input.operation, request: input.request }), JSON.stringify(input.result), this.now());
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../../src/merchant-core/opportunity/repository.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EACL,gBAAgB,GAQjB,MAAM,YAAY,CAAC;AAqEpB,SAAS,WAAW,CAAC,GAAc;IACjC,OAAO,EAAE,GAAG,GAAG,EAAE,CAAC;AACpB,CAAC;AAED,SAAS,UAAU,CAAC,GAAmB;IACrC,OAAO,EAAE,GAAG,GAAG,EAAE,CAAC;AACpB,CAAC;AAED,SAAS,gBAAgB,CAAC,GAAmB;IAC3C,OAAO,EAAE,GAAG,GAAG,EAAE,CAAC;AACpB,CAAC;AAED,SAAS,SAAS,CAAC,GAAY;IAC7B,OAAO,EAAE,GAAG,GAAG,EAAE,CAAC;AACpB,CAAC;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UAAU,EAChB,KAAK,CAAC,KAAK,EACX,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,QAAQ,EACd,KAAK,CAAC,KAAK,EACX,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,WAAW,CAAC,EACjC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAC5B,IAAI,CAAC,GAAG,EAAE,CACX,CAAC;IACN,CAAC;IAED,cAAc,CAAC,UAAkB,EAAE,GAAW;QAC5C,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE;aAChB,OAAO,CACN,+HAA+H,CAChI;aACA,GAAG,CAAC,UAAU,EAAE,GAAG,CAAmF,CAAC;QAC1G,OAAO,GAAG,KAAK,SAAS;YACtB,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,aAAa,EAAE,GAAG,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC;IAC/F,CAAC;IAED,cAAc,CAAC,KAMd;QACC,IAAI,CAAC,EAAE;aACJ,OAAO,CACN;;mCAE2B,CAC5B;aACA,GAAG,CACF,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,GAAG,EACT,KAAK,CAAC,SAAS,EACf,aAAa,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,EACrE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAC5B,IAAI,CAAC,GAAG,EAAE,CACX,CAAC;IACN,CAAC;CACF"}
|
|
@@ -0,0 +1,117 @@
|
|
|
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 { OpportunityRepository } from "./repository.js";
|
|
17
|
+
import { type TransitionResult } from "./state.js";
|
|
18
|
+
import { type OpportunityEvent, type OpportunityLink, type OpportunitySource, type OpportunitySourceEvent, type OpportunityStatus, type RequirementField, type RequirementSnapshot, type SalesOpportunity } from "./types.js";
|
|
19
|
+
export interface OpportunityServiceOptions {
|
|
20
|
+
repository: OpportunityRepository;
|
|
21
|
+
now: () => string;
|
|
22
|
+
}
|
|
23
|
+
export interface CommandOptions {
|
|
24
|
+
idempotency_key?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface IngestSourceInput {
|
|
27
|
+
merchant_id: string;
|
|
28
|
+
source_namespace: string;
|
|
29
|
+
source_account_id: string;
|
|
30
|
+
external_inquiry_id: string;
|
|
31
|
+
external_event_id: string;
|
|
32
|
+
event_kind: string;
|
|
33
|
+
raw_excerpt: string;
|
|
34
|
+
received_at: string;
|
|
35
|
+
operator: string;
|
|
36
|
+
parse_version: string;
|
|
37
|
+
payload?: unknown;
|
|
38
|
+
}
|
|
39
|
+
export interface CreateOpportunityInput {
|
|
40
|
+
merchant_id: string;
|
|
41
|
+
source_id: string;
|
|
42
|
+
owner: string;
|
|
43
|
+
operator: string;
|
|
44
|
+
next_action: string;
|
|
45
|
+
next_action_due_at?: string;
|
|
46
|
+
rfq_case_id?: string;
|
|
47
|
+
/** 必须已确认才能进入待方案的字段名;空数组表示无硬性字段。 */
|
|
48
|
+
required_fields: string[];
|
|
49
|
+
requirement_fields: RequirementField[];
|
|
50
|
+
basis: string;
|
|
51
|
+
}
|
|
52
|
+
export interface RecordRequirementInput {
|
|
53
|
+
merchant_id: string;
|
|
54
|
+
opportunity_id: string;
|
|
55
|
+
expected_revision: number;
|
|
56
|
+
fields: RequirementField[];
|
|
57
|
+
required_fields: string[];
|
|
58
|
+
created_by: string;
|
|
59
|
+
actor: string;
|
|
60
|
+
}
|
|
61
|
+
export interface AdvanceOpportunityInput {
|
|
62
|
+
merchant_id: string;
|
|
63
|
+
opportunity_id: string;
|
|
64
|
+
expected_revision: number;
|
|
65
|
+
event: OpportunityEvent;
|
|
66
|
+
actor: string;
|
|
67
|
+
next_action?: string | null;
|
|
68
|
+
next_action_due_at?: string | null;
|
|
69
|
+
waiting_reason?: string | null;
|
|
70
|
+
}
|
|
71
|
+
export declare class OpportunityService {
|
|
72
|
+
private readonly repository;
|
|
73
|
+
private readonly now;
|
|
74
|
+
constructor(options: OpportunityServiceOptions);
|
|
75
|
+
/** 来源摄取:同一外部询盘/事件重复进入不新建记录;相似文本不自动合并。 */
|
|
76
|
+
ingestSource(input: IngestSourceInput): {
|
|
77
|
+
source: OpportunitySource;
|
|
78
|
+
event: OpportunitySourceEvent;
|
|
79
|
+
created_source: boolean;
|
|
80
|
+
created_event: boolean;
|
|
81
|
+
};
|
|
82
|
+
createOpportunity(input: CreateOpportunityInput, command?: CommandOptions): {
|
|
83
|
+
opportunity: SalesOpportunity;
|
|
84
|
+
requirement: RequirementSnapshot;
|
|
85
|
+
link: OpportunityLink;
|
|
86
|
+
side_effects: string[];
|
|
87
|
+
};
|
|
88
|
+
recordRequirement(input: RecordRequirementInput, command?: CommandOptions): {
|
|
89
|
+
opportunity: SalesOpportunity;
|
|
90
|
+
requirement: RequirementSnapshot;
|
|
91
|
+
transition: TransitionResult;
|
|
92
|
+
};
|
|
93
|
+
advance(input: AdvanceOpportunityInput, command?: CommandOptions): {
|
|
94
|
+
opportunity: SalesOpportunity;
|
|
95
|
+
transition: TransitionResult;
|
|
96
|
+
};
|
|
97
|
+
linkSource(input: {
|
|
98
|
+
merchant_id: string;
|
|
99
|
+
opportunity_id: string;
|
|
100
|
+
source_id: string;
|
|
101
|
+
basis: string;
|
|
102
|
+
operator: string;
|
|
103
|
+
}, command?: CommandOptions): OpportunityLink;
|
|
104
|
+
unlinkSource(input: {
|
|
105
|
+
merchant_id: string;
|
|
106
|
+
source_id: string;
|
|
107
|
+
basis: string;
|
|
108
|
+
operator: string;
|
|
109
|
+
}, command?: CommandOptions): OpportunityLink;
|
|
110
|
+
getOpportunity(merchantId: string, opportunityId: string): SalesOpportunity | undefined;
|
|
111
|
+
listOpportunities(merchantId: string, filter?: {
|
|
112
|
+
status?: OpportunityStatus;
|
|
113
|
+
owner?: string;
|
|
114
|
+
}): SalesOpportunity[];
|
|
115
|
+
private requireOpportunity;
|
|
116
|
+
private withIdempotency;
|
|
117
|
+
}
|