@passflow/core 0.26.0 → 0.28.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.d.cts CHANGED
@@ -1287,13 +1287,21 @@ export type PassflowResponseError = {
1287
1287
  time: string;
1288
1288
  };
1289
1289
  };
1290
+ /** Id of the error a call rejects with when the Passflow API cannot be reached or its gateway answers 502, 503 or 504. */
1291
+ export declare const SERVICE_UNAVAILABLE_ERROR_ID = "error.service.unavailable";
1292
+ /** Message of the {@link SERVICE_UNAVAILABLE_ERROR_ID} error. */
1293
+ export declare const SERVICE_UNAVAILABLE_MESSAGE = "Passflow is temporarily unavailable. Please try again in a moment.";
1290
1294
  export declare class PassflowError extends Error {
1291
1295
  id: string;
1292
1296
  message: string;
1293
1297
  status: number;
1294
1298
  location: string;
1295
1299
  time: string;
1296
- constructor(error: PassflowResponseError['error']);
1300
+ /** Declared here rather than inherited: `Error.cause` is ES2022 and this build targets ES2021 libs. */
1301
+ readonly cause?: unknown;
1302
+ constructor(error: PassflowResponseError['error'], options?: {
1303
+ cause?: unknown;
1304
+ });
1297
1305
  }
1298
1306
  export type PassflowSignInPayload = {
1299
1307
  password: string;
@@ -3477,8 +3485,11 @@ type PassflowEventPayload = {
3477
3485
  parsedTokens?: ParsedTokens;
3478
3486
  /** `'other-tab'` only when an ended tab revives on a new session found in storage. Absent on this tab's own sign-in. */
3479
3487
  origin?: EventOrigin;
3480
- /** Set only when a federated redirect landed here and this instance exchanged its code. */
3481
- source?: 'federated-landing';
3488
+ /**
3489
+ * `'federated-landing'`: a federated redirect landed here and this instance exchanged its code.
3490
+ * `'tokens-in-url'`: tokens received in this page's URL were verified and saved.
3491
+ */
3492
+ source?: 'federated-landing' | 'tokens-in-url';
3482
3493
  };
3483
3494
  [PassflowEvent.SignInStart]: {
3484
3495
  email?: string;
@@ -5610,26 +5621,29 @@ export declare class Passflow {
5610
5621
  */
5611
5622
  unsubscribe(subscriber: PassflowSubscriber, events?: PassflowEvent[]): void;
5612
5623
  /**
5613
- * Handle OAuth redirect callback and extract tokens from URL query parameters.
5624
+ * Handle OAuth redirect callback and take tokens from the URL query or fragment.
5614
5625
  * This method should be called on the redirect page after authentication.
5615
5626
  *
5616
- * @returns Tokens object if found in URL, undefined otherwise
5627
+ * The tokens are removed from the URL at once, then verified in the background against the
5628
+ * configured server's published keys and this app id (required). `SignIn` with
5629
+ * `source: 'tokens-in-url'` (tokens saved), or `Error` with operation `tokens.from-url` (nothing
5630
+ * saved), reports the outcome, so subscribe first.
5617
5631
  *
5618
5632
  * @example
5619
5633
  * ```typescript
5620
5634
  * // On your redirect page (e.g., /auth/callback)
5621
- * const tokens = passflow.handleTokensRedirect();
5622
- * if (tokens) {
5623
- * console.log('Authentication successful', tokens.access_token);
5624
- * // Tokens are automatically saved to storage
5625
- * }
5635
+ * passflow.subscribe(
5636
+ * { onAuthChange: (event, payload) => console.log(event, payload) },
5637
+ * [PassflowEvent.SignIn, PassflowEvent.Error],
5638
+ * );
5639
+ * passflow.handleTokensRedirect();
5626
5640
  * ```
5627
5641
  *
5628
5642
  * A PKCE federated landing (`?code=`) returns `undefined` and finishes in the background: `SignIn`
5629
5643
  * or `TwoFactorRequired` is the signal. With `deferFederatedLanding` it is left to
5630
5644
  * `completeFederatedLanding()`.
5631
5645
  */
5632
- handleTokensRedirect(): Tokens | undefined;
5646
+ handleTokensRedirect(): void;
5633
5647
  /**
5634
5648
  * Takes a PKCE federated landing (`?code=&user_state=`) on this page, for an instance built with
5635
5649
  * `deferFederatedLanding`. The code is exchanged in the background; `SignIn` with
@@ -5655,6 +5669,10 @@ export declare class Passflow {
5655
5669
  */
5656
5670
  private adoptTwoFactorTokenFromUrl;
5657
5671
  private checkErrorsFromURL;
5672
+ /**
5673
+ * When a token appears in the query or the fragment, removes every token from the query and drops
5674
+ * a token-carrying fragment, in one history replace. Other query params stay.
5675
+ */
5658
5676
  private cleanupUrlParams;
5659
5677
  private setTokensToCacheFromLocalStorage;
5660
5678
  /**
package/dist/index.d.ts CHANGED
@@ -1287,13 +1287,21 @@ export type PassflowResponseError = {
1287
1287
  time: string;
1288
1288
  };
1289
1289
  };
1290
+ /** Id of the error a call rejects with when the Passflow API cannot be reached or its gateway answers 502, 503 or 504. */
1291
+ export declare const SERVICE_UNAVAILABLE_ERROR_ID = "error.service.unavailable";
1292
+ /** Message of the {@link SERVICE_UNAVAILABLE_ERROR_ID} error. */
1293
+ export declare const SERVICE_UNAVAILABLE_MESSAGE = "Passflow is temporarily unavailable. Please try again in a moment.";
1290
1294
  export declare class PassflowError extends Error {
1291
1295
  id: string;
1292
1296
  message: string;
1293
1297
  status: number;
1294
1298
  location: string;
1295
1299
  time: string;
1296
- constructor(error: PassflowResponseError['error']);
1300
+ /** Declared here rather than inherited: `Error.cause` is ES2022 and this build targets ES2021 libs. */
1301
+ readonly cause?: unknown;
1302
+ constructor(error: PassflowResponseError['error'], options?: {
1303
+ cause?: unknown;
1304
+ });
1297
1305
  }
1298
1306
  export type PassflowSignInPayload = {
1299
1307
  password: string;
@@ -3477,8 +3485,11 @@ type PassflowEventPayload = {
3477
3485
  parsedTokens?: ParsedTokens;
3478
3486
  /** `'other-tab'` only when an ended tab revives on a new session found in storage. Absent on this tab's own sign-in. */
3479
3487
  origin?: EventOrigin;
3480
- /** Set only when a federated redirect landed here and this instance exchanged its code. */
3481
- source?: 'federated-landing';
3488
+ /**
3489
+ * `'federated-landing'`: a federated redirect landed here and this instance exchanged its code.
3490
+ * `'tokens-in-url'`: tokens received in this page's URL were verified and saved.
3491
+ */
3492
+ source?: 'federated-landing' | 'tokens-in-url';
3482
3493
  };
3483
3494
  [PassflowEvent.SignInStart]: {
3484
3495
  email?: string;
@@ -5610,26 +5621,29 @@ export declare class Passflow {
5610
5621
  */
5611
5622
  unsubscribe(subscriber: PassflowSubscriber, events?: PassflowEvent[]): void;
5612
5623
  /**
5613
- * Handle OAuth redirect callback and extract tokens from URL query parameters.
5624
+ * Handle OAuth redirect callback and take tokens from the URL query or fragment.
5614
5625
  * This method should be called on the redirect page after authentication.
5615
5626
  *
5616
- * @returns Tokens object if found in URL, undefined otherwise
5627
+ * The tokens are removed from the URL at once, then verified in the background against the
5628
+ * configured server's published keys and this app id (required). `SignIn` with
5629
+ * `source: 'tokens-in-url'` (tokens saved), or `Error` with operation `tokens.from-url` (nothing
5630
+ * saved), reports the outcome, so subscribe first.
5617
5631
  *
5618
5632
  * @example
5619
5633
  * ```typescript
5620
5634
  * // On your redirect page (e.g., /auth/callback)
5621
- * const tokens = passflow.handleTokensRedirect();
5622
- * if (tokens) {
5623
- * console.log('Authentication successful', tokens.access_token);
5624
- * // Tokens are automatically saved to storage
5625
- * }
5635
+ * passflow.subscribe(
5636
+ * { onAuthChange: (event, payload) => console.log(event, payload) },
5637
+ * [PassflowEvent.SignIn, PassflowEvent.Error],
5638
+ * );
5639
+ * passflow.handleTokensRedirect();
5626
5640
  * ```
5627
5641
  *
5628
5642
  * A PKCE federated landing (`?code=`) returns `undefined` and finishes in the background: `SignIn`
5629
5643
  * or `TwoFactorRequired` is the signal. With `deferFederatedLanding` it is left to
5630
5644
  * `completeFederatedLanding()`.
5631
5645
  */
5632
- handleTokensRedirect(): Tokens | undefined;
5646
+ handleTokensRedirect(): void;
5633
5647
  /**
5634
5648
  * Takes a PKCE federated landing (`?code=&user_state=`) on this page, for an instance built with
5635
5649
  * `deferFederatedLanding`. The code is exchanged in the background; `SignIn` with
@@ -5655,6 +5669,10 @@ export declare class Passflow {
5655
5669
  */
5656
5670
  private adoptTwoFactorTokenFromUrl;
5657
5671
  private checkErrorsFromURL;
5672
+ /**
5673
+ * When a token appears in the query or the fragment, removes every token from the query and drops
5674
+ * a token-carrying fragment, in one history replace. Other query params stay.
5675
+ */
5658
5676
  private cleanupUrlParams;
5659
5677
  private setTokensToCacheFromLocalStorage;
5660
5678
  /**