@passflow/core 0.32.0 → 0.33.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
@@ -288,6 +288,13 @@ declare class StorageManager {
288
288
  setAppId(appId: string | undefined): void;
289
289
  /** The stored value, or undefined when it is a JWT issued for another app than this one. */
290
290
  private ownToken;
291
+ /**
292
+ * The value under `key`, the prefixed form of `name`. Earlier versions stored it under the
293
+ * unprefixed `name`: such a value is moved to `key` on first read.
294
+ */
295
+ private readPrefixed;
296
+ /** Removes `key` and the unprefixed `name`, so an old value is not read again. */
297
+ private removePrefixed;
291
298
  private readToken;
292
299
  /** The keys a stored token lives in: the JSON tokens and the cookie-mode ID token. */
293
300
  private tokenValueKeys;
@@ -399,6 +406,8 @@ declare class StorageManager {
399
406
  }
400
407
  declare class DeviceService {
401
408
  private storageManager;
409
+ /** The id this service minted; used when the storage keeps nothing (server rendering). */
410
+ private mintedDeviceId;
402
411
  constructor(storageManager?: StorageManager);
403
412
  getDeviceId(): string;
404
413
  generateUniqueDeviceId(): string;
@@ -1065,6 +1074,8 @@ export declare enum PassflowEndpointPaths {
1065
1074
  userPasskey = "/user/passkey",
1066
1075
  addUserPasskey = "/user/passkey/add/start",
1067
1076
  completeAddUserPasskey = "/user/passkey/add/complete",
1077
+ userSessions = "/user/sessions",
1078
+ userSessionsRevokeOthers = "/user/sessions/revoke-others",
1068
1079
  joinInvitation = "/user/tenant/join",
1069
1080
  tenantPath = "/user/tenant",
1070
1081
  invitationsPath = "/user/tenant/:tenantID/invitations",
@@ -1769,6 +1780,41 @@ export type PassflowUserPasskey = {
1769
1780
  count?: number;
1770
1781
  enrolled_with_app_id?: string;
1771
1782
  };
1783
+ /** The device a session was signed in from, as the server recorded it. */
1784
+ export type PassflowSessionDevice = {
1785
+ name?: string;
1786
+ /**
1787
+ * App type the session was signed in with. Known values: `web`, `spa`, `bff`, `android`, `ios`,
1788
+ * `desktop`, `cli`, `m2m`, `other`, `undefined`. The server may add more.
1789
+ */
1790
+ type?: string;
1791
+ user_agent?: string;
1792
+ ip?: string;
1793
+ location?: string;
1794
+ /** RFC 3339 time of the last request made with this session. */
1795
+ last_seen?: string;
1796
+ };
1797
+ /** One signed-in session of the current user. */
1798
+ export type PassflowUserSession = {
1799
+ id: string;
1800
+ app_id: string;
1801
+ /** RFC 3339 */
1802
+ created_at: string;
1803
+ /** RFC 3339 time of the sign-in this session started with. */
1804
+ auth_time: string;
1805
+ /** RFC 3339; absent when the session has no end. */
1806
+ expires_at?: string;
1807
+ /** `true` for the session that made the request. */
1808
+ current: boolean;
1809
+ device?: PassflowSessionDevice;
1810
+ };
1811
+ export type PassflowUserSessionList = {
1812
+ sessions: PassflowUserSession[];
1813
+ };
1814
+ export type PassflowRevokeOtherSessionsResponse = {
1815
+ /** How many sessions were ended. */
1816
+ revoked: number;
1817
+ };
1772
1818
  export type PassflowSendPasswordResetEmailPayload = {
1773
1819
  reset_page_url?: string;
1774
1820
  redirect_url?: string;
@@ -2836,6 +2882,9 @@ export declare class UserAPI {
2836
2882
  passkeyUsername?: string;
2837
2883
  }): Promise<PassflowPasskeyStart>;
2838
2884
  addUserPasskeyComplete(passkeyData: RegistrationResponseJSON, deviceId: string, challengeId: string): Promise<void>;
2885
+ getUserSessions(): Promise<PassflowUserSessionList>;
2886
+ revokeUserSession(sessionId: string): Promise<void>;
2887
+ revokeOtherUserSessions(): Promise<PassflowRevokeOtherSessionsResponse>;
2839
2888
  }
2840
2889
  export declare const APP_ID_HEADER_KEY = "X-Passflow-Clientid";
2841
2890
  export declare const AUTHORIZATION_HEADER_KEY = "Authorization";
@@ -3633,7 +3682,7 @@ export declare enum PassflowEvent {
3633
3682
  * The SDK operation that failed (`ErrorPayload.operation`). The SDK sets it on every `Error` it
3634
3683
  * emits, so a subscriber can tell a failed sign-in from a failed refresh without parsing messages.
3635
3684
  */
3636
- type PassflowOperation = 'sign-in' | 'sign-up' | 'passwordless.start' | 'passwordless.complete' | 'passwordless.wait' | 'passwordless.approval' | 'password-reset.send' | 'password-reset.complete' | 'email-verification.complete' | 'passkey.register' | 'passkey.authenticate' | 'federated.popup' | 'federated.redirect' | 'auth-redirect.url' | 'auth-redirect' | 'redirect.check' | 'auth.is-authenticated' | 'session.check' | 'tokens.get' | 'tokens.load' | 'tokens.from-url' | 'oidc.redirect' | 'refresh' | 'upgrade.commit' | 'log-out' | 'reset' | 'settings.app' | 'settings.all' | 'settings.password-policy' | 'settings.passkey' | 'passkey.list' | 'passkey.rename' | 'passkey.delete' | 'passkey.add' | 'tenant.create' | 'invitation.join' | 'invitation.request-link' | 'invitation.list' | 'invitation.delete' | 'invitation.resend' | 'invitation.get-link' | '2fa.status' | '2fa.setup.begin' | '2fa.setup.confirm' | '2fa.enrollment.read' | '2fa.enrollment.setup-link' | '2fa.verify' | '2fa.recovery.use' | '2fa.disable' | '2fa.recovery.regenerate' | '2fa.methods.available' | '2fa.methods.registered' | '2fa.method.setup.start' | '2fa.method.setup.complete' | '2fa.method.remove' | '2fa.challenge.request' | '2fa.challenge.verify' | '2fa.method.switch' | '2fa.trusted-devices.list' | '2fa.trusted-devices.revoke';
3685
+ type PassflowOperation = 'sign-in' | 'sign-up' | 'passwordless.start' | 'passwordless.complete' | 'passwordless.wait' | 'passwordless.approval' | 'password-reset.send' | 'password-reset.complete' | 'email-verification.complete' | 'passkey.register' | 'passkey.authenticate' | 'federated.popup' | 'federated.redirect' | 'auth-redirect.url' | 'auth-redirect' | 'redirect.check' | 'auth.is-authenticated' | 'session.check' | 'session.list' | 'session.revoke' | 'session.revoke-others' | 'tokens.get' | 'tokens.load' | 'tokens.from-url' | 'oidc.redirect' | 'refresh' | 'upgrade.commit' | 'log-out' | 'reset' | 'settings.app' | 'settings.all' | 'settings.password-policy' | 'settings.passkey' | 'passkey.list' | 'passkey.rename' | 'passkey.delete' | 'passkey.add' | 'tenant.create' | 'invitation.join' | 'invitation.request-link' | 'invitation.list' | 'invitation.delete' | 'invitation.resend' | 'invitation.get-link' | '2fa.status' | '2fa.setup.begin' | '2fa.setup.confirm' | '2fa.enrollment.read' | '2fa.enrollment.setup-link' | '2fa.verify' | '2fa.recovery.use' | '2fa.disable' | '2fa.recovery.regenerate' | '2fa.methods.available' | '2fa.methods.registered' | '2fa.method.setup.start' | '2fa.method.setup.complete' | '2fa.method.remove' | '2fa.challenge.request' | '2fa.challenge.verify' | '2fa.method.switch' | '2fa.trusted-devices.list' | '2fa.trusted-devices.revoke';
3637
3686
  /**
3638
3687
  * Error payload interface for structured error information
3639
3688
  */
@@ -4810,7 +4859,7 @@ export declare class TwoFactorService {
4810
4859
  revokeTrustedDevice(deviceId: string): Promise<void>;
4811
4860
  }
4812
4861
  /**
4813
- * Service for managing user profile and passkeys
4862
+ * Service for managing user profile, passkeys and sessions
4814
4863
  */
4815
4864
  export declare class UserService {
4816
4865
  private userAPI;
@@ -4845,6 +4894,22 @@ export declare class UserService {
4845
4894
  passkeyUsername?: string;
4846
4895
  passkeyDisplayName?: string;
4847
4896
  }): Promise<void>;
4897
+ /**
4898
+ * List the user's signed-in sessions
4899
+ * @returns Promise with sessions array
4900
+ */
4901
+ listSessions(): Promise<PassflowUserSession[]>;
4902
+ /**
4903
+ * End one of the user's sessions
4904
+ * @param sessionId The ID of the session to end
4905
+ * @returns Promise that resolves when the session is ended
4906
+ */
4907
+ revokeSession(sessionId: string): Promise<void>;
4908
+ /**
4909
+ * End every session of the user except the one making the request
4910
+ * @returns Promise with the number of sessions ended
4911
+ */
4912
+ signOutOtherSessions(): Promise<PassflowRevokeOtherSessionsResponse>;
4848
4913
  }
4849
4914
  /**
4850
4915
  * The level an `acr_values` list demands, or `undefined` for no constraint.
@@ -6677,6 +6742,57 @@ export declare class Passflow {
6677
6742
  passkeyUsername?: string;
6678
6743
  passkeyDisplayName?: string;
6679
6744
  }): Promise<void>;
6745
+ /**
6746
+ * List the current user's signed-in sessions, one per sign-in on any device or app.
6747
+ * The session making the request has `current: true`.
6748
+ *
6749
+ * @returns Promise with array of the user's sessions
6750
+ * @throws {PassflowError} If request fails
6751
+ *
6752
+ * @example
6753
+ * ```typescript
6754
+ * const sessions = await passflow.listSessions();
6755
+ * sessions.forEach(session => {
6756
+ * console.log('Session:', session.id, session.device?.name, session.current);
6757
+ * });
6758
+ * ```
6759
+ */
6760
+ listSessions(): Promise<PassflowUserSession[]>;
6761
+ /**
6762
+ * End one of the current user's sessions.
6763
+ *
6764
+ * Ending the session this instance is signed in with signs out like `logOut()`: storage is
6765
+ * deleted, one `SignOut` event follows and, when the sign-in was hosted, the browser goes to the
6766
+ * hosted end-session page. Code after `await revokeSession()` may then not run. A failed request
6767
+ * signs nothing out.
6768
+ *
6769
+ * @param sessionId - ID of the session to end, as returned by `listSessions()`
6770
+ * @returns Promise that resolves when the session is ended
6771
+ * @throws {PassflowError} If request fails
6772
+ *
6773
+ * @example
6774
+ * ```typescript
6775
+ * await passflow.revokeSession('session-123');
6776
+ * console.log('Session ended');
6777
+ * ```
6778
+ */
6779
+ revokeSession(sessionId: string): Promise<void>;
6780
+ /**
6781
+ * End every session of the current user except the one this instance is signed in with.
6782
+ * Nothing changes locally.
6783
+ *
6784
+ * @returns Promise with the number of sessions ended
6785
+ * @throws {PassflowError} If request fails
6786
+ *
6787
+ * @example
6788
+ * ```typescript
6789
+ * const { revoked } = await passflow.signOutOtherSessions();
6790
+ * console.log('Sessions ended:', revoked);
6791
+ * ```
6792
+ */
6793
+ signOutOtherSessions(): Promise<PassflowRevokeOtherSessionsResponse>;
6794
+ /** The `sid` of the stored access token, else of the stored ID token; undefined when neither is readable. */
6795
+ private currentSessionId;
6680
6796
  /**
6681
6797
  * Join a tenant invitation
6682
6798
  * @param token The invitation token
package/dist/index.d.ts CHANGED
@@ -288,6 +288,13 @@ declare class StorageManager {
288
288
  setAppId(appId: string | undefined): void;
289
289
  /** The stored value, or undefined when it is a JWT issued for another app than this one. */
290
290
  private ownToken;
291
+ /**
292
+ * The value under `key`, the prefixed form of `name`. Earlier versions stored it under the
293
+ * unprefixed `name`: such a value is moved to `key` on first read.
294
+ */
295
+ private readPrefixed;
296
+ /** Removes `key` and the unprefixed `name`, so an old value is not read again. */
297
+ private removePrefixed;
291
298
  private readToken;
292
299
  /** The keys a stored token lives in: the JSON tokens and the cookie-mode ID token. */
293
300
  private tokenValueKeys;
@@ -399,6 +406,8 @@ declare class StorageManager {
399
406
  }
400
407
  declare class DeviceService {
401
408
  private storageManager;
409
+ /** The id this service minted; used when the storage keeps nothing (server rendering). */
410
+ private mintedDeviceId;
402
411
  constructor(storageManager?: StorageManager);
403
412
  getDeviceId(): string;
404
413
  generateUniqueDeviceId(): string;
@@ -1065,6 +1074,8 @@ export declare enum PassflowEndpointPaths {
1065
1074
  userPasskey = "/user/passkey",
1066
1075
  addUserPasskey = "/user/passkey/add/start",
1067
1076
  completeAddUserPasskey = "/user/passkey/add/complete",
1077
+ userSessions = "/user/sessions",
1078
+ userSessionsRevokeOthers = "/user/sessions/revoke-others",
1068
1079
  joinInvitation = "/user/tenant/join",
1069
1080
  tenantPath = "/user/tenant",
1070
1081
  invitationsPath = "/user/tenant/:tenantID/invitations",
@@ -1769,6 +1780,41 @@ export type PassflowUserPasskey = {
1769
1780
  count?: number;
1770
1781
  enrolled_with_app_id?: string;
1771
1782
  };
1783
+ /** The device a session was signed in from, as the server recorded it. */
1784
+ export type PassflowSessionDevice = {
1785
+ name?: string;
1786
+ /**
1787
+ * App type the session was signed in with. Known values: `web`, `spa`, `bff`, `android`, `ios`,
1788
+ * `desktop`, `cli`, `m2m`, `other`, `undefined`. The server may add more.
1789
+ */
1790
+ type?: string;
1791
+ user_agent?: string;
1792
+ ip?: string;
1793
+ location?: string;
1794
+ /** RFC 3339 time of the last request made with this session. */
1795
+ last_seen?: string;
1796
+ };
1797
+ /** One signed-in session of the current user. */
1798
+ export type PassflowUserSession = {
1799
+ id: string;
1800
+ app_id: string;
1801
+ /** RFC 3339 */
1802
+ created_at: string;
1803
+ /** RFC 3339 time of the sign-in this session started with. */
1804
+ auth_time: string;
1805
+ /** RFC 3339; absent when the session has no end. */
1806
+ expires_at?: string;
1807
+ /** `true` for the session that made the request. */
1808
+ current: boolean;
1809
+ device?: PassflowSessionDevice;
1810
+ };
1811
+ export type PassflowUserSessionList = {
1812
+ sessions: PassflowUserSession[];
1813
+ };
1814
+ export type PassflowRevokeOtherSessionsResponse = {
1815
+ /** How many sessions were ended. */
1816
+ revoked: number;
1817
+ };
1772
1818
  export type PassflowSendPasswordResetEmailPayload = {
1773
1819
  reset_page_url?: string;
1774
1820
  redirect_url?: string;
@@ -2836,6 +2882,9 @@ export declare class UserAPI {
2836
2882
  passkeyUsername?: string;
2837
2883
  }): Promise<PassflowPasskeyStart>;
2838
2884
  addUserPasskeyComplete(passkeyData: RegistrationResponseJSON, deviceId: string, challengeId: string): Promise<void>;
2885
+ getUserSessions(): Promise<PassflowUserSessionList>;
2886
+ revokeUserSession(sessionId: string): Promise<void>;
2887
+ revokeOtherUserSessions(): Promise<PassflowRevokeOtherSessionsResponse>;
2839
2888
  }
2840
2889
  export declare const APP_ID_HEADER_KEY = "X-Passflow-Clientid";
2841
2890
  export declare const AUTHORIZATION_HEADER_KEY = "Authorization";
@@ -3633,7 +3682,7 @@ export declare enum PassflowEvent {
3633
3682
  * The SDK operation that failed (`ErrorPayload.operation`). The SDK sets it on every `Error` it
3634
3683
  * emits, so a subscriber can tell a failed sign-in from a failed refresh without parsing messages.
3635
3684
  */
3636
- type PassflowOperation = 'sign-in' | 'sign-up' | 'passwordless.start' | 'passwordless.complete' | 'passwordless.wait' | 'passwordless.approval' | 'password-reset.send' | 'password-reset.complete' | 'email-verification.complete' | 'passkey.register' | 'passkey.authenticate' | 'federated.popup' | 'federated.redirect' | 'auth-redirect.url' | 'auth-redirect' | 'redirect.check' | 'auth.is-authenticated' | 'session.check' | 'tokens.get' | 'tokens.load' | 'tokens.from-url' | 'oidc.redirect' | 'refresh' | 'upgrade.commit' | 'log-out' | 'reset' | 'settings.app' | 'settings.all' | 'settings.password-policy' | 'settings.passkey' | 'passkey.list' | 'passkey.rename' | 'passkey.delete' | 'passkey.add' | 'tenant.create' | 'invitation.join' | 'invitation.request-link' | 'invitation.list' | 'invitation.delete' | 'invitation.resend' | 'invitation.get-link' | '2fa.status' | '2fa.setup.begin' | '2fa.setup.confirm' | '2fa.enrollment.read' | '2fa.enrollment.setup-link' | '2fa.verify' | '2fa.recovery.use' | '2fa.disable' | '2fa.recovery.regenerate' | '2fa.methods.available' | '2fa.methods.registered' | '2fa.method.setup.start' | '2fa.method.setup.complete' | '2fa.method.remove' | '2fa.challenge.request' | '2fa.challenge.verify' | '2fa.method.switch' | '2fa.trusted-devices.list' | '2fa.trusted-devices.revoke';
3685
+ type PassflowOperation = 'sign-in' | 'sign-up' | 'passwordless.start' | 'passwordless.complete' | 'passwordless.wait' | 'passwordless.approval' | 'password-reset.send' | 'password-reset.complete' | 'email-verification.complete' | 'passkey.register' | 'passkey.authenticate' | 'federated.popup' | 'federated.redirect' | 'auth-redirect.url' | 'auth-redirect' | 'redirect.check' | 'auth.is-authenticated' | 'session.check' | 'session.list' | 'session.revoke' | 'session.revoke-others' | 'tokens.get' | 'tokens.load' | 'tokens.from-url' | 'oidc.redirect' | 'refresh' | 'upgrade.commit' | 'log-out' | 'reset' | 'settings.app' | 'settings.all' | 'settings.password-policy' | 'settings.passkey' | 'passkey.list' | 'passkey.rename' | 'passkey.delete' | 'passkey.add' | 'tenant.create' | 'invitation.join' | 'invitation.request-link' | 'invitation.list' | 'invitation.delete' | 'invitation.resend' | 'invitation.get-link' | '2fa.status' | '2fa.setup.begin' | '2fa.setup.confirm' | '2fa.enrollment.read' | '2fa.enrollment.setup-link' | '2fa.verify' | '2fa.recovery.use' | '2fa.disable' | '2fa.recovery.regenerate' | '2fa.methods.available' | '2fa.methods.registered' | '2fa.method.setup.start' | '2fa.method.setup.complete' | '2fa.method.remove' | '2fa.challenge.request' | '2fa.challenge.verify' | '2fa.method.switch' | '2fa.trusted-devices.list' | '2fa.trusted-devices.revoke';
3637
3686
  /**
3638
3687
  * Error payload interface for structured error information
3639
3688
  */
@@ -4810,7 +4859,7 @@ export declare class TwoFactorService {
4810
4859
  revokeTrustedDevice(deviceId: string): Promise<void>;
4811
4860
  }
4812
4861
  /**
4813
- * Service for managing user profile and passkeys
4862
+ * Service for managing user profile, passkeys and sessions
4814
4863
  */
4815
4864
  export declare class UserService {
4816
4865
  private userAPI;
@@ -4845,6 +4894,22 @@ export declare class UserService {
4845
4894
  passkeyUsername?: string;
4846
4895
  passkeyDisplayName?: string;
4847
4896
  }): Promise<void>;
4897
+ /**
4898
+ * List the user's signed-in sessions
4899
+ * @returns Promise with sessions array
4900
+ */
4901
+ listSessions(): Promise<PassflowUserSession[]>;
4902
+ /**
4903
+ * End one of the user's sessions
4904
+ * @param sessionId The ID of the session to end
4905
+ * @returns Promise that resolves when the session is ended
4906
+ */
4907
+ revokeSession(sessionId: string): Promise<void>;
4908
+ /**
4909
+ * End every session of the user except the one making the request
4910
+ * @returns Promise with the number of sessions ended
4911
+ */
4912
+ signOutOtherSessions(): Promise<PassflowRevokeOtherSessionsResponse>;
4848
4913
  }
4849
4914
  /**
4850
4915
  * The level an `acr_values` list demands, or `undefined` for no constraint.
@@ -6677,6 +6742,57 @@ export declare class Passflow {
6677
6742
  passkeyUsername?: string;
6678
6743
  passkeyDisplayName?: string;
6679
6744
  }): Promise<void>;
6745
+ /**
6746
+ * List the current user's signed-in sessions, one per sign-in on any device or app.
6747
+ * The session making the request has `current: true`.
6748
+ *
6749
+ * @returns Promise with array of the user's sessions
6750
+ * @throws {PassflowError} If request fails
6751
+ *
6752
+ * @example
6753
+ * ```typescript
6754
+ * const sessions = await passflow.listSessions();
6755
+ * sessions.forEach(session => {
6756
+ * console.log('Session:', session.id, session.device?.name, session.current);
6757
+ * });
6758
+ * ```
6759
+ */
6760
+ listSessions(): Promise<PassflowUserSession[]>;
6761
+ /**
6762
+ * End one of the current user's sessions.
6763
+ *
6764
+ * Ending the session this instance is signed in with signs out like `logOut()`: storage is
6765
+ * deleted, one `SignOut` event follows and, when the sign-in was hosted, the browser goes to the
6766
+ * hosted end-session page. Code after `await revokeSession()` may then not run. A failed request
6767
+ * signs nothing out.
6768
+ *
6769
+ * @param sessionId - ID of the session to end, as returned by `listSessions()`
6770
+ * @returns Promise that resolves when the session is ended
6771
+ * @throws {PassflowError} If request fails
6772
+ *
6773
+ * @example
6774
+ * ```typescript
6775
+ * await passflow.revokeSession('session-123');
6776
+ * console.log('Session ended');
6777
+ * ```
6778
+ */
6779
+ revokeSession(sessionId: string): Promise<void>;
6780
+ /**
6781
+ * End every session of the current user except the one this instance is signed in with.
6782
+ * Nothing changes locally.
6783
+ *
6784
+ * @returns Promise with the number of sessions ended
6785
+ * @throws {PassflowError} If request fails
6786
+ *
6787
+ * @example
6788
+ * ```typescript
6789
+ * const { revoked } = await passflow.signOutOtherSessions();
6790
+ * console.log('Sessions ended:', revoked);
6791
+ * ```
6792
+ */
6793
+ signOutOtherSessions(): Promise<PassflowRevokeOtherSessionsResponse>;
6794
+ /** The `sid` of the stored access token, else of the stored ID token; undefined when neither is readable. */
6795
+ private currentSessionId;
6680
6796
  /**
6681
6797
  * Join a tenant invitation
6682
6798
  * @param token The invitation token