@unboundcx/sdk 4.13.151 → 4.13.153
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/index.js +3 -0
- package/package.json +1 -1
- package/services/discountApprovals.js +120 -0
package/index.js
CHANGED
|
@@ -20,6 +20,7 @@ import { ContentService } from './services/content.js';
|
|
|
20
20
|
import { VerificationService } from './services/verification.js';
|
|
21
21
|
import { PortalsService } from './services/portals.js';
|
|
22
22
|
import { DealRegistrationsService } from './services/dealRegistrations.js';
|
|
23
|
+
import { DiscountApprovalsService } from './services/discountApprovals.js';
|
|
23
24
|
import { SipEndpointsService } from './services/sipEndpoints.js';
|
|
24
25
|
import { RingGroupsService } from './services/ringGroups.js';
|
|
25
26
|
import { LineGroupsService } from './services/lineGroups.js';
|
|
@@ -133,6 +134,7 @@ class UnboundSDK extends BaseSDK {
|
|
|
133
134
|
this.verification = new VerificationService(this);
|
|
134
135
|
this.portals = new PortalsService(this);
|
|
135
136
|
this.dealRegistrations = new DealRegistrationsService(this);
|
|
137
|
+
this.discountApprovals = new DiscountApprovalsService(this);
|
|
136
138
|
this.sipEndpoints = new SipEndpointsService(this);
|
|
137
139
|
this.ringGroups = new RingGroupsService(this);
|
|
138
140
|
this.lineGroups = new LineGroupsService(this);
|
|
@@ -347,6 +349,7 @@ export {
|
|
|
347
349
|
export { VerificationService } from './services/verification.js';
|
|
348
350
|
export { PortalsService } from './services/portals.js';
|
|
349
351
|
export { DealRegistrationsService } from './services/dealRegistrations.js';
|
|
352
|
+
export { DiscountApprovalsService } from './services/discountApprovals.js';
|
|
350
353
|
export { SipEndpointsService } from './services/sipEndpoints.js';
|
|
351
354
|
export { RingGroupsService } from './services/ringGroups.js';
|
|
352
355
|
export { LineGroupsService } from './services/lineGroups.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unboundcx/sdk",
|
|
3
|
-
"version": "4.13.
|
|
3
|
+
"version": "4.13.153",
|
|
4
4
|
"description": "Official JavaScript SDK for the Unbound API - A comprehensive toolkit for integrating with Unbound's communication, AI, and data management services",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { internalRequest } from '../base.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* opportunity-product-options-plan.md r18 §Routes & scopes decide route /
|
|
5
|
+
* §SDK ("DiscountApprovalsService.decide(id, {decision, decisionNote})
|
|
6
|
+
* ... built and published in P3"). Staff-only — endpoints live under
|
|
7
|
+
* `/discount-approvals/` (checkApiAuth), separate from the generic
|
|
8
|
+
* `discountApprovals` object (which is isCreateable=0/isEditable=0 and so
|
|
9
|
+
* has no CRUD surface through `sdk.objects.*` at all). The partner portal
|
|
10
|
+
* is NOT a consumer of this package — its equivalent discount-request/
|
|
11
|
+
* withdraw methods live in app1-customer-portals' own local
|
|
12
|
+
* `portalDeals.mixin.js`, never here.
|
|
13
|
+
*/
|
|
14
|
+
export class DiscountApprovalsService {
|
|
15
|
+
constructor(sdk) {
|
|
16
|
+
this.sdk = sdk;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Approve, reject, or withdraw a pending discount-approval request.
|
|
21
|
+
* `deciderId` is never a parameter here — the server always uses the
|
|
22
|
+
* calling session's own authenticated user id (Invariant 9).
|
|
23
|
+
* @param {string} id - discountApprovals record id
|
|
24
|
+
* @param {Object} options
|
|
25
|
+
* @param {'approved'|'rejected'|'withdrawn'} options.decision
|
|
26
|
+
* @param {string} [options.decisionNote]
|
|
27
|
+
* @returns {Promise<Object>} { id, status, rollup }
|
|
28
|
+
*/
|
|
29
|
+
async decide(id, { decision, decisionNote } = {}) {
|
|
30
|
+
this.sdk.validateParams(
|
|
31
|
+
{ id, decision, decisionNote },
|
|
32
|
+
{
|
|
33
|
+
id: { type: 'string', required: true },
|
|
34
|
+
decision: { type: 'string', required: true },
|
|
35
|
+
decisionNote: { type: 'string', required: false },
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
if (!['approved', 'rejected', 'withdrawn'].includes(decision)) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
"decision must be one of 'approved', 'rejected', 'withdrawn'",
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
const body = { decision };
|
|
44
|
+
if (decisionNote !== undefined) body.decisionNote = decisionNote;
|
|
45
|
+
return internalRequest(this.sdk, `/discount-approvals/${id}/decide`, 'POST', {
|
|
46
|
+
body,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Round-2 fix 1 (margin-in-discount-popover) -- numbers-free D9 dry-run
|
|
52
|
+
* for one or more lines on an opportunity. Never locks or writes
|
|
53
|
+
* anything server-side. `marginPercent` is included on each returned
|
|
54
|
+
* line ONLY when the calling session holds `crm:margin:view` -- this
|
|
55
|
+
* method never asks for it and can't force it; everyone else gets
|
|
56
|
+
* `belowMarginFloor` only.
|
|
57
|
+
* @param {string} opportunityId
|
|
58
|
+
* @param {Array<{lineId: string, price?: number, discountType?: 'percent'|'amount', discountValue?: number}>} lines
|
|
59
|
+
* @returns {Promise<{lines: Array<{lineId: string, belowMarginFloor: boolean, marginPercent?: number}>}>}
|
|
60
|
+
*/
|
|
61
|
+
async marginPreview(opportunityId, lines) {
|
|
62
|
+
this.sdk.validateParams(
|
|
63
|
+
{ opportunityId, lines },
|
|
64
|
+
{
|
|
65
|
+
opportunityId: { type: 'string', required: true },
|
|
66
|
+
lines: { type: 'array', required: true },
|
|
67
|
+
},
|
|
68
|
+
);
|
|
69
|
+
return internalRequest(
|
|
70
|
+
this.sdk,
|
|
71
|
+
'/discount-approvals/margin-preview',
|
|
72
|
+
'POST',
|
|
73
|
+
{ body: { opportunityId, lines } },
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Round-2 fix 3 (bulk discount) -- one `discountType`/`discountValue`
|
|
79
|
+
* applied to every line in `lineIds`, through ONE `evaluateLineWrite`
|
|
80
|
+
* call -> at most one `discountApprovals` row for the whole selection,
|
|
81
|
+
* never one request per line. `discountValue` with
|
|
82
|
+
* `discountType='amount'` is a PER-UNIT amount off each selected
|
|
83
|
+
* line's own listPrice (the same semantics a single-line
|
|
84
|
+
* `discountType='amount'` edit already has) -- never prorated across
|
|
85
|
+
* the selection. Lines that are closed/locked, already have a pending
|
|
86
|
+
* discount request, or aren't found are skipped server-side and
|
|
87
|
+
* reported back in `skipped`, never merged or silently dropped.
|
|
88
|
+
* @param {string} opportunityId
|
|
89
|
+
* @param {string[]} lineIds
|
|
90
|
+
* @param {Object} options
|
|
91
|
+
* @param {'percent'|'amount'} options.discountType
|
|
92
|
+
* @param {number} options.discountValue
|
|
93
|
+
* @param {string} [options.reason]
|
|
94
|
+
* @returns {Promise<{opportunityId: string, committed: string[], held: string[], skipped: Array<{lineId: string, reason: string}>, skippedCount: number, rollup: Object}>}
|
|
95
|
+
*/
|
|
96
|
+
async bulkDiscount(opportunityId, lineIds, { discountType, discountValue, reason } = {}) {
|
|
97
|
+
this.sdk.validateParams(
|
|
98
|
+
{ opportunityId, lineIds, discountType, discountValue },
|
|
99
|
+
{
|
|
100
|
+
opportunityId: { type: 'string', required: true },
|
|
101
|
+
lineIds: { type: 'array', required: true },
|
|
102
|
+
discountType: { type: 'string', required: true },
|
|
103
|
+
discountValue: { type: 'number', required: true },
|
|
104
|
+
},
|
|
105
|
+
);
|
|
106
|
+
if (!['percent', 'amount'].includes(discountType)) {
|
|
107
|
+
throw new Error("discountType must be one of 'percent', 'amount'");
|
|
108
|
+
}
|
|
109
|
+
const body = { opportunityId, lineIds, discountType, discountValue };
|
|
110
|
+
if (reason !== undefined) body.reason = reason;
|
|
111
|
+
return internalRequest(
|
|
112
|
+
this.sdk,
|
|
113
|
+
'/discount-approvals/bulk-discount',
|
|
114
|
+
'POST',
|
|
115
|
+
{ body },
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export default DiscountApprovalsService;
|