@depup/supabase__auth-js 2.115.0-depup.0 → 2.117.0-depup.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.
Files changed (51) hide show
  1. package/README.md +2 -2
  2. package/changes.json +1 -1
  3. package/dist/main/GoTrueAdminApi.d.ts +0 -6
  4. package/dist/main/GoTrueAdminApi.d.ts.map +1 -1
  5. package/dist/main/GoTrueAdminApi.js +0 -6
  6. package/dist/main/GoTrueAdminApi.js.map +1 -1
  7. package/dist/main/GoTrueClient.d.ts +45 -4
  8. package/dist/main/GoTrueClient.d.ts.map +1 -1
  9. package/dist/main/GoTrueClient.js +203 -13
  10. package/dist/main/GoTrueClient.js.map +1 -1
  11. package/dist/main/lib/error-codes.d.ts +1 -1
  12. package/dist/main/lib/error-codes.d.ts.map +1 -1
  13. package/dist/main/lib/helpers.d.ts +2 -2
  14. package/dist/main/lib/helpers.d.ts.map +1 -1
  15. package/dist/main/lib/helpers.js +4 -4
  16. package/dist/main/lib/helpers.js.map +1 -1
  17. package/dist/main/lib/types.d.ts +387 -10
  18. package/dist/main/lib/types.d.ts.map +1 -1
  19. package/dist/main/lib/types.js +2 -1
  20. package/dist/main/lib/types.js.map +1 -1
  21. package/dist/main/lib/version.d.ts +1 -1
  22. package/dist/main/lib/version.js +1 -1
  23. package/dist/module/GoTrueAdminApi.d.ts +0 -6
  24. package/dist/module/GoTrueAdminApi.d.ts.map +1 -1
  25. package/dist/module/GoTrueAdminApi.js +1 -7
  26. package/dist/module/GoTrueAdminApi.js.map +1 -1
  27. package/dist/module/GoTrueClient.d.ts +45 -4
  28. package/dist/module/GoTrueClient.d.ts.map +1 -1
  29. package/dist/module/GoTrueClient.js +204 -14
  30. package/dist/module/GoTrueClient.js.map +1 -1
  31. package/dist/module/lib/error-codes.d.ts +1 -1
  32. package/dist/module/lib/error-codes.d.ts.map +1 -1
  33. package/dist/module/lib/helpers.d.ts +2 -2
  34. package/dist/module/lib/helpers.d.ts.map +1 -1
  35. package/dist/module/lib/helpers.js +3 -3
  36. package/dist/module/lib/helpers.js.map +1 -1
  37. package/dist/module/lib/types.d.ts +387 -10
  38. package/dist/module/lib/types.d.ts.map +1 -1
  39. package/dist/module/lib/types.js +2 -1
  40. package/dist/module/lib/types.js.map +1 -1
  41. package/dist/module/lib/version.d.ts +1 -1
  42. package/dist/module/lib/version.js +1 -1
  43. package/dist/tsconfig.module.tsbuildinfo +1 -1
  44. package/dist/tsconfig.tsbuildinfo +1 -1
  45. package/package.json +3 -3
  46. package/src/GoTrueAdminApi.ts +1 -9
  47. package/src/GoTrueClient.ts +246 -15
  48. package/src/lib/error-codes.ts +5 -0
  49. package/src/lib/helpers.ts +5 -3
  50. package/src/lib/types.ts +408 -9
  51. package/src/lib/version.ts +1 -1
@@ -2,7 +2,7 @@ import GoTrueAdminApi from './GoTrueAdminApi';
2
2
  import { AUTO_REFRESH_TICK_DURATION_MS, AUTO_REFRESH_TICK_THRESHOLD, DEFAULT_HEADERS, EXPIRY_MARGIN_MS, GOTRUE_URL, JWKS_TTL, PKCE_FLOW_ID_PARAM, REFRESH_FAILURE_COOLDOWN_MS, STORAGE_KEY, } from './lib/constants';
3
3
  import { AuthImplicitGrantRedirectError, AuthInvalidCredentialsError, AuthInvalidJwtError, AuthInvalidTokenResponseError, AuthPKCECodeVerifierMissingError, AuthPKCEGrantCodeExchangeError, AuthRefreshDiscardedError, AuthSessionMissingError, AuthUnknownError, isAuthApiError, isAuthError, isAuthImplicitGrantRedirectError, isAuthRefreshDiscardedError, isAuthRetryableFetchError, isAuthSessionMissingError, } from './lib/errors';
4
4
  import { _request, _sessionResponse, _sessionResponsePassword, _ssoResponse, _userResponse, } from './lib/fetch';
5
- import { appendFlowIdToRedirectTo, assertPasskeyExperimentalEnabled, decodeJWT, deepClone, Deferred, generateCallbackId, getAlgorithm, getCodeChallengeAndMethod, getItemAsync, insecureUserWarningProxy, isBrowser, parseParametersFromURL, pkceVerifierSlotKey, removeAllPKCEVerifiers, removeItemAsync, removePKCEVerifier, resolveFetch, retrievePKCEVerifier, retryable, setItemAsync, sleep, supportsLocalStorage, userNotAvailableProxy, validateExp, validatePKCEFlowId, } from './lib/helpers';
5
+ import { appendFlowIdToRedirectTo, assertRecoveryCodesExperimentalEnabled, decodeJWT, deepClone, Deferred, expiresAt, generateCallbackId, getAlgorithm, getCodeChallengeAndMethod, getItemAsync, insecureUserWarningProxy, isBrowser, parseParametersFromURL, pkceVerifierSlotKey, removeAllPKCEVerifiers, removeItemAsync, removePKCEVerifier, resolveFetch, retrievePKCEVerifier, retryable, setItemAsync, sleep, supportsLocalStorage, userNotAvailableProxy, validateExp, validatePKCEFlowId, } from './lib/helpers';
6
6
  import { memoryLocalStorageAdapter } from './lib/local-storage';
7
7
  import { LockAcquireTimeoutError } from './lib/locks';
8
8
  import { polyfillGlobalThis } from './lib/polyfills';
@@ -219,6 +219,13 @@ class GoTrueClient {
219
219
  challengeAndVerify: this._challengeAndVerify.bind(this),
220
220
  getAuthenticatorAssuranceLevel: this._getAuthenticatorAssuranceLevel.bind(this),
221
221
  webauthn: new WebAuthnApi(this),
222
+ recoveryCodes: {
223
+ getStatus: this._getRecoveryCodesStatus.bind(this),
224
+ generate: this._generateRecoveryCodes.bind(this),
225
+ verify: this._verifyRecoveryCode.bind(this),
226
+ regenerate: this._regenerateRecoveryCodes.bind(this),
227
+ unenroll: this._unenrollRecoveryCodes.bind(this),
228
+ },
222
229
  };
223
230
  this.oauth = {
224
231
  getAuthorizationDetails: this._getAuthorizationDetails.bind(this),
@@ -3657,6 +3664,12 @@ class GoTrueClient {
3657
3664
  catch (err) {
3658
3665
  await ((_b = this.stateChangeEmitters.get(id)) === null || _b === void 0 ? void 0 : _b.callback('INITIAL_SESSION', null));
3659
3666
  this._debug('INITIAL_SESSION', 'callback id', id, 'error', err);
3667
+ if (isAuthRefreshDiscardedError(err)) {
3668
+ // Same successful no-op _recoverAndRefresh treats as debug-only: the
3669
+ // commit guard discarded a refresh because a concurrent signOut
3670
+ // changed session state mid-flight.
3671
+ return;
3672
+ }
3660
3673
  if (isAuthSessionMissingError(err) ||
3661
3674
  isAuthRetryableFetchError(err) ||
3662
3675
  (isAuthApiError(err) &&
@@ -5002,11 +5015,15 @@ class GoTrueClient {
5002
5015
  phone: [],
5003
5016
  totp: [],
5004
5017
  webauthn: [],
5018
+ recovery_code: [],
5005
5019
  };
5006
5020
  // loop over the factors ONCE
5007
5021
  for (const factor of (_a = user === null || user === void 0 ? void 0 : user.factors) !== null && _a !== void 0 ? _a : []) {
5008
5022
  data.all.push(factor);
5009
- if (factor.status === 'verified') {
5023
+ // Types that are not recognized are pushed to `all` bucket.
5024
+ if (factor.status === 'verified' &&
5025
+ factor.factor_type in data &&
5026
+ Array.isArray(data[factor.factor_type])) {
5010
5027
  ;
5011
5028
  data[factor.factor_type].push(factor);
5012
5029
  }
@@ -5070,6 +5087,164 @@ class GoTrueClient {
5070
5087
  const currentAuthenticationMethods = payload.amr || [];
5071
5088
  return { data: { currentLevel, nextLevel, currentAuthenticationMethods }, error: null };
5072
5089
  }
5090
+ /**
5091
+ * {@link AuthMFARecoveryCodesApi#getStatus}
5092
+ */
5093
+ async _getRecoveryCodesStatus() {
5094
+ assertRecoveryCodesExperimentalEnabled(this.experimental);
5095
+ try {
5096
+ return await this._useSession(async (result) => {
5097
+ var _a;
5098
+ const { data: sessionData, error: sessionError } = result;
5099
+ if (sessionError) {
5100
+ return this._returnResult({ data: null, error: sessionError });
5101
+ }
5102
+ const { data, error } = await _request(this.fetch, 'GET', `${this.url}/factors/recovery-codes`, {
5103
+ headers: this.headers,
5104
+ jwt: (_a = sessionData === null || sessionData === void 0 ? void 0 : sessionData.session) === null || _a === void 0 ? void 0 : _a.access_token,
5105
+ });
5106
+ if (error) {
5107
+ return this._returnResult({ data: null, error });
5108
+ }
5109
+ return this._returnResult({ data, error: null });
5110
+ });
5111
+ }
5112
+ catch (error) {
5113
+ if (isAuthError(error)) {
5114
+ return this._returnResult({ data: null, error });
5115
+ }
5116
+ throw error;
5117
+ }
5118
+ }
5119
+ /**
5120
+ * {@link AuthMFARecoveryCodesApi#generate}
5121
+ */
5122
+ async _generateRecoveryCodes(params) {
5123
+ assertRecoveryCodesExperimentalEnabled(this.experimental);
5124
+ try {
5125
+ return await this._useSession(async (result) => {
5126
+ var _a;
5127
+ const { data: sessionData, error: sessionError } = result;
5128
+ if (sessionError) {
5129
+ return this._returnResult({ data: null, error: sessionError });
5130
+ }
5131
+ const { data, error } = await _request(this.fetch, 'POST', `${this.url}/factors/recovery-codes`, {
5132
+ // The body is optional server-side; only send one when a name was given.
5133
+ body: (params === null || params === void 0 ? void 0 : params.friendlyName) ? { friendly_name: params.friendlyName } : undefined,
5134
+ headers: this.headers,
5135
+ jwt: (_a = sessionData === null || sessionData === void 0 ? void 0 : sessionData.session) === null || _a === void 0 ? void 0 : _a.access_token,
5136
+ });
5137
+ if (error) {
5138
+ return this._returnResult({ data: null, error });
5139
+ }
5140
+ return this._returnResult({ data, error: null });
5141
+ });
5142
+ }
5143
+ catch (error) {
5144
+ if (isAuthError(error)) {
5145
+ return this._returnResult({ data: null, error });
5146
+ }
5147
+ throw error;
5148
+ }
5149
+ }
5150
+ /**
5151
+ * {@link AuthMFARecoveryCodesApi#verify}
5152
+ */
5153
+ async _verifyRecoveryCode(params) {
5154
+ assertRecoveryCodesExperimentalEnabled(this.experimental);
5155
+ const run = async () => {
5156
+ try {
5157
+ return await this._useSession(async (result) => {
5158
+ var _a;
5159
+ const { data: sessionData, error: sessionError } = result;
5160
+ if (sessionError) {
5161
+ return this._returnResult({ data: null, error: sessionError });
5162
+ }
5163
+ const { data, error } = await _request(this.fetch, 'POST', `${this.url}/factors/recovery-codes/verify`, {
5164
+ body: { code: params.code },
5165
+ headers: this.headers,
5166
+ jwt: (_a = sessionData === null || sessionData === void 0 ? void 0 : sessionData.session) === null || _a === void 0 ? void 0 : _a.access_token,
5167
+ });
5168
+ if (error) {
5169
+ return this._returnResult({ data: null, error });
5170
+ }
5171
+ // A server-provided expires_at takes precedence over the computed one.
5172
+ const session = Object.assign({ expires_at: expiresAt(data.expires_in) }, data);
5173
+ await this._saveSession(session);
5174
+ await this._notifyAllSubscribers('MFA_CHALLENGE_VERIFIED', session);
5175
+ return this._returnResult({ data, error: null });
5176
+ });
5177
+ }
5178
+ catch (error) {
5179
+ if (isAuthError(error)) {
5180
+ return this._returnResult({ data: null, error });
5181
+ }
5182
+ throw error;
5183
+ }
5184
+ };
5185
+ if (this.lock != null) {
5186
+ return this._acquireLock(this.lockAcquireTimeout, run);
5187
+ }
5188
+ return run();
5189
+ }
5190
+ /**
5191
+ * {@link AuthMFARecoveryCodesApi#regenerate}
5192
+ */
5193
+ async _regenerateRecoveryCodes() {
5194
+ assertRecoveryCodesExperimentalEnabled(this.experimental);
5195
+ try {
5196
+ return await this._useSession(async (result) => {
5197
+ var _a;
5198
+ const { data: sessionData, error: sessionError } = result;
5199
+ if (sessionError) {
5200
+ return this._returnResult({ data: null, error: sessionError });
5201
+ }
5202
+ const { data, error } = await _request(this.fetch, 'POST', `${this.url}/factors/recovery-codes/regenerate`, {
5203
+ headers: this.headers,
5204
+ jwt: (_a = sessionData === null || sessionData === void 0 ? void 0 : sessionData.session) === null || _a === void 0 ? void 0 : _a.access_token,
5205
+ });
5206
+ if (error) {
5207
+ return this._returnResult({ data: null, error });
5208
+ }
5209
+ return this._returnResult({ data, error: null });
5210
+ });
5211
+ }
5212
+ catch (error) {
5213
+ if (isAuthError(error)) {
5214
+ return this._returnResult({ data: null, error });
5215
+ }
5216
+ throw error;
5217
+ }
5218
+ }
5219
+ /**
5220
+ * {@link AuthMFARecoveryCodesApi#unenroll}
5221
+ */
5222
+ async _unenrollRecoveryCodes() {
5223
+ assertRecoveryCodesExperimentalEnabled(this.experimental);
5224
+ try {
5225
+ return await this._useSession(async (result) => {
5226
+ var _a;
5227
+ const { data: sessionData, error: sessionError } = result;
5228
+ if (sessionError) {
5229
+ return this._returnResult({ data: null, error: sessionError });
5230
+ }
5231
+ const { data, error } = await _request(this.fetch, 'DELETE', `${this.url}/factors/recovery-codes`, {
5232
+ headers: this.headers,
5233
+ jwt: (_a = sessionData === null || sessionData === void 0 ? void 0 : sessionData.session) === null || _a === void 0 ? void 0 : _a.access_token,
5234
+ });
5235
+ if (error) {
5236
+ return this._returnResult({ data: null, error });
5237
+ }
5238
+ return this._returnResult({ data, error: null });
5239
+ });
5240
+ }
5241
+ catch (error) {
5242
+ if (isAuthError(error)) {
5243
+ return this._returnResult({ data: null, error });
5244
+ }
5245
+ throw error;
5246
+ }
5247
+ }
5073
5248
  /**
5074
5249
  * Retrieves details about an OAuth authorization request.
5075
5250
  * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
@@ -5406,13 +5581,35 @@ class GoTrueClient {
5406
5581
  * 2. Prompts user via navigator.credentials.get()
5407
5582
  * 3. Verifies credential with server and creates session
5408
5583
  *
5409
- * Requires `auth.experimental.passkey: true`.
5584
+ * Pass `options.mediation: 'conditional'` to use WebAuthn Conditional UI
5585
+ * (passkey autofill) instead of the modal picker; the value is forwarded to
5586
+ * `navigator.credentials.get()` unchanged.
5587
+ *
5588
+ * The challenge fetched in step 1 expires after the server's
5589
+ * GOTRUE_WEBAUTHN_CHALLENGE_EXPIRY_DURATION (5 minutes by default). With
5590
+ * `mediation: 'conditional'` the autofill prompt can stay pending for longer
5591
+ * than that: the browser ceremony then still succeeds, but verification fails
5592
+ * with `error_code: "webauthn_challenge_expired"`. Recover by calling
5593
+ * `signInWithPasskey()` again. It fetches a fresh challenge and, unless you
5594
+ * passed your own `options.signal`, cancels the pending ceremony first, so
5595
+ * the browser never sees two concurrent WebAuthn requests; the earlier call
5596
+ * resolves with a `WebAuthnError` whose code is `ERROR_CEREMONY_ABORTED`. If
5597
+ * you pass your own `signal`, abort it before retrying.
5410
5598
  *
5411
5599
  * @category Auth
5600
+ *
5601
+ * @example Sign in with Conditional UI (passkey autofill)
5602
+ * ```js
5603
+ * // <input autocomplete="username webauthn" /> somewhere on the page
5604
+ * const { data, error } = await supabase.auth.signInWithPasskey({
5605
+ * options: {
5606
+ * mediation: 'conditional'
5607
+ * }
5608
+ * });
5609
+ * ```
5412
5610
  */
5413
5611
  async signInWithPasskey(credentials) {
5414
- var _a, _b, _c;
5415
- assertPasskeyExperimentalEnabled(this.experimental);
5612
+ var _a, _b, _c, _d;
5416
5613
  try {
5417
5614
  if (!browserSupportsWebAuthn()) {
5418
5615
  return this._returnResult({
@@ -5433,6 +5630,7 @@ class GoTrueClient {
5433
5630
  const { data: credential, error: credentialError } = await getCredential({
5434
5631
  publicKey: publicKeyOptions,
5435
5632
  signal,
5633
+ mediation: (_d = credentials === null || credentials === void 0 ? void 0 : credentials.options) === null || _d === void 0 ? void 0 : _d.mediation,
5436
5634
  });
5437
5635
  if (credentialError || !credential) {
5438
5636
  return this._returnResult({
@@ -5460,13 +5658,12 @@ class GoTrueClient {
5460
5658
  * 2. Prompts user via navigator.credentials.create()
5461
5659
  * 3. Verifies credential with server
5462
5660
  *
5463
- * Requires an active session. Requires `auth.experimental.passkey: true`.
5661
+ * Requires an active session.
5464
5662
  *
5465
5663
  * @category Auth
5466
5664
  */
5467
5665
  async registerPasskey(credentials) {
5468
5666
  var _a, _b;
5469
- assertPasskeyExperimentalEnabled(this.experimental);
5470
5667
  try {
5471
5668
  if (!browserSupportsWebAuthn()) {
5472
5669
  return this._returnResult({
@@ -5511,7 +5708,6 @@ class GoTrueClient {
5511
5708
  * Returns WebAuthn credential creation options to pass to navigator.credentials.create().
5512
5709
  */
5513
5710
  async _startPasskeyRegistration() {
5514
- assertPasskeyExperimentalEnabled(this.experimental);
5515
5711
  try {
5516
5712
  return await this._useSession(async (result) => {
5517
5713
  const { data: { session }, error: sessionError, } = result;
@@ -5544,7 +5740,6 @@ class GoTrueClient {
5544
5740
  * The credentialResponse should be the serialized output of navigator.credentials.create().
5545
5741
  */
5546
5742
  async _verifyPasskeyRegistration(params) {
5547
- assertPasskeyExperimentalEnabled(this.experimental);
5548
5743
  try {
5549
5744
  return await this._useSession(async (result) => {
5550
5745
  const { data: { session }, error: sessionError, } = result;
@@ -5581,7 +5776,6 @@ class GoTrueClient {
5581
5776
  */
5582
5777
  async _startPasskeyAuthentication(params) {
5583
5778
  var _a;
5584
- assertPasskeyExperimentalEnabled(this.experimental);
5585
5779
  try {
5586
5780
  const { data, error } = await _request(this.fetch, 'POST', `${this.url}/passkeys/authentication/options`, {
5587
5781
  headers: this.headers,
@@ -5606,7 +5800,6 @@ class GoTrueClient {
5606
5800
  * The credential should be the serialized output of navigator.credentials.get().
5607
5801
  */
5608
5802
  async _verifyPasskeyAuthentication(params) {
5609
- assertPasskeyExperimentalEnabled(this.experimental);
5610
5803
  try {
5611
5804
  const { data, error } = await _request(this.fetch, 'POST', `${this.url}/passkeys/authentication/verify`, {
5612
5805
  headers: this.headers,
@@ -5636,7 +5829,6 @@ class GoTrueClient {
5636
5829
  * List all passkeys for the current user.
5637
5830
  */
5638
5831
  async _listPasskeys() {
5639
- assertPasskeyExperimentalEnabled(this.experimental);
5640
5832
  try {
5641
5833
  return await this._useSession(async (result) => {
5642
5834
  const { data: { session }, error: sessionError, } = result;
@@ -5668,7 +5860,6 @@ class GoTrueClient {
5668
5860
  * Update a passkey.
5669
5861
  */
5670
5862
  async _updatePasskey(params) {
5671
- assertPasskeyExperimentalEnabled(this.experimental);
5672
5863
  try {
5673
5864
  return await this._useSession(async (result) => {
5674
5865
  const { data: { session }, error: sessionError, } = result;
@@ -5700,7 +5891,6 @@ class GoTrueClient {
5700
5891
  * Delete a passkey.
5701
5892
  */
5702
5893
  async _deletePasskey(params) {
5703
- assertPasskeyExperimentalEnabled(this.experimental);
5704
5894
  try {
5705
5895
  return await this._useSession(async (result) => {
5706
5896
  const { data: { session }, error: sessionError, } = result;