@campfire-interactive/master-data-client 5.29.0 → 5.31.0
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/client.d.ts +4 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +5 -0
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/programs.d.ts +65 -0
- package/dist/programs.d.ts.map +1 -0
- package/dist/programs.js +193 -0
- package/dist/programs.js.map +1 -0
- package/dist/quoteAsks.d.ts +25 -2
- package/dist/quoteAsks.d.ts.map +1 -1
- package/dist/quoteAsks.js +25 -2
- package/dist/quoteAsks.js.map +1 -1
- package/dist/rfqs.d.ts +103 -0
- package/dist/rfqs.d.ts.map +1 -0
- package/dist/rfqs.js +148 -0
- package/dist/rfqs.js.map +1 -0
- package/dist/scopeGate.d.ts +103 -0
- package/dist/scopeGate.d.ts.map +1 -0
- package/dist/scopeGate.js +155 -0
- package/dist/scopeGate.js.map +1 -0
- package/dist/standardAttributes.d.ts +80 -0
- package/dist/standardAttributes.d.ts.map +1 -0
- package/dist/standardAttributes.js +188 -0
- package/dist/standardAttributes.js.map +1 -0
- package/dist/types.d.ts +177 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/dist/quoteAsks.js
CHANGED
|
@@ -4,6 +4,19 @@ exports.QuoteAskResource = void 0;
|
|
|
4
4
|
/**
|
|
5
5
|
* Quote asks — the OEM's request for several competing prices.
|
|
6
6
|
*
|
|
7
|
+
* **@deprecated Use {@link RfqResource} (`client.rfqs`).** `quote_ask` became
|
|
8
|
+
* the `rfq` table on 2026-10-24; this resource is the old face of the same
|
|
9
|
+
* rows, served through a server-side adapter. Migrated rows KEPT THEIR UUIDs,
|
|
10
|
+
* so an `askId` held from before is the `rfq.id` for the same request — moving
|
|
11
|
+
* over is a rename, not a re-fetch.
|
|
12
|
+
*
|
|
13
|
+
* It returns the old shape unchanged and will keep working until the
|
|
14
|
+
* `/v1/quote-asks` endpoints are removed, which is its own change once OMSF and
|
|
15
|
+
* CPQ are migrated. What you give up by staying: `status` here is the old
|
|
16
|
+
* three-value enum, so `resolved` still cannot tell you whether anybody
|
|
17
|
+
* actually won, and the new fields (`receivedAt`, `source`, `customerReference`,
|
|
18
|
+
* `mergedIntoRfqId`) are invisible.
|
|
19
|
+
*
|
|
7
20
|
* The level ABOVE the quote. An OEM asks for several COMPETING groupings of the
|
|
8
21
|
* same parts and picks one ("give me four prices on A3 bumpers: base + S line, RS
|
|
9
22
|
* alone, wagon alone, all four"); each grouping is a `Quote`, and the ask is what
|
|
@@ -30,12 +43,14 @@ exports.QuoteAskResource = void 0;
|
|
|
30
43
|
* resolution, kept together) is behavior over quote lifecycles and ships in a
|
|
31
44
|
* later phase behind its own gate.
|
|
32
45
|
*/
|
|
46
|
+
/** @deprecated Use {@link RfqResource}. */
|
|
33
47
|
class QuoteAskResource {
|
|
34
48
|
http;
|
|
35
49
|
constructor(http) {
|
|
36
50
|
this.http = http;
|
|
37
51
|
}
|
|
38
|
-
/** Asks with a `quoteCount` each — never an aggregate value.
|
|
52
|
+
/** Asks with a `quoteCount` each — never an aggregate value.
|
|
53
|
+
* @deprecated Use `client.rfqs.list()`. */
|
|
39
54
|
async list(options) {
|
|
40
55
|
const query = {};
|
|
41
56
|
if (options?.status)
|
|
@@ -54,6 +69,7 @@ class QuoteAskResource {
|
|
|
54
69
|
* One ask with its competing quotes — each carrying its own lines and roll-up —
|
|
55
70
|
* plus the ask-level `range`.
|
|
56
71
|
*/
|
|
72
|
+
/** @deprecated Use `client.rfqs.get()`. */
|
|
57
73
|
async get(id) {
|
|
58
74
|
return this.http.request({
|
|
59
75
|
method: 'GET',
|
|
@@ -61,7 +77,12 @@ class QuoteAskResource {
|
|
|
61
77
|
});
|
|
62
78
|
}
|
|
63
79
|
/** Open a request. `askNumber` (`ASK-YYYY-NNN`) is minted server-side from an
|
|
64
|
-
* atomic per-(tenant, year) counter.
|
|
80
|
+
* atomic per-(tenant, year) counter. The prefix has been `RFQ-` since
|
|
81
|
+
* 2026-08-06; the `ASK-` in older docs was never what the code minted. */
|
|
82
|
+
/**
|
|
83
|
+
* @deprecated Use `client.rfqs.create()`, which can also record how the
|
|
84
|
+
* request arrived. This path always records `source: 'manual'`.
|
|
85
|
+
*/
|
|
65
86
|
async create(input, idempotencyKey) {
|
|
66
87
|
return this.http.request({
|
|
67
88
|
method: 'POST',
|
|
@@ -77,6 +98,7 @@ class QuoteAskResource {
|
|
|
77
98
|
* ask's own quotes (422 otherwise) — the record of which one won must point
|
|
78
99
|
* inside the set that was competing.
|
|
79
100
|
*/
|
|
101
|
+
/** @deprecated Use `client.rfqs.update()`. */
|
|
80
102
|
async update(id, input) {
|
|
81
103
|
return this.http.request({
|
|
82
104
|
method: 'PATCH',
|
|
@@ -92,6 +114,7 @@ class QuoteAskResource {
|
|
|
92
114
|
* Refused once resolved (422): a resolved ask is the record of which quote won,
|
|
93
115
|
* and without it a closed sibling has no explanation. Cancel it instead.
|
|
94
116
|
*/
|
|
117
|
+
/** @deprecated Use `client.rfqs.remove()`. */
|
|
95
118
|
async remove(id) {
|
|
96
119
|
return this.http.request({
|
|
97
120
|
method: 'DELETE',
|
package/dist/quoteAsks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quoteAsks.js","sourceRoot":"","sources":["../src/quoteAsks.ts"],"names":[],"mappings":";;;AAWA
|
|
1
|
+
{"version":3,"file":"quoteAsks.js","sourceRoot":"","sources":["../src/quoteAsks.ts"],"names":[],"mappings":";;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,2CAA2C;AAC3C,MAAa,gBAAgB;IACE;IAA7B,YAA6B,IAAmB;QAAnB,SAAI,GAAJ,IAAI,CAAe;IAAG,CAAC;IAEpD;gDAC4C;I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8C;IAC9C,KAAK,CAAC,MAAM,CAAC,EAAU;QACrB,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAoD;YAC1E,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,kBAAkB,kBAAkB,CAAC,EAAE,CAAC,EAAE;SACjD,CAAC,CAAC;IACL,CAAC;CACF;AA/ED,4CA+EC"}
|
package/dist/rfqs.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { HttpTransport } from './http';
|
|
2
|
+
import type { Rfq, RfqDetail, RfqSummary, CreateRfqInput, UpdateRfqInput, ListRfqsOptions, SingleResponse } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* RFQs — ONE customer request; the competing quotes are its options.
|
|
5
|
+
*
|
|
6
|
+
* The level ABOVE the quote. An OEM asks for several COMPETING groupings of the
|
|
7
|
+
* same parts and picks one ("give me four prices on A3 bumpers: base + S line,
|
|
8
|
+
* RS alone, wagon alone, all four"); each grouping is a `Quote`, and the RFQ is
|
|
9
|
+
* what makes that set nameable. Without it "the losers" is not a set the system
|
|
10
|
+
* can name, and a shared nullable `opportunityId` is not a grouping — it is
|
|
11
|
+
* nullable, it drifts, and an opportunity spans rounds. See the nextgen ADR
|
|
12
|
+
* `2026-08-05-multi-part-quotes.md`.
|
|
13
|
+
*
|
|
14
|
+
* **A finer grain than an opportunity.** Audi asking for four prices in March
|
|
15
|
+
* and re-quoting in September is two RFQs on one opportunity. `opportunityId`
|
|
16
|
+
* is carried for reporting and is never used to decide competition.
|
|
17
|
+
*
|
|
18
|
+
* **A quote joins an RFQ via `rfqId` on the quote** (`quotes.create` /
|
|
19
|
+
* `quotes.update`), not through a method here. The join is validated to match
|
|
20
|
+
* the RFQ's customer — an RFQ is one OEM's request, and a foreign quote inside
|
|
21
|
+
* it would make "these compete with each other" false.
|
|
22
|
+
*
|
|
23
|
+
* **⚠ NEVER SUM AN RFQ'S QUOTES.** They are alternatives; three of four lose on
|
|
24
|
+
* every multi-scenario RFQ by construction. `range` (min/max) is the only honest
|
|
25
|
+
* summary and is deliberately provided instead of a total. For the same reason
|
|
26
|
+
* the RFQ carries no value column and no count column — both are computed at
|
|
27
|
+
* read.
|
|
28
|
+
*
|
|
29
|
+
* **⚠ Recording a win does not close the siblings.** Setting `status: 'won'`
|
|
30
|
+
* records WHICH quote won. Award-closes-losers (overlap + RFQ resolution, kept
|
|
31
|
+
* together) is behavior over quote lifecycles and ships in a later phase behind
|
|
32
|
+
* its own gate.
|
|
33
|
+
*
|
|
34
|
+
* **Replaces `quoteAsks` (5.30.0).** Same rows, same ids — `quote_ask` became
|
|
35
|
+
* the `rfq` table on 2026-10-24 and migrated rows kept their UUIDs, so an
|
|
36
|
+
* `askId` held from before resolves here unchanged. `quoteAsks` still works and
|
|
37
|
+
* still returns the old shape; it is deprecated and will be removed once every
|
|
38
|
+
* consumer is on this resource.
|
|
39
|
+
*/
|
|
40
|
+
export declare class RfqResource {
|
|
41
|
+
private readonly http;
|
|
42
|
+
constructor(http: HttpTransport);
|
|
43
|
+
/** RFQs with a `quoteCount` each — never an aggregate value. */
|
|
44
|
+
list(options?: ListRfqsOptions): Promise<SingleResponse<RfqSummary[]>>;
|
|
45
|
+
/**
|
|
46
|
+
* One RFQ with its competing quotes — each carrying its own lines and roll-up
|
|
47
|
+
* — plus the RFQ-level `range`.
|
|
48
|
+
*/
|
|
49
|
+
get(id: string): Promise<SingleResponse<RfqDetail>>;
|
|
50
|
+
/**
|
|
51
|
+
* Open a request. `rfqNumber` (`RFQ-YYYY-NNN`) is minted server-side from an
|
|
52
|
+
* atomic per-(tenant, year) counter.
|
|
53
|
+
*
|
|
54
|
+
* Send `receivedAt` when you know it: it is when the REQUEST arrived, which
|
|
55
|
+
* is not when the record was created. A caller minting an RFQ from an email
|
|
56
|
+
* that sat unread for two days should send the email's timestamp, or every
|
|
57
|
+
* response-time report measures the job rather than the response.
|
|
58
|
+
*
|
|
59
|
+
* `source` says what made this RFQ and defaults to `manual`. It is never
|
|
60
|
+
* nullable, deliberately — "was this minted by a machine?" has to stay
|
|
61
|
+
* answerable.
|
|
62
|
+
*/
|
|
63
|
+
create(input: CreateRfqInput, idempotencyKey?: string): Promise<SingleResponse<Rfq>>;
|
|
64
|
+
/**
|
|
65
|
+
* Update the editable fields and the status.
|
|
66
|
+
*
|
|
67
|
+
* `status: 'won'` requires `wonByQuoteId`, and the winner must be one of this
|
|
68
|
+
* RFQ's own quotes (422 otherwise) — the record of which one won must point
|
|
69
|
+
* inside the set that was competing. `status: 'merged'` requires
|
|
70
|
+
* `mergedIntoRfqId`; prefer {@link merge}, which takes it as its argument.
|
|
71
|
+
*
|
|
72
|
+
* `closedAt` is managed server-side, not supplied: stamped on the way out of
|
|
73
|
+
* `open`, cleared on the way back in.
|
|
74
|
+
*/
|
|
75
|
+
update(id: string, input: UpdateRfqInput): Promise<SingleResponse<Rfq>>;
|
|
76
|
+
/**
|
|
77
|
+
* Absorb this RFQ into another — the duplicate case, where two requests turn
|
|
78
|
+
* out to be one.
|
|
79
|
+
*
|
|
80
|
+
* The absorbed RFQ closes as `merged` and records WHAT absorbed it. Cancelling
|
|
81
|
+
* a duplicate instead loses that, which is what every consumer did before this
|
|
82
|
+
* existed: the row said "cancelled" and nothing said why or where the request
|
|
83
|
+
* went.
|
|
84
|
+
*
|
|
85
|
+
* Does not move quotes. One-directional and non-recursive.
|
|
86
|
+
*/
|
|
87
|
+
merge(id: string, mergedIntoRfqId: string): Promise<SingleResponse<Rfq>>;
|
|
88
|
+
/**
|
|
89
|
+
* Withdraw the request. Its quotes SURVIVE and compete with nothing again
|
|
90
|
+
* (`rfqId` is `ON DELETE SET NULL`) — deleting the request must never delete
|
|
91
|
+
* the offers made against it.
|
|
92
|
+
*
|
|
93
|
+
* Refused (422) once `won`, `lost` or `merged`: those rows are the record of
|
|
94
|
+
* how the request ended, and without them a closed sibling has no
|
|
95
|
+
* explanation. Cancel it instead. Also refused while other RFQs are merged
|
|
96
|
+
* into it.
|
|
97
|
+
*/
|
|
98
|
+
remove(id: string): Promise<SingleResponse<{
|
|
99
|
+
id: string;
|
|
100
|
+
rfqNumber: string;
|
|
101
|
+
}>>;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=rfqs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rfqs.d.ts","sourceRoot":"","sources":["../src/rfqs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EACV,GAAG,EACH,SAAS,EACT,UAAU,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,cAAc,EACf,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBAAa,WAAW;IACV,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,aAAa;IAEhD,gEAAgE;IAC1D,IAAI,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC,CAAC;IAa5E;;;OAGG;IACG,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IAOzD;;;;;;;;;;;;OAYG;IACG,MAAM,CACV,KAAK,EAAE,cAAc,EACrB,cAAc,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IAS/B;;;;;;;;;;OAUG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IAQ7E;;;;;;;;;;OAUG;IACG,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IAQ9E;;;;;;;;;OASG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAMrF"}
|
package/dist/rfqs.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RfqResource = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* RFQs — ONE customer request; the competing quotes are its options.
|
|
6
|
+
*
|
|
7
|
+
* The level ABOVE the quote. An OEM asks for several COMPETING groupings of the
|
|
8
|
+
* same parts and picks one ("give me four prices on A3 bumpers: base + S line,
|
|
9
|
+
* RS alone, wagon alone, all four"); each grouping is a `Quote`, and the RFQ is
|
|
10
|
+
* what makes that set nameable. Without it "the losers" is not a set the system
|
|
11
|
+
* can name, and a shared nullable `opportunityId` is not a grouping — it is
|
|
12
|
+
* nullable, it drifts, and an opportunity spans rounds. See the nextgen ADR
|
|
13
|
+
* `2026-08-05-multi-part-quotes.md`.
|
|
14
|
+
*
|
|
15
|
+
* **A finer grain than an opportunity.** Audi asking for four prices in March
|
|
16
|
+
* and re-quoting in September is two RFQs on one opportunity. `opportunityId`
|
|
17
|
+
* is carried for reporting and is never used to decide competition.
|
|
18
|
+
*
|
|
19
|
+
* **A quote joins an RFQ via `rfqId` on the quote** (`quotes.create` /
|
|
20
|
+
* `quotes.update`), not through a method here. The join is validated to match
|
|
21
|
+
* the RFQ's customer — an RFQ is one OEM's request, and a foreign quote inside
|
|
22
|
+
* it would make "these compete with each other" false.
|
|
23
|
+
*
|
|
24
|
+
* **⚠ NEVER SUM AN RFQ'S QUOTES.** They are alternatives; three of four lose on
|
|
25
|
+
* every multi-scenario RFQ by construction. `range` (min/max) is the only honest
|
|
26
|
+
* summary and is deliberately provided instead of a total. For the same reason
|
|
27
|
+
* the RFQ carries no value column and no count column — both are computed at
|
|
28
|
+
* read.
|
|
29
|
+
*
|
|
30
|
+
* **⚠ Recording a win does not close the siblings.** Setting `status: 'won'`
|
|
31
|
+
* records WHICH quote won. Award-closes-losers (overlap + RFQ resolution, kept
|
|
32
|
+
* together) is behavior over quote lifecycles and ships in a later phase behind
|
|
33
|
+
* its own gate.
|
|
34
|
+
*
|
|
35
|
+
* **Replaces `quoteAsks` (5.30.0).** Same rows, same ids — `quote_ask` became
|
|
36
|
+
* the `rfq` table on 2026-10-24 and migrated rows kept their UUIDs, so an
|
|
37
|
+
* `askId` held from before resolves here unchanged. `quoteAsks` still works and
|
|
38
|
+
* still returns the old shape; it is deprecated and will be removed once every
|
|
39
|
+
* consumer is on this resource.
|
|
40
|
+
*/
|
|
41
|
+
class RfqResource {
|
|
42
|
+
http;
|
|
43
|
+
constructor(http) {
|
|
44
|
+
this.http = http;
|
|
45
|
+
}
|
|
46
|
+
/** RFQs with a `quoteCount` each — never an aggregate value. */
|
|
47
|
+
async list(options) {
|
|
48
|
+
const query = {};
|
|
49
|
+
if (options?.status)
|
|
50
|
+
query.status = options.status;
|
|
51
|
+
if (options?.source)
|
|
52
|
+
query.source = options.source;
|
|
53
|
+
if (options?.customerCompanyId)
|
|
54
|
+
query.customerCompanyId = options.customerCompanyId;
|
|
55
|
+
if (options?.opportunityId)
|
|
56
|
+
query.opportunityId = options.opportunityId;
|
|
57
|
+
return this.http.request({
|
|
58
|
+
method: 'GET',
|
|
59
|
+
path: '/v1/rfqs',
|
|
60
|
+
query,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* One RFQ with its competing quotes — each carrying its own lines and roll-up
|
|
65
|
+
* — plus the RFQ-level `range`.
|
|
66
|
+
*/
|
|
67
|
+
async get(id) {
|
|
68
|
+
return this.http.request({
|
|
69
|
+
method: 'GET',
|
|
70
|
+
path: `/v1/rfqs/${encodeURIComponent(id)}`,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Open a request. `rfqNumber` (`RFQ-YYYY-NNN`) is minted server-side from an
|
|
75
|
+
* atomic per-(tenant, year) counter.
|
|
76
|
+
*
|
|
77
|
+
* Send `receivedAt` when you know it: it is when the REQUEST arrived, which
|
|
78
|
+
* is not when the record was created. A caller minting an RFQ from an email
|
|
79
|
+
* that sat unread for two days should send the email's timestamp, or every
|
|
80
|
+
* response-time report measures the job rather than the response.
|
|
81
|
+
*
|
|
82
|
+
* `source` says what made this RFQ and defaults to `manual`. It is never
|
|
83
|
+
* nullable, deliberately — "was this minted by a machine?" has to stay
|
|
84
|
+
* answerable.
|
|
85
|
+
*/
|
|
86
|
+
async create(input, idempotencyKey) {
|
|
87
|
+
return this.http.request({
|
|
88
|
+
method: 'POST',
|
|
89
|
+
path: '/v1/rfqs',
|
|
90
|
+
body: input,
|
|
91
|
+
idempotencyKey,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Update the editable fields and the status.
|
|
96
|
+
*
|
|
97
|
+
* `status: 'won'` requires `wonByQuoteId`, and the winner must be one of this
|
|
98
|
+
* RFQ's own quotes (422 otherwise) — the record of which one won must point
|
|
99
|
+
* inside the set that was competing. `status: 'merged'` requires
|
|
100
|
+
* `mergedIntoRfqId`; prefer {@link merge}, which takes it as its argument.
|
|
101
|
+
*
|
|
102
|
+
* `closedAt` is managed server-side, not supplied: stamped on the way out of
|
|
103
|
+
* `open`, cleared on the way back in.
|
|
104
|
+
*/
|
|
105
|
+
async update(id, input) {
|
|
106
|
+
return this.http.request({
|
|
107
|
+
method: 'PATCH',
|
|
108
|
+
path: `/v1/rfqs/${encodeURIComponent(id)}`,
|
|
109
|
+
body: input,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Absorb this RFQ into another — the duplicate case, where two requests turn
|
|
114
|
+
* out to be one.
|
|
115
|
+
*
|
|
116
|
+
* The absorbed RFQ closes as `merged` and records WHAT absorbed it. Cancelling
|
|
117
|
+
* a duplicate instead loses that, which is what every consumer did before this
|
|
118
|
+
* existed: the row said "cancelled" and nothing said why or where the request
|
|
119
|
+
* went.
|
|
120
|
+
*
|
|
121
|
+
* Does not move quotes. One-directional and non-recursive.
|
|
122
|
+
*/
|
|
123
|
+
async merge(id, mergedIntoRfqId) {
|
|
124
|
+
return this.http.request({
|
|
125
|
+
method: 'POST',
|
|
126
|
+
path: `/v1/rfqs/${encodeURIComponent(id)}/merge`,
|
|
127
|
+
body: { mergedIntoRfqId },
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Withdraw the request. Its quotes SURVIVE and compete with nothing again
|
|
132
|
+
* (`rfqId` is `ON DELETE SET NULL`) — deleting the request must never delete
|
|
133
|
+
* the offers made against it.
|
|
134
|
+
*
|
|
135
|
+
* Refused (422) once `won`, `lost` or `merged`: those rows are the record of
|
|
136
|
+
* how the request ended, and without them a closed sibling has no
|
|
137
|
+
* explanation. Cancel it instead. Also refused while other RFQs are merged
|
|
138
|
+
* into it.
|
|
139
|
+
*/
|
|
140
|
+
async remove(id) {
|
|
141
|
+
return this.http.request({
|
|
142
|
+
method: 'DELETE',
|
|
143
|
+
path: `/v1/rfqs/${encodeURIComponent(id)}`,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.RfqResource = RfqResource;
|
|
148
|
+
//# sourceMappingURL=rfqs.js.map
|
package/dist/rfqs.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rfqs.js","sourceRoot":"","sources":["../src/rfqs.ts"],"names":[],"mappings":";;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAa,WAAW;IACO;IAA7B,YAA6B,IAAmB;QAAnB,SAAI,GAAJ,IAAI,CAAe;IAAG,CAAC;IAEpD,gEAAgE;IAChE,KAAK,CAAC,IAAI,CAAC,OAAyB;QAClC,MAAM,KAAK,GAAuC,EAAE,CAAC;QACrD,IAAI,OAAO,EAAE,MAAM;YAAE,KAAK,CA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CAAC,OAAO,CAAsB;YAC5C,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,YAAY,kBAAkB,CAAC,EAAE,CAAC,QAAQ;YAChD,IAAI,EAAE,EAAE,eAAe,EAAE;SAC1B,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,MAAM,CAAC,EAAU;QACrB,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAoD;YAC1E,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,YAAY,kBAAkB,CAAC,EAAE,CAAC,EAAE;SAC3C,CAAC,CAAC;IACL,CAAC;CACF;AA3GD,kCA2GC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { HttpTransport } from './http';
|
|
2
|
+
import type { ScopeDimension, SingleResponse } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* The scope gate: who may see which records, once a tenant turns gating on.
|
|
5
|
+
*
|
|
6
|
+
* ONE implementation, shared. master-data can express the gate as an RLS policy
|
|
7
|
+
* because it owns the tables; OMSF and pm cannot — they have no RLS extension,
|
|
8
|
+
* so their gate is a clause in a query builder. A clause copied into a dozen
|
|
9
|
+
* call sites is a clause that gets missed in one of them, and a missed scope
|
|
10
|
+
* clause is a data leak rather than a cosmetic bug. So it lives here, with the
|
|
11
|
+
* fetching and caching it needs, and callers spread the result.
|
|
12
|
+
*
|
|
13
|
+
* TWO RULES SHAPE EVERYTHING, and both fail OPEN by deliberate decision
|
|
14
|
+
* (nextgen ADR 2026-09-14, decisions 3 and 4):
|
|
15
|
+
*
|
|
16
|
+
* - A user with NO assignment is unrestricted. On the day gating ships nobody
|
|
17
|
+
* has an assignment, and failing closed would lock out every user in the
|
|
18
|
+
* tenant at once — with the omission that caused it looking exactly like
|
|
19
|
+
* the feature working.
|
|
20
|
+
* - A record with NO scope is visible to everyone. Almost nothing is scoped
|
|
21
|
+
* at first, so failing closed would hide the entire dataset until someone
|
|
22
|
+
* hand-scoped it.
|
|
23
|
+
*
|
|
24
|
+
* The consequence, which is easy to misread as the gate being broken: gating
|
|
25
|
+
* restricts nothing until BOTH a user is assigned AND records are scoped.
|
|
26
|
+
*/
|
|
27
|
+
export interface UserScopeSets {
|
|
28
|
+
userId: string;
|
|
29
|
+
geographicScopeIds: string[];
|
|
30
|
+
productScopeIds: string[];
|
|
31
|
+
}
|
|
32
|
+
/** A Prisma-shaped `where` fragment. Deliberately a plain object: this package
|
|
33
|
+
* has no Prisma dependency and does not want one, and every consumer speaks
|
|
34
|
+
* this shape. Spread it into an existing `where`. */
|
|
35
|
+
export type ScopeGatePredicate = Record<string, unknown>;
|
|
36
|
+
export interface BuildScopeGateOptions {
|
|
37
|
+
/** Which dimensions the tenant has gating switched ON for. A dimension that
|
|
38
|
+
* is off contributes no clause at all. */
|
|
39
|
+
gatedDimensions: ScopeDimension[];
|
|
40
|
+
/** Column names, so a consumer whose table spells them differently can say
|
|
41
|
+
* so. Defaults match master-data and OMSF. */
|
|
42
|
+
columns?: {
|
|
43
|
+
geographic?: string;
|
|
44
|
+
product?: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Build the `where` fragment restricting a list to what this user may see.
|
|
49
|
+
*
|
|
50
|
+
* Returns an EMPTY object when the gate should not restrict — spreading `{}`
|
|
51
|
+
* into a `where` is a no-op, so a caller never has to branch on "is gating on".
|
|
52
|
+
*
|
|
53
|
+
* Per dimension, when gating is on for it AND the user has assignments:
|
|
54
|
+
*
|
|
55
|
+
* { OR: [ { <col>: null }, { <col>: { in: [...] } } ] }
|
|
56
|
+
*
|
|
57
|
+
* The `null` branch is rule 2 — an unscoped record is visible to everyone. Drop
|
|
58
|
+
* it and the gate hides almost the whole dataset on day one.
|
|
59
|
+
*
|
|
60
|
+
* Both dimensions gated produces an AND of the two, so a user must match on
|
|
61
|
+
* each. That is intersection, not union: someone assigned to Europe and to
|
|
62
|
+
* Doors sees European Doors work, which is what "my slice" means to the person
|
|
63
|
+
* asking for this feature.
|
|
64
|
+
*/
|
|
65
|
+
export declare function buildScopeGate(scopes: UserScopeSets | null, options: BuildScopeGateOptions): ScopeGatePredicate;
|
|
66
|
+
/** Clear everything. Exposed for tests and for a process that wants a clean
|
|
67
|
+
* slate; ordinary revocation is handled by the TTL. */
|
|
68
|
+
export declare function clearScopeCache(): void;
|
|
69
|
+
export declare class UserScopeResource {
|
|
70
|
+
private readonly http;
|
|
71
|
+
private readonly ttlMs;
|
|
72
|
+
private readonly cache;
|
|
73
|
+
constructor(http: HttpTransport, ttlMs?: number);
|
|
74
|
+
/** The caller's own sets, uncached. */
|
|
75
|
+
me(): Promise<SingleResponse<UserScopeSets>>;
|
|
76
|
+
/**
|
|
77
|
+
* The caller's own sets, cached for the TTL.
|
|
78
|
+
*
|
|
79
|
+
* Returns `null` rather than throwing when master-data cannot be reached.
|
|
80
|
+
* That is deliberate and it is the fail-open rule again: a gate that throws
|
|
81
|
+
* on a network blip takes every list in the app down, which is a worse
|
|
82
|
+
* outcome than briefly not restricting a feature that restricts nothing for
|
|
83
|
+
* most tenants anyway. Callers pass the null straight to buildScopeGate.
|
|
84
|
+
*/
|
|
85
|
+
mineCached(cacheKey: string): Promise<UserScopeSets | null>;
|
|
86
|
+
/** Drop a cached entry, so an admin who just changed an assignment can see it
|
|
87
|
+
* take effect without waiting out the TTL. */
|
|
88
|
+
invalidate(cacheKey: string): void;
|
|
89
|
+
/** Admin surface: every user in the tenant WITH an assignment. Users with
|
|
90
|
+
* none are absent — master-data does not know the tenant's roster, so the
|
|
91
|
+
* caller joins this against identity's user list. */
|
|
92
|
+
list(): Promise<{
|
|
93
|
+
data: UserScopeSets[];
|
|
94
|
+
}>;
|
|
95
|
+
get(userId: string): Promise<SingleResponse<UserScopeSets>>;
|
|
96
|
+
/** Replace a user's sets. Omit a dimension to leave it alone; send `[]` to
|
|
97
|
+
* clear it, which returns the user to unrestricted. */
|
|
98
|
+
set(userId: string, input: {
|
|
99
|
+
geographicScopeIds?: string[];
|
|
100
|
+
productScopeIds?: string[];
|
|
101
|
+
}, idempotencyKey?: string): Promise<SingleResponse<UserScopeSets>>;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=scopeGate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scopeGate.d.ts","sourceRoot":"","sources":["../src/scopeGate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED;;sDAEsD;AACtD,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEzD,MAAM,WAAW,qBAAqB;IACpC;+CAC2C;IAC3C,eAAe,EAAE,cAAc,EAAE,CAAC;IAClC;mDAC+C;IAC/C,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACrD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,aAAa,GAAG,IAAI,EAC5B,OAAO,EAAE,qBAAqB,GAC7B,kBAAkB,CAyBpB;AAiCD;wDACwD;AACxD,wBAAgB,eAAe,IAAI,IAAI,CAEtC;AAED,qBAAa,iBAAiB;IAI1B,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAJxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAc;gBAGjB,IAAI,EAAE,aAAa,EACnB,KAAK,GAAE,MAAe;IAGzC,uCAAuC;IACjC,EAAE,IAAI,OAAO,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;IAOlD;;;;;;;;OAQG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAejE;mDAC+C;IAC/C,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIlC;;0DAEsD;IAChD,IAAI,IAAI,OAAO,CAAC;QAAE,IAAI,EAAE,aAAa,EAAE,CAAA;KAAE,CAAC;IAO1C,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;IAOjE;4DACwD;IAClD,GAAG,CACP,MAAM,EAAE,MAAM,EACd,KAAK,EAAE;QAAE,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,EACpE,cAAc,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;CAQ1C"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserScopeResource = void 0;
|
|
4
|
+
exports.buildScopeGate = buildScopeGate;
|
|
5
|
+
exports.clearScopeCache = clearScopeCache;
|
|
6
|
+
/**
|
|
7
|
+
* Build the `where` fragment restricting a list to what this user may see.
|
|
8
|
+
*
|
|
9
|
+
* Returns an EMPTY object when the gate should not restrict — spreading `{}`
|
|
10
|
+
* into a `where` is a no-op, so a caller never has to branch on "is gating on".
|
|
11
|
+
*
|
|
12
|
+
* Per dimension, when gating is on for it AND the user has assignments:
|
|
13
|
+
*
|
|
14
|
+
* { OR: [ { <col>: null }, { <col>: { in: [...] } } ] }
|
|
15
|
+
*
|
|
16
|
+
* The `null` branch is rule 2 — an unscoped record is visible to everyone. Drop
|
|
17
|
+
* it and the gate hides almost the whole dataset on day one.
|
|
18
|
+
*
|
|
19
|
+
* Both dimensions gated produces an AND of the two, so a user must match on
|
|
20
|
+
* each. That is intersection, not union: someone assigned to Europe and to
|
|
21
|
+
* Doors sees European Doors work, which is what "my slice" means to the person
|
|
22
|
+
* asking for this feature.
|
|
23
|
+
*/
|
|
24
|
+
function buildScopeGate(scopes, options) {
|
|
25
|
+
// No scope information at all — treat as unrestricted rather than guessing.
|
|
26
|
+
// A resolver that failed is the likely cause, and failing a read closed on a
|
|
27
|
+
// network blip would take the app down for everyone.
|
|
28
|
+
if (!scopes)
|
|
29
|
+
return {};
|
|
30
|
+
const geoColumn = options.columns?.geographic ?? 'geographicScopeId';
|
|
31
|
+
const productColumn = options.columns?.product ?? 'productScopeId';
|
|
32
|
+
const clauses = [];
|
|
33
|
+
if (options.gatedDimensions.includes('geographic') && scopes.geographicScopeIds.length > 0) {
|
|
34
|
+
clauses.push({
|
|
35
|
+
OR: [{ [geoColumn]: null }, { [geoColumn]: { in: [...scopes.geographicScopeIds] } }],
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (options.gatedDimensions.includes('product') && scopes.productScopeIds.length > 0) {
|
|
39
|
+
clauses.push({
|
|
40
|
+
OR: [{ [productColumn]: null }, { [productColumn]: { in: [...scopes.productScopeIds] } }],
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (clauses.length === 0)
|
|
44
|
+
return {};
|
|
45
|
+
if (clauses.length === 1)
|
|
46
|
+
return clauses[0];
|
|
47
|
+
return { AND: clauses };
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The caller's own scope sets, cached briefly.
|
|
51
|
+
*
|
|
52
|
+
* The cache exists because the gate needs this on EVERY request in OMSF and pm,
|
|
53
|
+
* and a cross-service hop in front of every list query is the one place latency
|
|
54
|
+
* is most visible. master-data itself needs none of this — its tables are local.
|
|
55
|
+
*
|
|
56
|
+
* **The TTL is a revocation window.** Removing someone's scope does not take
|
|
57
|
+
* effect until their entry expires. 60 seconds is the agreed value: short
|
|
58
|
+
* enough that "I removed her access and she can still see it" never becomes a
|
|
59
|
+
* support call, long enough that a warm Lambda makes roughly one call per user
|
|
60
|
+
* per container lifetime.
|
|
61
|
+
*
|
|
62
|
+
* Keyed by tenant AND user: a container serves many callers, and the whole
|
|
63
|
+
* point of the gate is that they get different answers.
|
|
64
|
+
*/
|
|
65
|
+
/**
|
|
66
|
+
* MODULE-LEVEL, not per-instance, and that is not an optimization — it is the
|
|
67
|
+
* only thing that makes the cache work at all.
|
|
68
|
+
*
|
|
69
|
+
* OMSF constructs a fresh `MasterDataClient` on every call, because the auth
|
|
70
|
+
* token comes from the request context. A cache living on the resource instance
|
|
71
|
+
* would therefore be born and discarded inside a single request and never once
|
|
72
|
+
* be read, while looking entirely correct. Hoisting it to the module makes the
|
|
73
|
+
* lifetime what the design assumes: the container's.
|
|
74
|
+
*
|
|
75
|
+
* Safe to share because every key carries the tenant AND the user — two callers
|
|
76
|
+
* can never collide, which is the whole point of the gate.
|
|
77
|
+
*/
|
|
78
|
+
const scopeCache = new Map();
|
|
79
|
+
/** Clear everything. Exposed for tests and for a process that wants a clean
|
|
80
|
+
* slate; ordinary revocation is handled by the TTL. */
|
|
81
|
+
function clearScopeCache() {
|
|
82
|
+
scopeCache.clear();
|
|
83
|
+
}
|
|
84
|
+
class UserScopeResource {
|
|
85
|
+
http;
|
|
86
|
+
ttlMs;
|
|
87
|
+
cache = scopeCache;
|
|
88
|
+
constructor(http, ttlMs = 60_000) {
|
|
89
|
+
this.http = http;
|
|
90
|
+
this.ttlMs = ttlMs;
|
|
91
|
+
}
|
|
92
|
+
/** The caller's own sets, uncached. */
|
|
93
|
+
async me() {
|
|
94
|
+
return this.http.request({
|
|
95
|
+
method: 'GET',
|
|
96
|
+
path: '/v1/user-scopes/me',
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The caller's own sets, cached for the TTL.
|
|
101
|
+
*
|
|
102
|
+
* Returns `null` rather than throwing when master-data cannot be reached.
|
|
103
|
+
* That is deliberate and it is the fail-open rule again: a gate that throws
|
|
104
|
+
* on a network blip takes every list in the app down, which is a worse
|
|
105
|
+
* outcome than briefly not restricting a feature that restricts nothing for
|
|
106
|
+
* most tenants anyway. Callers pass the null straight to buildScopeGate.
|
|
107
|
+
*/
|
|
108
|
+
async mineCached(cacheKey) {
|
|
109
|
+
const hit = this.cache.get(cacheKey);
|
|
110
|
+
if (hit && Date.now() - hit.at < this.ttlMs)
|
|
111
|
+
return hit.value;
|
|
112
|
+
try {
|
|
113
|
+
const response = await this.me();
|
|
114
|
+
this.cache.set(cacheKey, { at: Date.now(), value: response.data });
|
|
115
|
+
return response.data;
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
// Serve a stale entry if we have one — it is closer to the truth than
|
|
119
|
+
// nothing, and it keeps the revocation window bounded to the outage.
|
|
120
|
+
return hit ? hit.value : null;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/** Drop a cached entry, so an admin who just changed an assignment can see it
|
|
124
|
+
* take effect without waiting out the TTL. */
|
|
125
|
+
invalidate(cacheKey) {
|
|
126
|
+
this.cache.delete(cacheKey);
|
|
127
|
+
}
|
|
128
|
+
/** Admin surface: every user in the tenant WITH an assignment. Users with
|
|
129
|
+
* none are absent — master-data does not know the tenant's roster, so the
|
|
130
|
+
* caller joins this against identity's user list. */
|
|
131
|
+
async list() {
|
|
132
|
+
return this.http.request({
|
|
133
|
+
method: 'GET',
|
|
134
|
+
path: '/v1/user-scopes',
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
async get(userId) {
|
|
138
|
+
return this.http.request({
|
|
139
|
+
method: 'GET',
|
|
140
|
+
path: `/v1/user-scopes/${encodeURIComponent(userId)}`,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/** Replace a user's sets. Omit a dimension to leave it alone; send `[]` to
|
|
144
|
+
* clear it, which returns the user to unrestricted. */
|
|
145
|
+
async set(userId, input, idempotencyKey) {
|
|
146
|
+
return this.http.request({
|
|
147
|
+
method: 'PUT',
|
|
148
|
+
path: `/v1/user-scopes/${encodeURIComponent(userId)}`,
|
|
149
|
+
body: input,
|
|
150
|
+
idempotencyKey,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.UserScopeResource = UserScopeResource;
|
|
155
|
+
//# sourceMappingURL=scopeGate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scopeGate.js","sourceRoot":"","sources":["../src/scopeGate.ts"],"names":[],"mappings":";;;AAkEA,wCA4BC;AAmCD,0CAEC;AAnFD;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,cAAc,CAC5B,MAA4B,EAC5B,OAA8B;IAE9B,4EAA4E;IAC5E,6EAA6E;IAC7E,qDAAqD;IACrD,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IAEvB,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,EAAE,UAAU,IAAI,mBAAmB,CAAC;IACrE,MAAM,aAAa,GAAG,OAAO,CAAC,OAAO,EAAE,OAAO,IAAI,gBAAgB,CAAC;IAEnE,MAAM,OAAO,GAA8B,EAAE,CAAC;IAE9C,IAAI,OAAO,CAAC,eAAe,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,MAAM,CAAC,kBAAkB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3F,OAAO,CAAC,IAAI,CAAC;YACX,EAAE,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,kBAAkB,CAAC,EAAE,EAAE,CAAC;SACrF,CAAC,CAAC;IACL,CAAC;IACD,IAAI,OAAO,CAAC,eAAe,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrF,OAAO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