@nulvless/nulvless-js 0.1.5 → 0.1.7

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.cjs CHANGED
@@ -317,6 +317,10 @@ var FactorsClient = class extends AuthSubClient {
317
317
  * the factor on the user's device.
318
318
  *
319
319
  * For TOTP: use `secret` for manual entry or `url` to generate a QR code.
320
+ * For SMS: pass `phone` to send the codes to a number other than the user's.
321
+ *
322
+ * A user holds up to 10 authenticator apps and SMS factors combined, and one
323
+ * email factor and one set of recovery codes.
320
324
  *
321
325
  * After the user configures their device, call `enable` with the `token` and
322
326
  * the first OTP code to activate the factor.
@@ -332,8 +336,9 @@ var FactorsClient = class extends AuthSubClient {
332
336
  async enroll(params, options) {
333
337
  const auth = await this.bearer(options);
334
338
  if (!auth.ok) return { data: null, error: auth.error };
335
- const { nonce, type, name } = params;
336
- return this.http.post(route`/factors/${type}`, name ? { name } : {}, {
339
+ const { nonce, type, name, phone } = params;
340
+ const body = { ...name ? { name } : {}, ...phone ? { phone } : {} };
341
+ return this.http.post(route`/factors/${type}`, body, {
337
342
  ...options,
338
343
  nonce,
339
344
  headers: { ...options?.headers, ...auth.headers }
@@ -379,7 +384,6 @@ var FactorsClient = class extends AuthSubClient {
379
384
 
380
385
  // src/auth/users/index.ts
381
386
  var UsersClient = class extends AuthSubClient {
382
- // ─── Profile ────────────────────────────────────────────────────────────────
383
387
  /**
384
388
  * Returns the authenticated user's full profile.
385
389
  */
@@ -404,7 +408,6 @@ var UsersClient = class extends AuthSubClient {
404
408
  headers: { ...options?.headers, ...auth.headers }
405
409
  });
406
410
  }
407
- // ─── Identities ─────────────────────────────────────────────────────────────
408
411
  /**
409
412
  * Lists all identities (email, phone, OAuth) linked to the authenticated user.
410
413
  *
@@ -495,7 +498,6 @@ var UsersClient = class extends AuthSubClient {
495
498
  headers: { ...options?.headers, ...auth.headers }
496
499
  });
497
500
  }
498
- // ─── Credential updates ──────────────────────────────────────────────────────
499
501
  /**
500
502
  * Sends an OTP to the new email address to initiate an email change.
501
503
  *
@@ -695,14 +697,19 @@ var ChallengesClient = class extends AuthSubClient {
695
697
  * Requires an authenticated session. Prompt the user for the code, then call
696
698
  * `verify({ token, code })`.
697
699
  *
700
+ * A `totp` challenge accepts a code from any of the user's authenticator
701
+ * apps. For `sms_otp`, pass `factor_id` to pick which phone receives it.
702
+ *
698
703
  * @example
699
- * const { data } = await nulvless.auth.challenges.create('totp')
704
+ * const { data } = await nulvless.auth.challenges.create({ type: 'totp' })
705
+ * const { data: sms } = await nulvless.auth.challenges.create({ type: 'sms_otp', factor_id })
700
706
  */
701
- async create(targetType, options) {
707
+ async create(params, options) {
702
708
  const auth = await this.bearer(options);
703
709
  if (!auth.ok) return { data: null, error: auth.error };
704
- return this.http.post(route`/challenges/${targetType}`, void 0, {
710
+ return this.http.post(route`/challenges/${params.type}`, void 0, {
705
711
  ...options,
712
+ ...params.factor_id ? { query: { factor_id: params.factor_id } } : {},
706
713
  headers: { ...options?.headers, ...auth.headers }
707
714
  });
708
715
  }
@@ -722,7 +729,7 @@ var ChallengesClient = class extends AuthSubClient {
722
729
  return this.http.patch(
723
730
  route`/challenges/${params.type}`,
724
731
  { token: params.token },
725
- options
732
+ params.factor_id ? { ...options, query: { factor_id: params.factor_id } } : options
726
733
  );
727
734
  }
728
735
  /**
@@ -922,7 +929,6 @@ var OAuthClient = class extends AuthSubClient {
922
929
  super(http, getToken);
923
930
  this.grants = new OAuthGrantsClient(http, getToken);
924
931
  }
925
- // ─── Authorization redirect (platform key) ──────────────────────────────────
926
932
  /**
927
933
  * Builds the OAuth authorization URL and, in the browser, redirects the user
928
934
  * agent to it. On the server the URL is returned for manual handling.
@@ -957,7 +963,9 @@ var OAuthClient = class extends AuthSubClient {
957
963
  scope: params.scope,
958
964
  state: params.state,
959
965
  resource: params.resource,
960
- nonce: params.nonce
966
+ nonce: params.nonce,
967
+ prompt: params.prompt,
968
+ max_age: params.max_age === void 0 ? void 0 : String(params.max_age)
961
969
  };
962
970
  for (const [key, value] of Object.entries(query)) {
963
971
  if (value !== void 0) url.searchParams.set(key, value);
@@ -967,7 +975,6 @@ var OAuthClient = class extends AuthSubClient {
967
975
  }
968
976
  return { data: { url: url.toString() }, error: null };
969
977
  }
970
- // ─── Token endpoint (public) ────────────────────────────────────────────────
971
978
  /**
972
979
  * Exchanges an authorization code for tokens
973
980
  * (`POST /oauth/token`, `grant_type=authorization_code`).
@@ -997,7 +1004,6 @@ var OAuthClient = class extends AuthSubClient {
997
1004
  { ...options, skipApiKey: true }
998
1005
  );
999
1006
  }
1000
- // ─── Dynamic registration (platform key) ────────────────────────────────────
1001
1007
  /**
1002
1008
  * Dynamically registers a new OAuth app (RFC 7591, `POST /oauth/register`).
1003
1009
  *
@@ -1007,7 +1013,6 @@ var OAuthClient = class extends AuthSubClient {
1007
1013
  register(params, options) {
1008
1014
  return this.http.post("/oauth/register", params, { ...options, skipApiKey: true });
1009
1015
  }
1010
- // ─── Consent flow (authenticated user) ──────────────────────────────────────
1011
1016
  /**
1012
1017
  * Loads a pending authorization for the consent screen
1013
1018
  * (`GET /oauth/authorizations/:id`).
@@ -1042,7 +1047,6 @@ var OAuthClient = class extends AuthSubClient {
1042
1047
  headers: { ...options?.headers, ...auth.headers }
1043
1048
  });
1044
1049
  }
1045
- // ─── UserInfo (authenticated user) ──────────────────────────────────────────
1046
1050
  /**
1047
1051
  * Returns OIDC UserInfo claims for the access token (`GET /oauth/userinfo`).
1048
1052
  *
@@ -1058,7 +1062,6 @@ var OAuthClient = class extends AuthSubClient {
1058
1062
  headers: { ...options?.headers, ...auth.headers }
1059
1063
  });
1060
1064
  }
1061
- // ─── Public OIDC metadata (no auth) ─────────────────────────────────────────
1062
1065
  /**
1063
1066
  * Returns the OpenID Connect discovery document
1064
1067
  * (`GET /.well-known/openid-configuration`). Public — no auth required.
@@ -1283,12 +1286,6 @@ var AdminClient = class {
1283
1286
  roles;
1284
1287
  grants;
1285
1288
  oauthClients;
1286
- /**
1287
- * Returns basic platform information (id, name, slug).
1288
- */
1289
- getPlatform(options) {
1290
- return this.http.get("/admin/platform", options);
1291
- }
1292
1289
  };
1293
1290
 
1294
1291
  // src/session/stored.ts
@@ -1463,14 +1460,12 @@ var AuthClient = class {
1463
1460
  async getAccessToken() {
1464
1461
  return this.session?.getValidToken() ?? null;
1465
1462
  }
1466
- // ─── Helpers ──────────────────────────────────────────────────────────────
1467
1463
  async persistSession(result) {
1468
1464
  if (!result.error && result.data.access_token && this.session) {
1469
1465
  await this.session.save(result.data);
1470
1466
  }
1471
1467
  return result;
1472
1468
  }
1473
- // ─── Sign-up / Sign-in ─────────────────────────────────────────────────────
1474
1469
  /**
1475
1470
  * Creates a new user account.
1476
1471
  *
@@ -1631,7 +1626,6 @@ var AuthClient = class {
1631
1626
  headers: { ...options?.headers, ...auth.headers }
1632
1627
  });
1633
1628
  }
1634
- // ─── Challenge ─────────────────────────────────────────────────────────────
1635
1629
  /**
1636
1630
  * Looks up whether an identifier exists and which sign-in method applies.
1637
1631
  *
@@ -1658,7 +1652,6 @@ var AuthClient = class {
1658
1652
  async verifyChallenge(params, options) {
1659
1653
  return this.challenges.verify(params, options);
1660
1654
  }
1661
- // ─── Account lifecycle ─────────────────────────────────────────────────────
1662
1655
  /**
1663
1656
  * Activates an account via the confirmation link sent to the user's email/phone.
1664
1657
  */
@@ -1692,7 +1685,6 @@ var AuthClient = class {
1692
1685
  resetPassword(params, options) {
1693
1686
  return this.http.post("/recover/reset-password", params, options);
1694
1687
  }
1695
- // ─── Session ───────────────────────────────────────────────────────────────
1696
1688
  /**
1697
1689
  * Validates the current session and optionally checks a grant.
1698
1690
  *
@@ -1811,7 +1803,6 @@ var AuthBrowserClient = class extends AuthClient {
1811
1803
  on(event, handler) {
1812
1804
  return this.emitter.on(event, handler);
1813
1805
  }
1814
- // ─── Session persistence override ─────────────────────────────────────────
1815
1806
  async persistSession(result) {
1816
1807
  const out = await super.persistSession(result);
1817
1808
  if (!out.error) {
@@ -1826,7 +1817,6 @@ var AuthBrowserClient = class extends AuthClient {
1826
1817
  }
1827
1818
  return out;
1828
1819
  }
1829
- // ─── Active session helpers ────────────────────────────────────────────────
1830
1820
  /**
1831
1821
  * Returns the session currently stored in storage, or `null` if there is none.
1832
1822
  *
@@ -1858,7 +1848,6 @@ var AuthBrowserClient = class extends AuthClient {
1858
1848
  await this.session?.save(data);
1859
1849
  }
1860
1850
  }
1861
- // ─── Multi-account ─────────────────────────────────────────────────────────
1862
1851
  /**
1863
1852
  * Adds an account to the accounts store without switching the active session.
1864
1853
  *
@@ -1937,7 +1926,6 @@ var AuthBrowserClient = class extends AuthClient {
1937
1926
  }
1938
1927
  await this.session?.clear();
1939
1928
  }
1940
- // ─── signOut override ──────────────────────────────────────────────────────
1941
1929
  async signOut(scope, options) {
1942
1930
  const stored = await this.session?.get();
1943
1931
  const userId = stored ? stored.user?.id ?? extractUserId({ access_token: stored.access_token }) : null;