herald-auth-web 0.6.9 → 0.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/dist/index.js CHANGED
@@ -878,6 +878,22 @@ var handlePasskeyVerify = (options) => (options.client ?? client).post({
878
878
  ...options.headers
879
879
  }
880
880
  });
881
+ var smsOtpSend = (options) => (options.client ?? client).post({
882
+ url: "/api/auth/{realmId}/login/sms-otp/send",
883
+ ...options,
884
+ headers: {
885
+ "Content-Type": "application/json",
886
+ ...options.headers
887
+ }
888
+ });
889
+ var smsOtpVerify = (options) => (options.client ?? client).post({
890
+ url: "/api/auth/{realmId}/login/sms-otp/verify",
891
+ ...options,
892
+ headers: {
893
+ "Content-Type": "application/json",
894
+ ...options.headers
895
+ }
896
+ });
881
897
  var handleVerifyTotp = (options) => (options.client ?? client).post({
882
898
  url: "/api/auth/{realmId}/login/verify-totp",
883
899
  ...options,
@@ -1324,6 +1340,76 @@ function createAuth(deps) {
1324
1340
  return toLoginResult(body, deps);
1325
1341
  }
1326
1342
  },
1343
+ loginWithSmsOtp: {
1344
+ /**
1345
+ * Send a passwordless SMS login code. The single 409 control-flow
1346
+ * outcome — `phone_not_registered` (no account matches; no code is sent
1347
+ * and none is created, DEC-phone-login-001) — resolves as
1348
+ * `{ kind: 'conflict' }` instead of throwing. SMS OTP has no
1349
+ * auto-register consent branch, unlike `loginWithEmailOtp.send`. All
1350
+ * other HTTP failures throw `HeraldError`.
1351
+ */
1352
+ async send(payload) {
1353
+ const { data, error, response } = await smsOtpSend({
1354
+ client: client2,
1355
+ path: { realmId },
1356
+ body: {
1357
+ clientId: deps.clientId,
1358
+ phone: payload.phone,
1359
+ ...payload.turnstileToken ? { turnstileToken: payload.turnstileToken } : {}
1360
+ }
1361
+ });
1362
+ if (data) {
1363
+ return {
1364
+ kind: "sent",
1365
+ message: data.message,
1366
+ expiresInSeconds: data.expiresInSeconds,
1367
+ maskedPhone: data.maskedPhone
1368
+ };
1369
+ }
1370
+ const body = error ?? {};
1371
+ if (response?.status === 409 && body["code"] === "phone_not_registered") {
1372
+ return {
1373
+ kind: "conflict",
1374
+ code: String(body["code"]),
1375
+ message: String(body["message"] ?? "")
1376
+ };
1377
+ }
1378
+ throw toHeraldError(error, response);
1379
+ },
1380
+ /**
1381
+ * Verify an SMS login code. On success the issued token set is applied
1382
+ * internally and the result mirrors the other `loginWith*` verify
1383
+ * methods. The documented 409 `phone_not_registered` (the account was
1384
+ * anonymized between send and verify, backend `sms_otp.rs`) resolves as
1385
+ * `{ kind: 'conflict' }` — the same shape as `send` — instead of
1386
+ * throwing. All other HTTP failures throw `HeraldError`.
1387
+ */
1388
+ async verify(payload) {
1389
+ const { data, error, response } = await smsOtpVerify({
1390
+ client: client2,
1391
+ path: { realmId },
1392
+ body: {
1393
+ clientId: deps.clientId,
1394
+ phone: payload.phone,
1395
+ code: payload.code,
1396
+ ...payload.turnstileToken ? { turnstileToken: payload.turnstileToken } : {}
1397
+ }
1398
+ });
1399
+ if (data) {
1400
+ return toLoginResult(data, deps);
1401
+ }
1402
+ const errBody = error ?? {};
1403
+ if (response?.status === 409 && errBody["code"] === "phone_not_registered") {
1404
+ return {
1405
+ kind: "conflict",
1406
+ code: String(errBody["code"]),
1407
+ message: String(errBody["message"] ?? "")
1408
+ };
1409
+ }
1410
+ throw toHeraldError(error, response);
1411
+ }
1412
+ },
1327
1413
  async getStatus() {
1328
1414
  const data = await resolveOp(status({ client: client2 }));
1329
1415
  deps.session.emit({ type: "authenticated", session: sessionFromStatus(data, deps) });