@unboundcx/sdk 4.13.150 → 4.13.151

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 CHANGED
@@ -63,6 +63,8 @@ import {
63
63
  DataExportService,
64
64
  } from './services/dataImport.js';
65
65
  import { VoicemailDropsService } from './services/voicemailDrops.js';
66
+ import { InternalService } from './services/internal/index.js';
67
+ import { simRules } from './lib/simRules.js';
66
68
 
67
69
  class UnboundSDK extends BaseSDK {
68
70
  constructor(options = {}) {
@@ -172,6 +174,8 @@ class UnboundSDK extends BaseSDK {
172
174
  this.dataImport = new DataImportService(this);
173
175
  this.dataExport = new DataExportService(this);
174
176
  this.voicemailDrops = new VoicemailDropsService(this);
177
+ this.internal = new InternalService(this);
178
+ this.simRules = simRules;
175
179
 
176
180
  // Add additional services that might be missing
177
181
  this._initializeAdditionalServices();
@@ -401,3 +405,13 @@ export {
401
405
  } from './services/voicemailDrops.js';
402
406
  export { BaseSDK } from './base.js';
403
407
  export { layoutJourney, MAX_LANES as JOURNEY_LAYOUT_MAX_LANES } from './lib/journeyLayout.js';
408
+ export { InternalService } from './services/internal/index.js';
409
+ export { InternalSimService } from './services/internal/SimService.js';
410
+ export {
411
+ simRules,
412
+ SIM_NUMBER_RE,
413
+ SIM_EMAIL_DOMAIN,
414
+ isSimNumber,
415
+ isSimEmail,
416
+ simModeKey,
417
+ } from './lib/simRules.js';
@@ -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.150",
3
+ "version": "4.13.151",
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,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;