@signalhouse-sms/sdk 1.6.0 → 1.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signalhouse-sms/sdk",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "description": "Signal House SDK for use with the Signal House platform",
5
5
  "type": "module",
6
6
  "main": "src/SignalHouseSDK.js",
@@ -158,6 +158,7 @@ export class SignalHouseSDK {
158
158
  // Attach helpers to the client
159
159
  client._getQueryString = this._getQueryString.bind(this);
160
160
  client._require = this._require.bind(this);
161
+ client._baseUrl = this.baseUrl;
161
162
 
162
163
  return client;
163
164
  }
@@ -122,7 +122,7 @@
122
122
  * @property {string} inboundText - The contact message the agent was answering.
123
123
  * @property {string} draftText - The reply as the agent wrote it.
124
124
  * @property {string|null} sentText - The text actually sent; differs from draftText when edited.
125
- * @property {string} reason - Why it was held: "review_mode", "escalation", "fallback" or "guardrail", or "autopilot" for a confident auto-pilot reply that its channel delivers without a person.
125
+ * @property {string} reason - Why it was held: "review_mode", "escalation", "fallback", "guardrail" or "quiet_hours" (an auto-pilot reply written between 9 pm and 9 am in the contact's time zone), or "autopilot" for a confident auto-pilot reply that its channel delivers without a person.
126
126
  * @property {string} status - "pending", "sending", "sent", "rejected" or "failed" (the send path accepted nothing, e.g. the contact opted out).
127
127
  * @property {string|null} decidedBy - The user who approved or rejected it.
128
128
  * @property {string|null} decidedAt - When it was approved or rejected.
@@ -28,6 +28,22 @@ export class Auth {
28
28
  const safeGroupId = encodeURIComponent(groupId);
29
29
  return this.client(`/auth/groups/${safeGroupId}/logout-all`, { method: "POST", ...options });
30
30
  },
31
+
32
+ /**
33
+ * Turn off two-factor authentication for a user who has lost every factor (lockout recovery).
34
+ * Clears their methods, backup codes and trusted devices. Audited.
35
+ * @async
36
+ * @roles signalhouse
37
+ * @param {Object} params - The parameters for resetting a user's two-factor authentication
38
+ * @param {string} params.userId - The id of the user to reset
39
+ * @param {RequestOptions} [params.options] - Additional options for the request
40
+ * @throws {Error} Throws an error if the userId parameter is missing
41
+ * @returns {Promise<SdkResponse<any>>} - The response ({ reset: true })
42
+ */
43
+ resetUserTwoFactor: async ({ userId, options = {} }) => {
44
+ this.client._require({ userId });
45
+ return this.client(`/auth/2fa/users/${encodeURIComponent(userId)}`, { method: "DELETE", ...options });
46
+ },
31
47
  };
32
48
  }
33
49
  }
@@ -39,11 +55,12 @@ export class Auth {
39
55
  * @param {Object} params
40
56
  * @param {string} params.email - The user's email address
41
57
  * @param {string} params.password - The user's password
58
+ * @param {string} [params.deviceToken] - A trusted-device token from an earlier verifyTwoFactorChallenge; skips 2FA while valid
42
59
  * @param {RequestOptions} [params.options] - Additional options for the request
43
- * @returns {Promise<SdkResponse<any>>} The response from the server
60
+ * @returns {Promise<SdkResponse<any>>} The response from the server: { token }, or { mfaRequired: true, challengeId, methods, primaryMethod, hasBackupCodes } when the account has 2FA on; or { token, twoFactorSetupRequired: true } (a setup-only session) when the user's group requires 2FA and they haven't turned it on
44
61
  */
45
- async login({ email, password, options = {} }) {
46
- return this.client(`/auth`, { method: "POST", body: { email, password }, ...options });
62
+ async login({ email, password, deviceToken, options = {} }) {
63
+ return this.client(`/auth`, { method: "POST", body: { email, password, deviceToken }, ...options });
47
64
  }
48
65
 
49
66
  /**
@@ -54,7 +71,8 @@ export class Auth {
54
71
  * @param {string} params.businessName - The business / group name
55
72
  * @param {string} params.fullName - The owner's full name
56
73
  * @param {string} params.email - The owner's work email
57
- * @param {string} params.password - The owner's password (min 8 characters)
74
+ * @param {string} [params.password] - The owner's password (min 8 characters). Required unless `oauthTicket` is provided
75
+ * @param {string} [params.oauthTicket] - A `signup` ticket from a provider sign-in (see readOAuthTicket). Replaces the password; `email` must match the provider's email
58
76
  * @param {string} [params.phone] - National phone number
59
77
  * @param {string} [params.dialCode] - Country dial code (e.g. "1")
60
78
  * @param {string} [params.country] - Country ISO code (e.g. "US")
@@ -73,10 +91,10 @@ export class Auth {
73
91
  * @param {RequestOptions} [params.options] - Additional options for the request
74
92
  * @returns {Promise<SdkResponse<any>>} The response from the server (contains the JWT token)
75
93
  */
76
- async register({ businessName, fullName, email, password, phone, dialCode, country, volume, products, acceptedTermsOfService, psXid, psPartnerKey, attribution, options = {} }) {
94
+ async register({ businessName, fullName, email, password, oauthTicket, phone, dialCode, country, volume, products, acceptedTermsOfService, psXid, psPartnerKey, attribution, options = {} }) {
77
95
  return this.client(`/auth/register`, {
78
96
  method: "POST",
79
- body: { businessName, fullName, email, password, phone, dialCode, country, volume, products, acceptedTermsOfService, psXid, psPartnerKey, attribution },
97
+ body: { businessName, fullName, email, password, oauthTicket, phone, dialCode, country, volume, products, acceptedTermsOfService, psXid, psPartnerKey, attribution },
80
98
  ...options,
81
99
  });
82
100
  }
@@ -88,8 +106,9 @@ export class Auth {
88
106
  * The response carries a session JWT (`token`) for the user the link was emailed to, so a click
89
107
  * from any device establishes a session — use it exactly as you would the token from `login`.
90
108
  * `token` is omitted when the link cannot establish a session (issued before auto-login shipped,
91
- * or the account is inactive/ineligible); `verified` is still true in that case, so treat a
92
- * missing token as "verified, ask them to log in" rather than as a failure.
109
+ * the account is inactive/ineligible, or the account has two-factor authentication on, since the
110
+ * link is not a second factor); `verified` is still true in that case, so treat a missing token as
111
+ * "verified, ask them to log in" rather than as a failure.
93
112
  *
94
113
  * Rate limited per source IP. The token is single-use and expires 24 hours after it is issued.
95
114
  * @async
@@ -222,4 +241,405 @@ export class Auth {
222
241
  this.client._require({ product });
223
242
  return this.client(`/auth/external-link-token`, { method: "POST", body: { product }, ...options });
224
243
  }
244
+
245
+ /**
246
+ * List the OAuth sign-in providers enabled on this API (only providers with credentials configured)
247
+ * @async
248
+ * @roles public
249
+ * @param {Object} [params]
250
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
251
+ * @returns {Promise<Object>} The response from the server ([{ id, label }])
252
+ */
253
+ async getOAuthProviders({ options = {} } = {}) {
254
+ return this.client(`/auth/oauth/providers`, { method: "GET", ...options });
255
+ }
256
+
257
+ /**
258
+ * Build the URL that starts an OAuth sign-in. Navigate the browser to it (it is a redirect, not an
259
+ * API call); the API returns the user to the portal's /auth/callback with a single-use ticket.
260
+ * With a `linkTicket` (from createOAuthLink) it links the provider to the signed-in account instead,
261
+ * and the API returns the user to /Settings/Security with `pendingLink` (finish with confirmOAuthLink) or `linkError`.
262
+ * With a `reauthTicket` (from createOAuthReauth) the signed-in user signs in again with a linked provider to
263
+ * confirm it's them, and the API returns them to /Settings/Security with a single-use `pendingReauth` (the session that started it redeems it with confirmOAuthReauth) or `reauthError`.
264
+ * @roles public
265
+ * @param {Object} params
266
+ * @param {string} params.provider - The provider id ("google", "microsoft", "apple" or "sso" for Enterprise SSO)
267
+ * @param {string} [params.next] - A same-site path (e.g. "/oauth/consent?request=abc") to return the user to
268
+ * after sign-in. The API hands it back on the /auth/callback redirect as `next`; anything that isn't a
269
+ * rooted path on the portal is dropped
270
+ * @param {string} [params.email] - Required for "sso" sign-in: the user's work email, whose domain picks the organization's identity provider. Not needed with a reauthTicket
271
+ * @param {string} [params.linkTicket] - Link the provider to the signed-in account that requested this ticket
272
+ * @param {string} [params.reauthTicket] - Sign in again with a linked provider to confirm it's the account that requested this ticket
273
+ * @returns {string} The absolute authorization URL
274
+ */
275
+ getOAuthAuthorizationUrl({ provider, next, email, linkTicket, reauthTicket }) {
276
+ this.client._require({ provider });
277
+ const base = String(this.client._baseUrl).replace(/\/+$/, "");
278
+ const query = new URLSearchParams();
279
+ if (email) query.set("email", email);
280
+ if (linkTicket) query.set("linkTicket", linkTicket);
281
+ if (reauthTicket) query.set("reauthTicket", reauthTicket);
282
+ if (next) query.set("next", next);
283
+ const queryString = query.toString();
284
+ return `${base}/auth/oauth/${encodeURIComponent(provider)}${queryString ? `?${queryString}` : ""}`;
285
+ }
286
+
287
+ /**
288
+ * List the caller's sign-in methods: whether they chose their own password (`passwordKnown` is false for
289
+ * an account created through a provider or Enterprise SSO), and every provider linked to the account
290
+ * @async
291
+ * @roles admin, developer, billing, user
292
+ * @param {Object} [params]
293
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
294
+ * @returns {Promise<Object>} The response from the server ({ passwordKnown, links: [{ provider, email, linkedAt, lastLoginAt }] })
295
+ */
296
+ async getOAuthLinks({ options = {} } = {}) {
297
+ return this.client(`/auth/oauth/links`, { method: "GET", ...options });
298
+ }
299
+
300
+ /**
301
+ * Start linking Google, Microsoft or Apple to the caller's account. Returns a single-use link ticket
302
+ * (valid 2 minutes): navigate the browser to getOAuthAuthorizationUrl({ provider, linkTicket }).
303
+ * Requires a fresh confirmTwoFactorIdentity from the same session, which this spends.
304
+ * @async
305
+ * @roles admin, developer, billing, user
306
+ * @param {Object} params
307
+ * @param {string} params.provider - "google", "microsoft" or "apple"
308
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
309
+ * @returns {Promise<Object>} The response from the server ({ linkTicket, expiresInSeconds })
310
+ */
311
+ async createOAuthLink({ provider, options = {} }) {
312
+ this.client._require({ provider });
313
+ return this.client(`/auth/oauth/${encodeURIComponent(provider)}/link`, { method: "POST", ...options });
314
+ }
315
+
316
+ /**
317
+ * Start signing in again with a provider already linked to the caller's account, to confirm it's them.
318
+ * Returns a single-use ticket (valid 2 minutes): navigate the browser to getOAuthAuthorizationUrl({ provider, reauthTicket }).
319
+ * The provider is asked for a fresh sign-in, and the API returns the browser to /Settings/Security with
320
+ * a single-use `pendingReauth` (the session that started it redeems it with confirmOAuthReauth) or `reauthError` (reauth_wrong_account, reauth_unsupported, reauth_stale, invalid_state,
321
+ * sso_not_configured, access_denied or provider_error). Spends nothing.
322
+ * @async
323
+ * @roles admin, developer, billing, user
324
+ * @param {Object} params
325
+ * @param {string} params.provider - "microsoft", "apple" or "sso"; must be linked to the account. Google is
326
+ * refused with a 400 because it can't confirm a fresh sign-in; confirm with a code instead
327
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
328
+ * @returns {Promise<Object>} The response from the server ({ reauthTicket, reauthSecret, expiresInSeconds }). Keep
329
+ * `reauthSecret` in the client that started the flow: it is returned only here, and confirmOAuthReauth needs it
330
+ */
331
+ async createOAuthReauth({ provider, options = {} }) {
332
+ this.client._require({ provider });
333
+ return this.client(`/auth/oauth/${encodeURIComponent(provider)}/reauth`, { method: "POST", ...options });
334
+ }
335
+
336
+ /**
337
+ * Finish signing in again with a linked provider. The round trip started with createOAuthReauth returns the
338
+ * browser to /Settings/Security with a single-use `pendingReauth` (valid 5 minutes); this redeems it, but only
339
+ * for the same account and the same session that called createOAuthReauth, so a re-sign-in completed in
340
+ * someone else's browser confirms nothing. Fails with 400 when it expired or was used, 403 for another account or session.
341
+ * @async
342
+ * @roles admin, developer, billing, user
343
+ * @param {Object} params
344
+ * @param {string} params.pendingReauth - The `pendingReauth` query parameter from the redirect
345
+ * @param {string} params.reauthSecret - The `reauthSecret` createOAuthReauth returned; a wrong or missing secret is refused (403) and uses up the pending re-sign-in
346
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
347
+ * @returns {Promise<Object>} The response from the server: { identityConfirmed } (true when 2FA is off, so it counts as a confirmed identity)
348
+ */
349
+ async confirmOAuthReauth({ pendingReauth, reauthSecret, options = {} }) {
350
+ this.client._require({ pendingReauth, reauthSecret });
351
+ return this.client(`/auth/oauth/reauth/confirm`, { method: "POST", body: { pendingReauth, reauthSecret }, ...options });
352
+ }
353
+
354
+ /**
355
+ * Finish linking a provider. The provider round trip started with createOAuthLink returns the browser to
356
+ * /Settings/Security with a single-use `pendingLink`; this links it, but only for the account the link was
357
+ * started for, so a link URL opened in someone else's browser can't attach their provider to your account.
358
+ * @async
359
+ * @roles admin, developer, billing, user
360
+ * @param {Object} params
361
+ * @param {string} params.pendingLink - The `pendingLink` query parameter from the redirect
362
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
363
+ * @returns {Promise<Object>} The response from the server: the caller's { passwordKnown, links }
364
+ */
365
+ async confirmOAuthLink({ pendingLink, options = {} }) {
366
+ this.client._require({ pendingLink });
367
+ return this.client(`/auth/oauth/links/confirm`, { method: "POST", body: { pendingLink }, ...options });
368
+ }
369
+
370
+ /**
371
+ * Unlink a provider from the caller's account. Refused when it is the account's only way to sign in. With 2FA on and no password, the last linked Microsoft, Apple or SSO sign-in is refused (400) too.
372
+ * Requires a fresh confirmTwoFactorIdentity from the same session.
373
+ * @async
374
+ * @roles admin, developer, billing, user
375
+ * @param {Object} params
376
+ * @param {string} params.provider - "google", "microsoft", "apple" or "sso"
377
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
378
+ * @returns {Promise<Object>} The response from the server: the remaining { passwordKnown, links }
379
+ */
380
+ async deleteOAuthLink({ provider, options = {} }) {
381
+ this.client._require({ provider });
382
+ return this.client(`/auth/oauth/${encodeURIComponent(provider)}/link`, { method: "DELETE", ...options });
383
+ }
384
+
385
+ /**
386
+ * Read what a single-use OAuth ticket resolves to, without consuming it: a `session` (ready to
387
+ * exchange), a `select` (pick one of several accounts) or a `signup` (finish registration)
388
+ * @async
389
+ * @roles public
390
+ * @param {Object} params
391
+ * @param {string} params.ticket - The ticket from the OAuth callback redirect
392
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
393
+ * @returns {Promise<Object>} The response from the server ({ kind, provider, profile?, accounts? })
394
+ */
395
+ async readOAuthTicket({ ticket, options = {} }) {
396
+ this.client._require({ ticket });
397
+ return this.client(`/auth/oauth/ticket`, { method: "POST", body: { ticket }, ...options });
398
+ }
399
+
400
+ /**
401
+ * Exchange a single-use `session` or `select` OAuth ticket for a JWT Bearer token. Consumes the ticket.
402
+ * @async
403
+ * @roles public
404
+ * @param {Object} params
405
+ * @param {string} params.ticket - The ticket from the OAuth callback redirect
406
+ * @param {string} [params.userId] - Required for a `select` ticket: the chosen account from `accounts`
407
+ * @param {string} [params.deviceToken] - A trusted-device token from an earlier verifyTwoFactorChallenge; skips 2FA while valid
408
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
409
+ * @returns {Promise<Object>} The response from the server: { token }, or { mfaRequired: true, challengeId, ... } when the account has 2FA on; or { token, twoFactorSetupRequired: true } (a setup-only session) when the user's group requires 2FA and they haven't turned it on
410
+ */
411
+ async exchangeOAuthTicket({ ticket, userId, deviceToken, options = {} }) {
412
+ this.client._require({ ticket });
413
+ return this.client(`/auth/oauth/exchange`, { method: "POST", body: { ticket, userId, deviceToken }, ...options });
414
+ }
415
+
416
+ /**
417
+ * Get the caller's two-factor authentication settings: enrolled methods (targets masked), the default
418
+ * method, backup-code counts and trusted devices. Never returns secrets or codes.
419
+ * @async
420
+ * @roles admin, developer, billing, user
421
+ * @param {Object} [params]
422
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
423
+ * @returns {Promise<Object>} The response from the server (the settings object)
424
+ */
425
+ async getTwoFactorSettings({ options = {} } = {}) {
426
+ return this.client(`/auth/2fa`, { method: "GET", ...options });
427
+ }
428
+
429
+ /**
430
+ * Confirm it's really the account owner before a sensitive change: startTwoFactorEnrollment,
431
+ * removeTwoFactorMethod, regenerateBackupCodes, disableTwoFactor, createOAuthLink, deleteOAuthLink, or
432
+ * groups.saveSsoConnection / groups.deleteSsoConnection. With 2FA on, pass a current `code` (or a backup
433
+ * code); with 2FA off, pass the account `password`, or, for an account without a password of its own
434
+ * (getOAuthLinks returns passwordKnown: false), the `code` from sendTwoFactorIdentityCode({ method: "email" })
435
+ * with method "email". A confirmation lasts 5 minutes, belongs to the session that made it, and unlocks
436
+ * exactly one change.
437
+ * @async
438
+ * @roles admin, developer, billing, user
439
+ * @param {Object} [params]
440
+ * @param {string} [params.password] - The account password. Required while 2FA is off
441
+ * @param {string} [params.code] - A code from an enrolled method, or a backup code. Required while 2FA is on
442
+ * @param {string} [params.method] - The method the code came from; defaults to the primary method
443
+ * @param {boolean} [params.usingBackupCode] - True when `code` is a backup code
444
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
445
+ * @returns {Promise<Object>} The response from the server ({ confirmed: true, expiresInSeconds })
446
+ */
447
+ async confirmTwoFactorIdentity({ password, code, method, usingBackupCode, options = {} } = {}) {
448
+ return this.client(`/auth/2fa/confirm-identity`, { method: "POST", body: { password, code, method, usingBackupCode }, ...options });
449
+ }
450
+
451
+ /**
452
+ * Send a code by text or email to use with confirmTwoFactorIdentity. An authenticator app needs no send.
453
+ * @async
454
+ * @roles admin, developer, billing, user
455
+ * @param {Object} params
456
+ * @param {string} params.method - An enrolled "sms" or "email" method, or "email" for an account without a password of its own
457
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
458
+ * @returns {Promise<Object>} The response from the server ({ sent, target, expiresInSeconds? })
459
+ */
460
+ async sendTwoFactorIdentityCode({ method, options = {} }) {
461
+ this.client._require({ method });
462
+ return this.client(`/auth/2fa/confirm-identity/send`, { method: "POST", body: { method }, ...options });
463
+ }
464
+
465
+ /**
466
+ * Start enrolling a two-factor method. For "app" the response carries the setup secret and otpauth URI
467
+ * (render it as a QR code); for "sms" and "email" a code is sent to the given phone or address.
468
+ * Requires a fresh confirmTwoFactorIdentity from the same session (403 otherwise); each confirmation unlocks one change.
469
+ * @async
470
+ * @roles admin, developer, billing, user
471
+ * @param {Object} params
472
+ * @param {string} params.method - "app", "sms" or "email"
473
+ * @param {string} [params.phone] - Required for "sms": the mobile number to send codes to
474
+ * @param {string} [params.address] - Required for "email": the address to send codes to
475
+ * @param {string} [params.deviceName] - Optional label for an authenticator app
476
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
477
+ * @returns {Promise<Object>} The response from the server ({ enrollmentId, secret?, otpauthUri?, sentTo? })
478
+ */
479
+ async startTwoFactorEnrollment({ method, phone, address, deviceName, options = {} }) {
480
+ this.client._require({ method });
481
+ return this.client(`/auth/2fa/enroll`, { method: "POST", body: { method, phone, address, deviceName }, ...options });
482
+ }
483
+
484
+ /**
485
+ * Confirm a pending enrollment with the code from the app, text or email. The first method enrolled turns
486
+ * 2FA on and returns a set of backup codes, shown only this once.
487
+ * @async
488
+ * @roles admin, developer, billing, user
489
+ * @param {Object} params
490
+ * @param {string} params.enrollmentId - From startTwoFactorEnrollment
491
+ * @param {string} params.code - The 6-digit code
492
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
493
+ * @returns {Promise<Object>} The response from the server ({ settings, backupCodes })
494
+ */
495
+ async confirmTwoFactorEnrollment({ enrollmentId, code, options = {} }) {
496
+ this.client._require({ enrollmentId, code });
497
+ return this.client(`/auth/2fa/enroll/${encodeURIComponent(enrollmentId)}/verify`, { method: "POST", body: { code }, ...options });
498
+ }
499
+
500
+ /**
501
+ * Choose which enrolled method is offered first at sign-in
502
+ * @async
503
+ * @roles admin, developer, billing, user
504
+ * @param {Object} params
505
+ * @param {string} params.method - An enrolled method: "app", "sms" or "email"
506
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
507
+ * @returns {Promise<Object>} The response from the server (the settings object)
508
+ */
509
+ async setTwoFactorPrimaryMethod({ method, options = {} }) {
510
+ this.client._require({ method });
511
+ return this.client(`/auth/2fa/primary`, { method: "PUT", body: { method }, ...options });
512
+ }
513
+
514
+ /**
515
+ * Remove an enrolled two-factor method. Removing the last one turns 2FA off.
516
+ * Requires a fresh confirmTwoFactorIdentity from the same session (403 otherwise); each confirmation unlocks one change.
517
+ * @async
518
+ * @roles admin, developer, billing, user
519
+ * @param {Object} params
520
+ * @param {string} params.method - "app", "sms" or "email"
521
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
522
+ * @returns {Promise<Object>} The response from the server (the settings object)
523
+ */
524
+ async removeTwoFactorMethod({ method, options = {} }) {
525
+ this.client._require({ method });
526
+ return this.client(`/auth/2fa/methods/${encodeURIComponent(method)}`, { method: "DELETE", ...options });
527
+ }
528
+
529
+ /**
530
+ * Replace all backup codes with a new set. The previous codes stop working; the new ones are shown only once.
531
+ * Requires a fresh confirmTwoFactorIdentity from the same session (403 otherwise); each confirmation unlocks one change.
532
+ * @async
533
+ * @roles admin, developer, billing, user
534
+ * @param {Object} [params]
535
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
536
+ * @returns {Promise<Object>} The response from the server ({ codes, settings })
537
+ */
538
+ async regenerateBackupCodes({ options = {} } = {}) {
539
+ return this.client(`/auth/2fa/backup-codes`, { method: "POST", ...options });
540
+ }
541
+
542
+ /**
543
+ * Stop trusting a device, so its next sign-in asks for the second factor again
544
+ * @async
545
+ * @roles admin, developer, billing, user
546
+ * @param {Object} params
547
+ * @param {string} params.deviceId - The trusted device's id from getTwoFactorSettings
548
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
549
+ * @returns {Promise<Object>} The response from the server (the settings object)
550
+ */
551
+ async revokeTrustedDevice({ deviceId, options = {} }) {
552
+ this.client._require({ deviceId });
553
+ return this.client(`/auth/2fa/trusted-devices/${encodeURIComponent(deviceId)}`, { method: "DELETE", ...options });
554
+ }
555
+
556
+ /**
557
+ * Turn two-factor authentication off: removes every method, backup code and trusted device.
558
+ * Requires a fresh confirmTwoFactorIdentity from the same session (403 otherwise); each confirmation unlocks one change.
559
+ * @async
560
+ * @roles admin, developer, billing, user
561
+ * @param {Object} [params]
562
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
563
+ * @returns {Promise<Object>} The response from the server (the settings object)
564
+ */
565
+ async disableTwoFactor({ options = {} } = {}) {
566
+ return this.client(`/auth/2fa`, { method: "DELETE", ...options });
567
+ }
568
+
569
+ /**
570
+ * Whether the "secure your account" enrollment prompt is due for the caller
571
+ * @async
572
+ * @roles admin, developer, billing, user
573
+ * @param {Object} [params]
574
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
575
+ * @returns {Promise<Object>} The response from the server ({ due })
576
+ */
577
+ async getTwoFactorPrompt({ options = {} } = {}) {
578
+ return this.client(`/auth/2fa/prompt`, { method: "GET", ...options });
579
+ }
580
+
581
+ /**
582
+ * Dismiss the enrollment prompt ("Set up later") until the next sign-in. It stops for good after three dismissals.
583
+ * @async
584
+ * @roles admin, developer, billing, user
585
+ * @param {Object} [params]
586
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
587
+ * @returns {Promise<Object>} The response from the server ({ due: false })
588
+ */
589
+ async dismissTwoFactorPrompt({ options = {} } = {}) {
590
+ return this.client(`/auth/2fa/prompt/dismiss`, { method: "POST", ...options });
591
+ }
592
+
593
+ /**
594
+ * Send a sign-in code by text or email for a pending two-factor challenge. Not needed for "app".
595
+ * @async
596
+ * @roles public
597
+ * @param {Object} params
598
+ * @param {string} params.challengeId - From the mfaRequired login or exchange response
599
+ * @param {string} params.method - "sms" or "email"
600
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
601
+ * @returns {Promise<Object>} The response from the server ({ sent, target, expiresInSeconds })
602
+ */
603
+ async sendTwoFactorChallengeCode({ challengeId, method, options = {} }) {
604
+ this.client._require({ challengeId, method });
605
+ return this.client(`/auth/2fa/challenge/${encodeURIComponent(challengeId)}/send`, { method: "POST", body: { method }, ...options });
606
+ }
607
+
608
+ /**
609
+ * Verify a sign-in code (or a backup code) for a pending two-factor challenge and receive the session JWT.
610
+ * With rememberDevice the response also carries a deviceToken to pass on later logins.
611
+ * @async
612
+ * @roles public
613
+ * @param {Object} params
614
+ * @param {string} params.challengeId - From the mfaRequired login or exchange response
615
+ * @param {string} params.code - The 6-digit code, or a backup code (xxxx-xxxx)
616
+ * @param {string} [params.method] - The method the code came from ("app", "sms" or "email"); defaults to the primary method
617
+ * @param {boolean} [params.usingBackupCode] - True when code is a backup code
618
+ * @param {boolean} [params.rememberDevice] - Trust this device for 30 days
619
+ * @param {string} [params.deviceName] - Label for the trusted device (e.g. "Chrome on Windows")
620
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
621
+ * @returns {Promise<Object>} The response from the server ({ token, deviceToken? })
622
+ */
623
+ async verifyTwoFactorChallenge({ challengeId, code, method, usingBackupCode, rememberDevice, deviceName, options = {} }) {
624
+ this.client._require({ challengeId, code });
625
+ return this.client(`/auth/2fa/challenge/${encodeURIComponent(challengeId)}/verify`, {
626
+ method: "POST",
627
+ body: { code, method, usingBackupCode, rememberDevice, deviceName },
628
+ ...options,
629
+ });
630
+ }
631
+
632
+ /**
633
+ * Cancel a pending two-factor challenge (e.g. "Back to sign in")
634
+ * @async
635
+ * @roles public
636
+ * @param {Object} params
637
+ * @param {string} params.challengeId - From the mfaRequired login or exchange response
638
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
639
+ * @returns {Promise<Object>} The response from the server ({ cancelled: true })
640
+ */
641
+ async cancelTwoFactorChallenge({ challengeId, options = {} }) {
642
+ this.client._require({ challengeId });
643
+ return this.client(`/auth/2fa/challenge/${encodeURIComponent(challengeId)}`, { method: "DELETE", ...options });
644
+ }
225
645
  }
@@ -175,6 +175,51 @@ export class Brands {
175
175
  this.client = client;
176
176
  this.multipartClient = multipartClient;
177
177
  this.enableAdmin = enableAdmin;
178
+
179
+ if (enableAdmin) {
180
+ this.admin = {
181
+ /**
182
+ * Get a group's toll-free ISV account: the group's own top-level account at the toll-free provider, used when its
183
+ * subgroups are separate businesses. Each subgroup gets an account and business verifications of its own under it.
184
+ * Staff only.
185
+ * @async
186
+ * @roles signalhouse_api, signalhouse_admin, signalhouse_user
187
+ * @param {Object} params - The parameters for getting the toll-free ISV account
188
+ * @param {string} params.groupId - The ID of the group whose toll-free ISV account to get
189
+ * @param {RequestOptions} [params.options] - Additional options for the request
190
+ * @throws {Error} Throws an error if the groupId parameter is missing
191
+ * @returns {Promise<SdkResponse<TollFreeIsvAccount|null>>} The group's toll-free ISV account, or null when it has none. The API key secret is never returned. The API returns 404 when the group does not exist or is not active.
192
+ */
193
+ getTollFreeIsvAccount: async ({ groupId, options = {} }) => {
194
+ this.client._require({ groupId });
195
+ return this.client(`/brand/toll-free-isv-account/${encodeURIComponent(groupId)}`, { method: 'GET', ...options });
196
+ },
197
+
198
+ /**
199
+ * Register a group's toll-free ISV account, or replace the API key of the account it already has. Staff only. The
200
+ * toll-free provider checks the account and key before they are stored. Register it before the group has any toll-free
201
+ * records at the provider; after that, only the API key of the same account can be replaced.
202
+ * @async
203
+ * @roles signalhouse_admin
204
+ * @param {Object} params - The parameters for setting the toll-free ISV account
205
+ * @param {string} params.groupId - The ID of the group whose toll-free ISV account to set
206
+ * @param {string} params.accountSid - The SID of the group's own top-level account at the toll-free provider (AC followed by 32 lowercase hexadecimal characters)
207
+ * @param {string} params.apiKeySid - The SID of a Main API key in that account, which can create subaccounts (SK followed by 32 lowercase hexadecimal characters)
208
+ * @param {string} params.apiKeySecret - The API key's secret (1 to 128 characters), stored encrypted and never returned
209
+ * @param {RequestOptions} [params.options] - Additional options for the request
210
+ * @throws {Error} Throws an error if the groupId, accountSid, apiKeySid or apiKeySecret parameter is missing
211
+ * @returns {Promise<SdkResponse<TollFreeIsvAccount>>} The stored toll-free ISV account, without the API key secret. The API returns 400 when the provider refuses the account or its key, and 404 when the group does not exist or is not active.
212
+ */
213
+ setTollFreeIsvAccount: async ({ groupId, accountSid, apiKeySid, apiKeySecret, options = {} }) => {
214
+ this.client._require({ groupId, accountSid, apiKeySid, apiKeySecret });
215
+ return this.client(`/brand/toll-free-isv-account/${encodeURIComponent(groupId)}`, {
216
+ method: 'PUT',
217
+ body: { accountSid, apiKeySid, apiKeySecret },
218
+ ...options,
219
+ });
220
+ },
221
+ };
222
+ }
178
223
  }
179
224
 
180
225
  /**
@@ -373,47 +418,6 @@ export class Brands {
373
418
  return this.client(`/brand/business-verification/${encodeURIComponent(groupId)}/${encodeURIComponent(businessVerificationId)}`, { method: 'PUT', body: details, ...options });
374
419
  }
375
420
 
376
- /**
377
- * Get a group's toll-free ISV account: the group's own top-level account at the toll-free provider, used when its
378
- * subgroups are separate businesses. Each subgroup gets an account and business verifications of its own under it.
379
- * Staff only.
380
- * @async
381
- * @roles signalhouse_api, signalhouse_admin, signalhouse_user
382
- * @param {Object} params - The parameters for getting the toll-free ISV account
383
- * @param {string} params.groupId - The ID of the group whose toll-free ISV account to get
384
- * @param {RequestOptions} [params.options] - Additional options for the request
385
- * @throws {Error} Throws an error if the groupId parameter is missing
386
- * @returns {Promise<SdkResponse<TollFreeIsvAccount|null>>} The group's toll-free ISV account, or null when it has none. The API key secret is never returned. The API returns 404 when the group does not exist or is not active.
387
- */
388
- async getTollFreeIsvAccount({ groupId, options = {} }) {
389
- this.client._require({ groupId });
390
- return this.client(`/brand/toll-free-isv-account/${encodeURIComponent(groupId)}`, { method: 'GET', ...options });
391
- }
392
-
393
- /**
394
- * Register a group's toll-free ISV account, or replace the API key of the account it already has. Staff only. The
395
- * toll-free provider checks the account and key before they are stored. Register it before the group has any toll-free
396
- * records at the provider; after that, only the API key of the same account can be replaced.
397
- * @async
398
- * @roles signalhouse_admin
399
- * @param {Object} params - The parameters for setting the toll-free ISV account
400
- * @param {string} params.groupId - The ID of the group whose toll-free ISV account to set
401
- * @param {string} params.accountSid - The SID of the group's own top-level account at the toll-free provider (AC followed by 32 lowercase hexadecimal characters)
402
- * @param {string} params.apiKeySid - The SID of a Main API key in that account, which can create subaccounts (SK followed by 32 lowercase hexadecimal characters)
403
- * @param {string} params.apiKeySecret - The API key's secret (1 to 128 characters), stored encrypted and never returned
404
- * @param {RequestOptions} [params.options] - Additional options for the request
405
- * @throws {Error} Throws an error if the groupId, accountSid, apiKeySid or apiKeySecret parameter is missing
406
- * @returns {Promise<SdkResponse<TollFreeIsvAccount>>} The stored toll-free ISV account, without the API key secret. The API returns 400 when the provider refuses the account or its key, and 404 when the group does not exist or is not active.
407
- */
408
- async setTollFreeIsvAccount({ groupId, accountSid, apiKeySid, apiKeySecret, options = {} }) {
409
- this.client._require({ groupId, accountSid, apiKeySid, apiKeySecret });
410
- return this.client(`/brand/toll-free-isv-account/${encodeURIComponent(groupId)}`, {
411
- method: 'PUT',
412
- body: { accountSid, apiKeySid, apiKeySecret },
413
- ...options,
414
- });
415
- }
416
-
417
421
  /**
418
422
  * Create a local Short Code brand for manual Signal House review.
419
423
  * @async
@@ -433,6 +433,22 @@ export class Campaigns {
433
433
  return this.client(`/campaign/throughput-limits${queryString}`, { method: 'GET', ...options });
434
434
  }
435
435
 
436
+ /**
437
+ * Get today's T-Mobile usage against the daily limit for every active campaign in a group that has one. The same limits and counter as getCampaignThroughputLimits, for the whole group in one call.
438
+ * @async
439
+ * @roles api, admin, developer, billing, user
440
+ * @param {Object} params - Parameters for reading group throughput usage
441
+ * @param {string} params.groupId - Group identifier
442
+ * @param {RequestOptions} [params.options] - Additional request options
443
+ * @throws {Error} Throws an error if the groupId parameter is missing
444
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to `[{ campaignId, brandId, brandName, usecase, tmobile: { tier, dailyLimit, usedToday: { date, segments, resetsAt } } }]`. Campaigns without a T-Mobile limit (unverified brand, GOVERNMENT entity, PUBLIC_SAFETY_RESTRICTED usecase) are left out. The counter is per brand EIN and UTC day, so every campaign of a brand shows the same usage; a LOW_VOLUME campaign's limit is 2,000 whatever the brand's score.
445
+ */
446
+ async getGroupThroughputUsage({ groupId, options = {} }) {
447
+ this.client._require({ groupId });
448
+ const queryString = this.client._getQueryString({ groupId });
449
+ return this.client(`/campaign/throughput-usage${queryString}`, { method: 'GET', ...options });
450
+ }
451
+
436
452
  /**
437
453
  * Create a new campaign
438
454
  * @async