@signalhouse-sms/sdk 1.5.1 → 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/README.md CHANGED
@@ -51,7 +51,7 @@ Integrated Axios with standardized returns
51
51
  Lightweight and tree-shakeable
52
52
 
53
53
  Documentation
54
- For full API reference and advanced usage, visit https://v2.signalhouse.io
54
+ For full API reference and advanced usage, visit https://app2.signalhouse.io/docs
55
55
 
56
56
  License
57
57
  ISC © Signal House
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signalhouse-sms/sdk",
3
- "version": "1.5.1",
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
  }
@@ -91,6 +91,22 @@
91
91
  * @property {string} updatedAt - Last-update timestamp.
92
92
  */
93
93
 
94
+ /**
95
+ * A paused agent conversation: a person took over the conversation between an agent's number and
96
+ * one contact, so the agent does not answer that contact on that number until someone resumes it. As returned
97
+ * by the server.
98
+ * @typedef {Object} AgentContactPause
99
+ * @property {string} groupId - The group that owns the agent's number.
100
+ * @property {string|null} subgroupId - The number's subgroup.
101
+ * @property {string} channel - The channel; "sms".
102
+ * @property {string} endpointValue - The agent's number: digits only, country code included, no "+".
103
+ * @property {string} contactIdentifier - The contact's number: digits only, country code included, no "+".
104
+ * @property {string} reason - Why it was paused: "human_reply" (a person replied by hand), "escalation" (the agent asked for a person) or "manual".
105
+ * @property {string|null} pausedBy - The user who paused it, when known.
106
+ * @property {string} createdAt - When the conversation was paused.
107
+ * @property {string} updatedAt - Last-update timestamp.
108
+ */
109
+
94
110
  /**
95
111
  * A reply an SMS agent wrote but did not send, held for a person to approve or reject (the
96
112
  * Pending Replies queue), as returned by the server.
@@ -106,7 +122,7 @@
106
122
  * @property {string} inboundText - The contact message the agent was answering.
107
123
  * @property {string} draftText - The reply as the agent wrote it.
108
124
  * @property {string|null} sentText - The text actually sent; differs from draftText when edited.
109
- * @property {string} reason - Why it was held: "review_mode", "escalation", "fallback" or "guardrail".
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.
110
126
  * @property {string} status - "pending", "sending", "sent", "rejected" or "failed" (the send path accepted nothing, e.g. the contact opted out).
111
127
  * @property {string|null} decidedBy - The user who approved or rejected it.
112
128
  * @property {string|null} decidedAt - When it was approved or rejected.
@@ -586,6 +602,70 @@ export class Agents {
586
602
  return this.client(`/agent/endpoints/${safeChannel}/${safeEndpointValue}`, { method: "DELETE", ...options });
587
603
  }
588
604
 
605
+ /**
606
+ * List paused agent conversations in a group, newest first. A paused conversation is one a person took
607
+ * over; the agent stays out of it until it is resumed.
608
+ * @async
609
+ * @roles api, admin, developer, billing, user
610
+ * @param {Object} params - The parameters for listing paused conversations.
611
+ * @param {string} params.groupId - The group whose paused conversations to list (required).
612
+ * @param {string} [params.subgroupId] - Narrow to one subgroup.
613
+ * @param {string} [params.channel] - Narrow to one channel ("sms").
614
+ * @param {string} [params.endpointValue] - Narrow to one agent number (digits only, no "+").
615
+ * @param {string} [params.contactIdentifier] - Narrow to one contact number (digits only, no "+").
616
+ * @param {RequestOptions} [params.options] - Additional options for the request.
617
+ * @throws {Error} Throws an error if the groupId parameter is missing.
618
+ * @returns {Promise<SdkResponse<AgentContactPause[]>>} - The paused conversations returned from the server.
619
+ */
620
+ async getAgentContactPauses({ groupId, subgroupId, channel, endpointValue, contactIdentifier, options = {} }) {
621
+ this.client._require({ groupId });
622
+ const queryString = this.client._getQueryString({ groupId, subgroupId, channel, endpointValue, contactIdentifier });
623
+ return this.client(`/agent/pauses${queryString}`, { method: "GET", ...options });
624
+ }
625
+
626
+ /**
627
+ * Pause an agent on one conversation (its number + one contact). The agent stops answering that contact
628
+ * on that number until the conversation is resumed; there is no timer. The conversation's pending
629
+ * replies are rejected. Pausing a paused conversation keeps the original pause.
630
+ * @async
631
+ * @roles api, admin, developer, billing, user
632
+ * @param {Object} params - The parameters for the pause.
633
+ * @param {string} params.channel - The channel; must be "sms".
634
+ * @param {string} params.endpointValue - The agent's number: 10 to 15 digits, country code included, no "+".
635
+ * @param {string} params.contactIdentifier - The contact's number: 10 to 15 digits, country code included, no "+".
636
+ * @param {Object} [params.pauseData] - `{ reason? }`: "human_reply" or "manual" (the default).
637
+ * @param {RequestOptions} [params.options] - Additional options for the request.
638
+ * @throws {Error} Throws an error if channel, endpointValue, or contactIdentifier is missing.
639
+ * @returns {Promise<SdkResponse<AgentContactPause>>} - The pause returned from the server.
640
+ */
641
+ async pauseAgentConversation({ channel, endpointValue, contactIdentifier, pauseData = {}, options = {} }) {
642
+ this.client._require({ channel, endpointValue, contactIdentifier });
643
+ const safeChannel = encodeURIComponent(channel);
644
+ const safeEndpointValue = encodeURIComponent(endpointValue);
645
+ const safeContactIdentifier = encodeURIComponent(contactIdentifier);
646
+ return this.client(`/agent/pauses/${safeChannel}/${safeEndpointValue}/${safeContactIdentifier}`, { method: "PUT", body: pauseData, ...options });
647
+ }
648
+
649
+ /**
650
+ * Resume an agent on a paused conversation, so it answers the contact's next text again.
651
+ * @async
652
+ * @roles api, admin, developer, billing, user
653
+ * @param {Object} params - The parameters for the resume.
654
+ * @param {string} params.channel - The channel; must be "sms".
655
+ * @param {string} params.endpointValue - The agent's number: 10 to 15 digits, country code included, no "+".
656
+ * @param {string} params.contactIdentifier - The contact's number: 10 to 15 digits, country code included, no "+".
657
+ * @param {RequestOptions} [params.options] - Additional options for the request.
658
+ * @throws {Error} Throws an error if channel, endpointValue, or contactIdentifier is missing.
659
+ * @returns {Promise<SdkResponse<AgentContactPause>>} - The removed pause returned from the server.
660
+ */
661
+ async resumeAgentConversation({ channel, endpointValue, contactIdentifier, options = {} }) {
662
+ this.client._require({ channel, endpointValue, contactIdentifier });
663
+ const safeChannel = encodeURIComponent(channel);
664
+ const safeEndpointValue = encodeURIComponent(endpointValue);
665
+ const safeContactIdentifier = encodeURIComponent(contactIdentifier);
666
+ return this.client(`/agent/pauses/${safeChannel}/${safeEndpointValue}/${safeContactIdentifier}`, { method: "DELETE", ...options });
667
+ }
668
+
589
669
  /**
590
670
  * List held agent replies (the Pending Replies queue) in a group, newest first.
591
671
  * @async
@@ -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
  }