@unboundcx/sdk 4.13.150 → 4.13.152
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 +17 -0
- package/lib/simRules.js +58 -0
- package/package.json +1 -1
- package/services/discountApprovals.js +51 -0
- package/services/internal/SimService.js +204 -0
- package/services/internal/index.js +19 -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';
|
|
@@ -63,6 +64,8 @@ import {
|
|
|
63
64
|
DataExportService,
|
|
64
65
|
} from './services/dataImport.js';
|
|
65
66
|
import { VoicemailDropsService } from './services/voicemailDrops.js';
|
|
67
|
+
import { InternalService } from './services/internal/index.js';
|
|
68
|
+
import { simRules } from './lib/simRules.js';
|
|
66
69
|
|
|
67
70
|
class UnboundSDK extends BaseSDK {
|
|
68
71
|
constructor(options = {}) {
|
|
@@ -131,6 +134,7 @@ class UnboundSDK extends BaseSDK {
|
|
|
131
134
|
this.verification = new VerificationService(this);
|
|
132
135
|
this.portals = new PortalsService(this);
|
|
133
136
|
this.dealRegistrations = new DealRegistrationsService(this);
|
|
137
|
+
this.discountApprovals = new DiscountApprovalsService(this);
|
|
134
138
|
this.sipEndpoints = new SipEndpointsService(this);
|
|
135
139
|
this.ringGroups = new RingGroupsService(this);
|
|
136
140
|
this.lineGroups = new LineGroupsService(this);
|
|
@@ -172,6 +176,8 @@ class UnboundSDK extends BaseSDK {
|
|
|
172
176
|
this.dataImport = new DataImportService(this);
|
|
173
177
|
this.dataExport = new DataExportService(this);
|
|
174
178
|
this.voicemailDrops = new VoicemailDropsService(this);
|
|
179
|
+
this.internal = new InternalService(this);
|
|
180
|
+
this.simRules = simRules;
|
|
175
181
|
|
|
176
182
|
// Add additional services that might be missing
|
|
177
183
|
this._initializeAdditionalServices();
|
|
@@ -343,6 +349,7 @@ export {
|
|
|
343
349
|
export { VerificationService } from './services/verification.js';
|
|
344
350
|
export { PortalsService } from './services/portals.js';
|
|
345
351
|
export { DealRegistrationsService } from './services/dealRegistrations.js';
|
|
352
|
+
export { DiscountApprovalsService } from './services/discountApprovals.js';
|
|
346
353
|
export { SipEndpointsService } from './services/sipEndpoints.js';
|
|
347
354
|
export { RingGroupsService } from './services/ringGroups.js';
|
|
348
355
|
export { LineGroupsService } from './services/lineGroups.js';
|
|
@@ -401,3 +408,13 @@ export {
|
|
|
401
408
|
} from './services/voicemailDrops.js';
|
|
402
409
|
export { BaseSDK } from './base.js';
|
|
403
410
|
export { layoutJourney, MAX_LANES as JOURNEY_LAYOUT_MAX_LANES } from './lib/journeyLayout.js';
|
|
411
|
+
export { InternalService } from './services/internal/index.js';
|
|
412
|
+
export { InternalSimService } from './services/internal/SimService.js';
|
|
413
|
+
export {
|
|
414
|
+
simRules,
|
|
415
|
+
SIM_NUMBER_RE,
|
|
416
|
+
SIM_EMAIL_DOMAIN,
|
|
417
|
+
isSimNumber,
|
|
418
|
+
isSimEmail,
|
|
419
|
+
simModeKey,
|
|
420
|
+
} from './lib/simRules.js';
|
package/lib/simRules.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/* eslint-disable indent */
|
|
2
|
+
/* eslint-disable prettier/prettier */
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Shared simulator identification rules (simulator-plan.md §5).
|
|
6
|
+
*
|
|
7
|
+
* Pure, dependency-free. Used by app1-api, app1-queue-messaging and
|
|
8
|
+
* app1-simulator to recognize sim traffic by PATTERN, never by a flag:
|
|
9
|
+
* +1555NXXXXXX (NPA 555 is unassignable in the NANP) and @sim.invalid
|
|
10
|
+
* (RFC 2606 reserved domain). Fail closed everywhere these are consulted —
|
|
11
|
+
* an address that doesn't match is treated as real, never routed to a sink.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// NPA 555, 7 trailing digits -- no real subscriber can hold one.
|
|
15
|
+
export const SIM_NUMBER_RE = /^\+1555\d{7}$/;
|
|
16
|
+
|
|
17
|
+
export const SIM_EMAIL_DOMAIN = 'sim.invalid';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {string} e164
|
|
21
|
+
* @returns {boolean}
|
|
22
|
+
*/
|
|
23
|
+
export function isSimNumber(e164) {
|
|
24
|
+
return typeof e164 === 'string' && SIM_NUMBER_RE.test(e164);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {string} addr
|
|
29
|
+
* @returns {boolean}
|
|
30
|
+
*/
|
|
31
|
+
export function isSimEmail(addr) {
|
|
32
|
+
if (typeof addr !== 'string') return false;
|
|
33
|
+
const at = addr.lastIndexOf('@');
|
|
34
|
+
if (at === -1) return false;
|
|
35
|
+
return addr.slice(at + 1).toLowerCase() === SIM_EMAIL_DOMAIN;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Redis key for the per-account SIM MODE choke point (simulator-plan.md
|
|
40
|
+
* §5, "Account SIM MODE"). Unprefixed -- callers in queue-messaging must
|
|
41
|
+
* use a Redis client without its `queue-messaging:` keyPrefix to read it.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} accountId
|
|
44
|
+
* @returns {string}
|
|
45
|
+
*/
|
|
46
|
+
export function simModeKey(accountId) {
|
|
47
|
+
return `sim:mode:${accountId}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const simRules = {
|
|
51
|
+
SIM_NUMBER_RE,
|
|
52
|
+
SIM_EMAIL_DOMAIN,
|
|
53
|
+
isSimNumber,
|
|
54
|
+
isSimEmail,
|
|
55
|
+
simModeKey,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export default simRules;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unboundcx/sdk",
|
|
3
|
-
"version": "4.13.
|
|
3
|
+
"version": "4.13.152",
|
|
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,51 @@
|
|
|
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
|
+
export default DiscountApprovalsService;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { internalRequest } from '../../base.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* app1-simulator internal surface (simulator-plan.md §14 routes B, C, G).
|
|
5
|
+
* Internal-API-key auth: the caller sets `sdk.token` to a JWT signed with
|
|
6
|
+
* `JWT_INTERNAL_API_KEY` (same mechanism as `buildInternalApiAuth` /
|
|
7
|
+
* `InternalAuthService.issueBotUserToken` in app1-ai-bot) before calling
|
|
8
|
+
* these methods. Every route is server-side gated by `SIM_ENABLED` and,
|
|
9
|
+
* for mode/dids/purge, `SIM_ALLOWED_ACCOUNTS` + sim-pattern enforcement.
|
|
10
|
+
*
|
|
11
|
+
* Request/response contract: services/internal/SIM_CONTRACT.md.
|
|
12
|
+
*/
|
|
13
|
+
export class InternalSimService {
|
|
14
|
+
constructor(sdk) {
|
|
15
|
+
this.sdk = sdk;
|
|
16
|
+
this.mode = {
|
|
17
|
+
/**
|
|
18
|
+
* POST /internal/sim/mode -- turn on SIM MODE for an account (every
|
|
19
|
+
* carrier egress for that account sinks/rejects while set).
|
|
20
|
+
* @param {object} args
|
|
21
|
+
* @param {string} args.accountId
|
|
22
|
+
* @param {number} [args.ttlSeconds=120]
|
|
23
|
+
* @returns {Promise<{accountId: string, mode: 'on', expiresAt: string}>}
|
|
24
|
+
*/
|
|
25
|
+
set: async ({ accountId, ttlSeconds } = {}) => {
|
|
26
|
+
this.sdk.validateParams(
|
|
27
|
+
{ accountId, ttlSeconds },
|
|
28
|
+
{
|
|
29
|
+
accountId: { type: 'string', required: true },
|
|
30
|
+
ttlSeconds: { type: 'number', required: false },
|
|
31
|
+
},
|
|
32
|
+
);
|
|
33
|
+
return internalRequest(this.sdk, '/internal/sim/mode', 'POST', {
|
|
34
|
+
body: { accountId, ttlSeconds },
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* DELETE /internal/sim/mode -- clear SIM MODE for an account.
|
|
40
|
+
* @param {object} args
|
|
41
|
+
* @param {string} args.accountId
|
|
42
|
+
* @returns {Promise<{accountId: string, mode: 'off'}>}
|
|
43
|
+
*/
|
|
44
|
+
clear: async ({ accountId } = {}) => {
|
|
45
|
+
this.sdk.validateParams(
|
|
46
|
+
{ accountId },
|
|
47
|
+
{ accountId: { type: 'string', required: true } },
|
|
48
|
+
);
|
|
49
|
+
return internalRequest(this.sdk, '/internal/sim/mode', 'DELETE', {
|
|
50
|
+
query: { accountId },
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* GET /internal/sim/mode -- current SIM MODE state for an account.
|
|
56
|
+
* @param {object} args
|
|
57
|
+
* @param {string} args.accountId
|
|
58
|
+
* @returns {Promise<{accountId: string, mode: 'on'|'off', expiresAt: string|null}>}
|
|
59
|
+
*/
|
|
60
|
+
get: async ({ accountId } = {}) => {
|
|
61
|
+
this.sdk.validateParams(
|
|
62
|
+
{ accountId },
|
|
63
|
+
{ accountId: { type: 'string', required: true } },
|
|
64
|
+
);
|
|
65
|
+
return internalRequest(this.sdk, '/internal/sim/mode', 'GET', {
|
|
66
|
+
query: { accountId },
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
this.dids = {
|
|
72
|
+
/**
|
|
73
|
+
* POST /internal/sim/dids -- provision sim DIDs (pattern-enforced,
|
|
74
|
+
* no Telnyx). simulator-plan.md §7.3.
|
|
75
|
+
* @param {object} args
|
|
76
|
+
* @param {string} args.accountId
|
|
77
|
+
* @param {Array<{phoneNumber: string, voiceApp?: string, voiceAppMetaData?: string, textApp?: string, textAppMetaData?: string}>} args.numbers
|
|
78
|
+
* @returns {Promise<{created: Array<object>}>}
|
|
79
|
+
*/
|
|
80
|
+
create: async ({ accountId, numbers } = {}) => {
|
|
81
|
+
this.sdk.validateParams(
|
|
82
|
+
{ accountId, numbers },
|
|
83
|
+
{
|
|
84
|
+
accountId: { type: 'string', required: true },
|
|
85
|
+
numbers: { type: 'array', required: true },
|
|
86
|
+
},
|
|
87
|
+
);
|
|
88
|
+
return internalRequest(this.sdk, '/internal/sim/dids', 'POST', {
|
|
89
|
+
body: { accountId, numbers },
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* GET /internal/sim/dids -- list sim DIDs provisioned for an account.
|
|
95
|
+
* @param {object} args
|
|
96
|
+
* @param {string} args.accountId
|
|
97
|
+
* @returns {Promise<{dids: Array<object>}>}
|
|
98
|
+
*/
|
|
99
|
+
list: async ({ accountId } = {}) => {
|
|
100
|
+
this.sdk.validateParams(
|
|
101
|
+
{ accountId },
|
|
102
|
+
{ accountId: { type: 'string', required: true } },
|
|
103
|
+
);
|
|
104
|
+
return internalRequest(this.sdk, '/internal/sim/dids', 'GET', {
|
|
105
|
+
query: { accountId },
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* POST /internal/sim/purge -- tear down everything a run created, pattern-
|
|
113
|
+
* and run-scoped only (simulator-plan.md §7.1, §8).
|
|
114
|
+
* @param {object} args
|
|
115
|
+
* @param {string} args.accountId
|
|
116
|
+
* @param {string} [args.runId]
|
|
117
|
+
* @param {boolean} [args.dryRun=false]
|
|
118
|
+
* @returns {Promise<{dryRun: boolean, counts: Object<string, number>, leaks?: Array<object>}>}
|
|
119
|
+
*/
|
|
120
|
+
async purge({ accountId, runId, dryRun } = {}) {
|
|
121
|
+
this.sdk.validateParams(
|
|
122
|
+
{ accountId, runId, dryRun },
|
|
123
|
+
{
|
|
124
|
+
accountId: { type: 'string', required: true },
|
|
125
|
+
runId: { type: 'string', required: false },
|
|
126
|
+
dryRun: { type: 'boolean', required: false },
|
|
127
|
+
},
|
|
128
|
+
);
|
|
129
|
+
return internalRequest(this.sdk, '/internal/sim/purge', 'POST', {
|
|
130
|
+
body: { accountId, runId, dryRun },
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* POST /internal/auth/sim-user-token -- agent bearer token without a
|
|
136
|
+
* password/email (clone of bot-user-token, simulator-plan.md §14-B).
|
|
137
|
+
* @param {object} args
|
|
138
|
+
* @param {string} args.userId
|
|
139
|
+
* @param {string} args.accountId
|
|
140
|
+
* @returns {Promise<{token: string, expiresAt?: string}>}
|
|
141
|
+
*/
|
|
142
|
+
async userToken({ userId, accountId } = {}) {
|
|
143
|
+
this.sdk.validateParams(
|
|
144
|
+
{ userId, accountId },
|
|
145
|
+
{
|
|
146
|
+
userId: { type: 'string', required: true },
|
|
147
|
+
accountId: { type: 'string', required: true },
|
|
148
|
+
},
|
|
149
|
+
);
|
|
150
|
+
return internalRequest(this.sdk, '/internal/auth/sim-user-token', 'POST', {
|
|
151
|
+
body: { userId, accountId },
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* POST /internal/sms/sim-inbound -- inject an inbound SMS/MMS through the
|
|
157
|
+
* real `inboundSmsMms` routine (never the unverified public webhook).
|
|
158
|
+
* `to` must be a `carrier='sim'` DID; `from` must match `SIM_NUMBER_RE`.
|
|
159
|
+
* @param {object} args
|
|
160
|
+
* @param {string} args.to
|
|
161
|
+
* @param {string} args.from
|
|
162
|
+
* @param {string} [args.text]
|
|
163
|
+
* @param {string[]} [args.mediaUrls]
|
|
164
|
+
* @returns {Promise<{taskId?: string, messageId: string}>}
|
|
165
|
+
*/
|
|
166
|
+
async smsInbound({ to, from, text, mediaUrls } = {}) {
|
|
167
|
+
this.sdk.validateParams(
|
|
168
|
+
{ to, from, text, mediaUrls },
|
|
169
|
+
{
|
|
170
|
+
to: { type: 'string', required: true },
|
|
171
|
+
from: { type: 'string', required: true },
|
|
172
|
+
text: { type: 'string', required: false },
|
|
173
|
+
mediaUrls: { type: 'array', required: false },
|
|
174
|
+
},
|
|
175
|
+
);
|
|
176
|
+
return internalRequest(this.sdk, '/internal/sms/sim-inbound', 'POST', {
|
|
177
|
+
body: { to, from, text, mediaUrls },
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* POST /internal/email/sim-inbound -- inject an inbound email through
|
|
183
|
+
* `ingestRawEmail` (real thread/attachments/body). `receivedAddress` must
|
|
184
|
+
* be a sim DID's mailbox; the sender in `rawMime` must be `@sim.invalid`.
|
|
185
|
+
* @param {object} args
|
|
186
|
+
* @param {string} args.receivedAddress
|
|
187
|
+
* @param {string} args.rawMime
|
|
188
|
+
* @returns {Promise<{taskId?: string, messageId: string}>}
|
|
189
|
+
*/
|
|
190
|
+
async emailInbound({ receivedAddress, rawMime } = {}) {
|
|
191
|
+
this.sdk.validateParams(
|
|
192
|
+
{ receivedAddress, rawMime },
|
|
193
|
+
{
|
|
194
|
+
receivedAddress: { type: 'string', required: true },
|
|
195
|
+
rawMime: { type: 'string', required: true },
|
|
196
|
+
},
|
|
197
|
+
);
|
|
198
|
+
return internalRequest(this.sdk, '/internal/email/sim-inbound', 'POST', {
|
|
199
|
+
body: { receivedAddress, rawMime },
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export default InternalSimService;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { InternalSimService } from './SimService.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `sdk.internal` namespace on the main @unboundcx/sdk instance.
|
|
5
|
+
*
|
|
6
|
+
* Distinct from the separate `@unboundcx/sdk-internal` package (master
|
|
7
|
+
* auth, SIP/voice/email internal routes for app1-ai-bot etc.): this is a
|
|
8
|
+
* small, self-contained surface for the app1-simulator controller, which
|
|
9
|
+
* already holds a signed-in admin SDK instance and just needs to swap in
|
|
10
|
+
* an internal-API-key token for these specific calls.
|
|
11
|
+
*/
|
|
12
|
+
export class InternalService {
|
|
13
|
+
constructor(sdk) {
|
|
14
|
+
this.sdk = sdk;
|
|
15
|
+
this.sim = new InternalSimService(sdk);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default InternalService;
|