@signalhouse-sms/sdk 1.6.0 → 1.7.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.7.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
  }
@@ -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,404 @@ 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 - "google", "microsoft", "apple" or "sso"; must be linked to the account
326
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
327
+ * @returns {Promise<Object>} The response from the server ({ reauthTicket, reauthSecret, expiresInSeconds }). Keep
328
+ * `reauthSecret` in the client that started the flow: it is returned only here, and confirmOAuthReauth needs it
329
+ */
330
+ async createOAuthReauth({ provider, options = {} }) {
331
+ this.client._require({ provider });
332
+ return this.client(`/auth/oauth/${encodeURIComponent(provider)}/reauth`, { method: "POST", ...options });
333
+ }
334
+
335
+ /**
336
+ * Finish signing in again with a linked provider. The round trip started with createOAuthReauth returns the
337
+ * browser to /Settings/Security with a single-use `pendingReauth` (valid 5 minutes); this redeems it, but only
338
+ * for the same account and the same session that called createOAuthReauth, so a re-sign-in completed in
339
+ * someone else's browser confirms nothing. Fails with 400 when it expired or was used, 403 for another account or session.
340
+ * @async
341
+ * @roles admin, developer, billing, user
342
+ * @param {Object} params
343
+ * @param {string} params.pendingReauth - The `pendingReauth` query parameter from the redirect
344
+ * @param {string} params.reauthSecret - The `reauthSecret` createOAuthReauth returned; a wrong or missing secret is refused (403) and uses up the pending re-sign-in
345
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
346
+ * @returns {Promise<Object>} The response from the server: { identityConfirmed } (true when 2FA is off, so it counts as a confirmed identity)
347
+ */
348
+ async confirmOAuthReauth({ pendingReauth, reauthSecret, options = {} }) {
349
+ this.client._require({ pendingReauth, reauthSecret });
350
+ return this.client(`/auth/oauth/reauth/confirm`, { method: "POST", body: { pendingReauth, reauthSecret }, ...options });
351
+ }
352
+
353
+ /**
354
+ * Finish linking a provider. The provider round trip started with createOAuthLink returns the browser to
355
+ * /Settings/Security with a single-use `pendingLink`; this links it, but only for the account the link was
356
+ * started for, so a link URL opened in someone else's browser can't attach their provider to your account.
357
+ * @async
358
+ * @roles admin, developer, billing, user
359
+ * @param {Object} params
360
+ * @param {string} params.pendingLink - The `pendingLink` query parameter from the redirect
361
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
362
+ * @returns {Promise<Object>} The response from the server: the caller's { passwordKnown, links }
363
+ */
364
+ async confirmOAuthLink({ pendingLink, options = {} }) {
365
+ this.client._require({ pendingLink });
366
+ return this.client(`/auth/oauth/links/confirm`, { method: "POST", body: { pendingLink }, ...options });
367
+ }
368
+
369
+ /**
370
+ * Unlink a provider from the caller's account. Refused when it is the account's only way to sign in.
371
+ * Requires a fresh confirmTwoFactorIdentity from the same session.
372
+ * @async
373
+ * @roles admin, developer, billing, user
374
+ * @param {Object} params
375
+ * @param {string} params.provider - "google", "microsoft", "apple" or "sso"
376
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
377
+ * @returns {Promise<Object>} The response from the server: the remaining { passwordKnown, links }
378
+ */
379
+ async deleteOAuthLink({ provider, options = {} }) {
380
+ this.client._require({ provider });
381
+ return this.client(`/auth/oauth/${encodeURIComponent(provider)}/link`, { method: "DELETE", ...options });
382
+ }
383
+
384
+ /**
385
+ * Read what a single-use OAuth ticket resolves to, without consuming it: a `session` (ready to
386
+ * exchange), a `select` (pick one of several accounts) or a `signup` (finish registration)
387
+ * @async
388
+ * @roles public
389
+ * @param {Object} params
390
+ * @param {string} params.ticket - The ticket from the OAuth callback redirect
391
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
392
+ * @returns {Promise<Object>} The response from the server ({ kind, provider, profile?, accounts? })
393
+ */
394
+ async readOAuthTicket({ ticket, options = {} }) {
395
+ this.client._require({ ticket });
396
+ return this.client(`/auth/oauth/ticket`, { method: "POST", body: { ticket }, ...options });
397
+ }
398
+
399
+ /**
400
+ * Exchange a single-use `session` or `select` OAuth ticket for a JWT Bearer token. Consumes the ticket.
401
+ * @async
402
+ * @roles public
403
+ * @param {Object} params
404
+ * @param {string} params.ticket - The ticket from the OAuth callback redirect
405
+ * @param {string} [params.userId] - Required for a `select` ticket: the chosen account from `accounts`
406
+ * @param {string} [params.deviceToken] - A trusted-device token from an earlier verifyTwoFactorChallenge; skips 2FA while valid
407
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
408
+ * @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
409
+ */
410
+ async exchangeOAuthTicket({ ticket, userId, deviceToken, options = {} }) {
411
+ this.client._require({ ticket });
412
+ return this.client(`/auth/oauth/exchange`, { method: "POST", body: { ticket, userId, deviceToken }, ...options });
413
+ }
414
+
415
+ /**
416
+ * Get the caller's two-factor authentication settings: enrolled methods (targets masked), the default
417
+ * method, backup-code counts and trusted devices. Never returns secrets or codes.
418
+ * @async
419
+ * @roles admin, developer, billing, user
420
+ * @param {Object} [params]
421
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
422
+ * @returns {Promise<Object>} The response from the server (the settings object)
423
+ */
424
+ async getTwoFactorSettings({ options = {} } = {}) {
425
+ return this.client(`/auth/2fa`, { method: "GET", ...options });
426
+ }
427
+
428
+ /**
429
+ * Confirm it's really the account owner before a sensitive change: startTwoFactorEnrollment,
430
+ * removeTwoFactorMethod, regenerateBackupCodes, disableTwoFactor, createOAuthLink, deleteOAuthLink, or
431
+ * groups.saveSsoConnection / groups.deleteSsoConnection. With 2FA on, pass a current `code` (or a backup
432
+ * code); with 2FA off, pass the account `password`, or, for an account without a password of its own
433
+ * (getOAuthLinks returns passwordKnown: false), the `code` from sendTwoFactorIdentityCode({ method: "email" })
434
+ * with method "email". A confirmation lasts 5 minutes, belongs to the session that made it, and unlocks
435
+ * exactly one change.
436
+ * @async
437
+ * @roles admin, developer, billing, user
438
+ * @param {Object} [params]
439
+ * @param {string} [params.password] - The account password. Required while 2FA is off
440
+ * @param {string} [params.code] - A code from an enrolled method, or a backup code. Required while 2FA is on
441
+ * @param {string} [params.method] - The method the code came from; defaults to the primary method
442
+ * @param {boolean} [params.usingBackupCode] - True when `code` is a backup code
443
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
444
+ * @returns {Promise<Object>} The response from the server ({ confirmed: true, expiresInSeconds })
445
+ */
446
+ async confirmTwoFactorIdentity({ password, code, method, usingBackupCode, options = {} } = {}) {
447
+ return this.client(`/auth/2fa/confirm-identity`, { method: "POST", body: { password, code, method, usingBackupCode }, ...options });
448
+ }
449
+
450
+ /**
451
+ * Send a code by text or email to use with confirmTwoFactorIdentity. An authenticator app needs no send.
452
+ * @async
453
+ * @roles admin, developer, billing, user
454
+ * @param {Object} params
455
+ * @param {string} params.method - An enrolled "sms" or "email" method, or "email" for an account without a password of its own
456
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
457
+ * @returns {Promise<Object>} The response from the server ({ sent, target, expiresInSeconds? })
458
+ */
459
+ async sendTwoFactorIdentityCode({ method, options = {} }) {
460
+ this.client._require({ method });
461
+ return this.client(`/auth/2fa/confirm-identity/send`, { method: "POST", body: { method }, ...options });
462
+ }
463
+
464
+ /**
465
+ * Start enrolling a two-factor method. For "app" the response carries the setup secret and otpauth URI
466
+ * (render it as a QR code); for "sms" and "email" a code is sent to the given phone or address.
467
+ * Requires a fresh confirmTwoFactorIdentity from the same session (403 otherwise); each confirmation unlocks one change.
468
+ * @async
469
+ * @roles admin, developer, billing, user
470
+ * @param {Object} params
471
+ * @param {string} params.method - "app", "sms" or "email"
472
+ * @param {string} [params.phone] - Required for "sms": the mobile number to send codes to
473
+ * @param {string} [params.address] - Required for "email": the address to send codes to
474
+ * @param {string} [params.deviceName] - Optional label for an authenticator app
475
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
476
+ * @returns {Promise<Object>} The response from the server ({ enrollmentId, secret?, otpauthUri?, sentTo? })
477
+ */
478
+ async startTwoFactorEnrollment({ method, phone, address, deviceName, options = {} }) {
479
+ this.client._require({ method });
480
+ return this.client(`/auth/2fa/enroll`, { method: "POST", body: { method, phone, address, deviceName }, ...options });
481
+ }
482
+
483
+ /**
484
+ * Confirm a pending enrollment with the code from the app, text or email. The first method enrolled turns
485
+ * 2FA on and returns a set of backup codes, shown only this once.
486
+ * @async
487
+ * @roles admin, developer, billing, user
488
+ * @param {Object} params
489
+ * @param {string} params.enrollmentId - From startTwoFactorEnrollment
490
+ * @param {string} params.code - The 6-digit code
491
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
492
+ * @returns {Promise<Object>} The response from the server ({ settings, backupCodes })
493
+ */
494
+ async confirmTwoFactorEnrollment({ enrollmentId, code, options = {} }) {
495
+ this.client._require({ enrollmentId, code });
496
+ return this.client(`/auth/2fa/enroll/${encodeURIComponent(enrollmentId)}/verify`, { method: "POST", body: { code }, ...options });
497
+ }
498
+
499
+ /**
500
+ * Choose which enrolled method is offered first at sign-in
501
+ * @async
502
+ * @roles admin, developer, billing, user
503
+ * @param {Object} params
504
+ * @param {string} params.method - An enrolled method: "app", "sms" or "email"
505
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
506
+ * @returns {Promise<Object>} The response from the server (the settings object)
507
+ */
508
+ async setTwoFactorPrimaryMethod({ method, options = {} }) {
509
+ this.client._require({ method });
510
+ return this.client(`/auth/2fa/primary`, { method: "PUT", body: { method }, ...options });
511
+ }
512
+
513
+ /**
514
+ * Remove an enrolled two-factor method. Removing the last one turns 2FA off.
515
+ * Requires a fresh confirmTwoFactorIdentity from the same session (403 otherwise); each confirmation unlocks one change.
516
+ * @async
517
+ * @roles admin, developer, billing, user
518
+ * @param {Object} params
519
+ * @param {string} params.method - "app", "sms" or "email"
520
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
521
+ * @returns {Promise<Object>} The response from the server (the settings object)
522
+ */
523
+ async removeTwoFactorMethod({ method, options = {} }) {
524
+ this.client._require({ method });
525
+ return this.client(`/auth/2fa/methods/${encodeURIComponent(method)}`, { method: "DELETE", ...options });
526
+ }
527
+
528
+ /**
529
+ * Replace all backup codes with a new set. The previous codes stop working; the new ones are shown only once.
530
+ * Requires a fresh confirmTwoFactorIdentity from the same session (403 otherwise); each confirmation unlocks one change.
531
+ * @async
532
+ * @roles admin, developer, billing, user
533
+ * @param {Object} [params]
534
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
535
+ * @returns {Promise<Object>} The response from the server ({ codes, settings })
536
+ */
537
+ async regenerateBackupCodes({ options = {} } = {}) {
538
+ return this.client(`/auth/2fa/backup-codes`, { method: "POST", ...options });
539
+ }
540
+
541
+ /**
542
+ * Stop trusting a device, so its next sign-in asks for the second factor again
543
+ * @async
544
+ * @roles admin, developer, billing, user
545
+ * @param {Object} params
546
+ * @param {string} params.deviceId - The trusted device's id from getTwoFactorSettings
547
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
548
+ * @returns {Promise<Object>} The response from the server (the settings object)
549
+ */
550
+ async revokeTrustedDevice({ deviceId, options = {} }) {
551
+ this.client._require({ deviceId });
552
+ return this.client(`/auth/2fa/trusted-devices/${encodeURIComponent(deviceId)}`, { method: "DELETE", ...options });
553
+ }
554
+
555
+ /**
556
+ * Turn two-factor authentication off: removes every method, backup code and trusted device.
557
+ * Requires a fresh confirmTwoFactorIdentity from the same session (403 otherwise); each confirmation unlocks one change.
558
+ * @async
559
+ * @roles admin, developer, billing, user
560
+ * @param {Object} [params]
561
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
562
+ * @returns {Promise<Object>} The response from the server (the settings object)
563
+ */
564
+ async disableTwoFactor({ options = {} } = {}) {
565
+ return this.client(`/auth/2fa`, { method: "DELETE", ...options });
566
+ }
567
+
568
+ /**
569
+ * Whether the "secure your account" enrollment prompt is due for the caller
570
+ * @async
571
+ * @roles admin, developer, billing, user
572
+ * @param {Object} [params]
573
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
574
+ * @returns {Promise<Object>} The response from the server ({ due })
575
+ */
576
+ async getTwoFactorPrompt({ options = {} } = {}) {
577
+ return this.client(`/auth/2fa/prompt`, { method: "GET", ...options });
578
+ }
579
+
580
+ /**
581
+ * Dismiss the enrollment prompt ("Set up later") until the next sign-in. It stops for good after three dismissals.
582
+ * @async
583
+ * @roles admin, developer, billing, user
584
+ * @param {Object} [params]
585
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
586
+ * @returns {Promise<Object>} The response from the server ({ due: false })
587
+ */
588
+ async dismissTwoFactorPrompt({ options = {} } = {}) {
589
+ return this.client(`/auth/2fa/prompt/dismiss`, { method: "POST", ...options });
590
+ }
591
+
592
+ /**
593
+ * Send a sign-in code by text or email for a pending two-factor challenge. Not needed for "app".
594
+ * @async
595
+ * @roles public
596
+ * @param {Object} params
597
+ * @param {string} params.challengeId - From the mfaRequired login or exchange response
598
+ * @param {string} params.method - "sms" or "email"
599
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
600
+ * @returns {Promise<Object>} The response from the server ({ sent, target, expiresInSeconds })
601
+ */
602
+ async sendTwoFactorChallengeCode({ challengeId, method, options = {} }) {
603
+ this.client._require({ challengeId, method });
604
+ return this.client(`/auth/2fa/challenge/${encodeURIComponent(challengeId)}/send`, { method: "POST", body: { method }, ...options });
605
+ }
606
+
607
+ /**
608
+ * Verify a sign-in code (or a backup code) for a pending two-factor challenge and receive the session JWT.
609
+ * With rememberDevice the response also carries a deviceToken to pass on later logins.
610
+ * @async
611
+ * @roles public
612
+ * @param {Object} params
613
+ * @param {string} params.challengeId - From the mfaRequired login or exchange response
614
+ * @param {string} params.code - The 6-digit code, or a backup code (xxxx-xxxx)
615
+ * @param {string} [params.method] - The method the code came from ("app", "sms" or "email"); defaults to the primary method
616
+ * @param {boolean} [params.usingBackupCode] - True when code is a backup code
617
+ * @param {boolean} [params.rememberDevice] - Trust this device for 30 days
618
+ * @param {string} [params.deviceName] - Label for the trusted device (e.g. "Chrome on Windows")
619
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
620
+ * @returns {Promise<Object>} The response from the server ({ token, deviceToken? })
621
+ */
622
+ async verifyTwoFactorChallenge({ challengeId, code, method, usingBackupCode, rememberDevice, deviceName, options = {} }) {
623
+ this.client._require({ challengeId, code });
624
+ return this.client(`/auth/2fa/challenge/${encodeURIComponent(challengeId)}/verify`, {
625
+ method: "POST",
626
+ body: { code, method, usingBackupCode, rememberDevice, deviceName },
627
+ ...options,
628
+ });
629
+ }
630
+
631
+ /**
632
+ * Cancel a pending two-factor challenge (e.g. "Back to sign in")
633
+ * @async
634
+ * @roles public
635
+ * @param {Object} params
636
+ * @param {string} params.challengeId - From the mfaRequired login or exchange response
637
+ * @param {import('../SignalHouseSDK.js').RequestOptions} [params.options] - Additional options for the request
638
+ * @returns {Promise<Object>} The response from the server ({ cancelled: true })
639
+ */
640
+ async cancelTwoFactorChallenge({ challengeId, options = {} }) {
641
+ this.client._require({ challengeId });
642
+ return this.client(`/auth/2fa/challenge/${encodeURIComponent(challengeId)}`, { method: "DELETE", ...options });
643
+ }
225
644
  }
@@ -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