@passflow/core 0.49.2 → 0.49.4

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
@@ -1624,6 +1624,8 @@ export type PassflowUserPayload = {
1624
1624
  email: string;
1625
1625
  } | {
1626
1626
  phone_number: string;
1627
+ } | {
1628
+ username: string;
1627
1629
  });
1628
1630
  export type PassflowSignUpPayload = {
1629
1631
  user: PassflowUserPayload;
@@ -2257,6 +2259,7 @@ export type PassflowInviteResponse = {
2257
2259
  export type PassflowInvitePayload = {
2258
2260
  invite_token: string;
2259
2261
  scopes: string[];
2262
+ code_challenge?: string;
2260
2263
  };
2261
2264
  /**
2262
2265
  * One member of a tenant group, as listed in `PassflowTenantResponse.users_in_groups`:
@@ -2886,7 +2889,7 @@ type OperationErrorPayload = ErrorPayload & {
2886
2889
  operation: PassflowOperation;
2887
2890
  };
2888
2891
  /** Which call produced an `EmailVerificationRequired` event. */
2889
- type PassflowEmailVerificationOperation = 'sign-up' | 'sign-in' | 'reset-password';
2892
+ type PassflowEmailVerificationOperation = 'sign-up' | 'sign-in' | 'reset-password' | 'join-invitation';
2890
2893
  /**
2891
2894
  * Event-specific payload types
2892
2895
  */
@@ -3546,7 +3549,7 @@ export declare class TenantAPI {
3546
3549
  protected axiosClient: AxiosClient;
3547
3550
  constructor(config: PassflowConfig, storageManager?: StorageManager, deviceService?: DeviceService);
3548
3551
  setAppId(appId: string): void;
3549
- joinInvitation(token: string, scopes: string[]): Promise<PassflowAuthorizationResponse>;
3552
+ joinInvitation(token: string, scopes: string[], codeChallenge?: string): Promise<PassflowAuthorizationResponse>;
3550
3553
  createTenant(name: string): Promise<PassflowTenantResponse>;
3551
3554
  /**
3552
3555
  * Get tenant details
@@ -5261,6 +5264,15 @@ export declare class AuthService {
5261
5264
  */
5262
5265
  refreshToken(upgrade?: UpgradeRefreshField, pin?: UpgradeSessionPin): Promise<PassflowAuthorizationResponse>;
5263
5266
  sendPasswordResetEmail(payload: PassflowSendPasswordResetEmailPayload, options?: PassflowAuthOptions): Promise<PassflowSuccessResponse>;
5267
+ /**
5268
+ * Joins a tenant with an invitation and continues the session with the tokens the join issues.
5269
+ *
5270
+ * `join` posts the invitation; on a PKCE app it gets a code challenge, and the code the join
5271
+ * answers with is exchanged with the verifier. An emailed-code step is returned as it is, with
5272
+ * the verifier kept so `verifyEmailCode` finishes the join. Emits no event of its own beyond that
5273
+ * step's `EmailVerificationRequired`, and reports no error: the caller does.
5274
+ */
5275
+ joinInvitation(join: (codeChallenge?: string) => Promise<PassflowAuthorizationResponse>, scopes: string[]): Promise<PassflowAuthorizationResponse>;
5264
5276
  resetPassword(newPassword: string, scopes?: string[], token?: string): Promise<PassflowAuthorizationResponse>;
5265
5277
  passkeyRegister(payload: PassflowPasskeyRegisterStartPayload, options?: PassflowAuthOptions): Promise<PassflowAuthorizationResponse>;
5266
5278
  passkeyAuthenticate(payload: PassflowPasskeyAuthenticateStartPayload, options?: PassflowAuthOptions): Promise<PassflowAuthorizationResponse>;
@@ -5524,9 +5536,10 @@ export declare class TenantService {
5524
5536
  * Join a tenant invitation
5525
5537
  * @param token The invitation token
5526
5538
  * @param scopes Optional scopes to request
5539
+ * @param codeChallenge PKCE code challenge, sent only when given
5527
5540
  * @returns Promise with invite response
5528
5541
  */
5529
- joinInvitation(token: string, scopes?: string[]): Promise<PassflowAuthorizationResponse>;
5542
+ joinInvitation(token: string, scopes?: string[], codeChallenge?: string): Promise<PassflowAuthorizationResponse>;
5530
5543
  /**
5531
5544
  * Create a new tenant
5532
5545
  * @param name The name of the tenant
@@ -7367,12 +7380,11 @@ export declare class Passflow {
7367
7380
  */
7368
7381
  signIn(payload: PassflowSignInPayload, options?: PassflowAuthOptions): Promise<PassflowAuthorizationResponse>;
7369
7382
  /**
7370
- * Register a new user account with email and password.
7383
+ * Register a new user account with a password.
7371
7384
  *
7372
7385
  * @param payload - Registration details
7373
- * @param payload.email - User's email address
7374
- * @param payload.password - User's password
7375
- * @param payload.username - Optional username
7386
+ * @param payload.user - The new user: `password` and at least one of `email`, `phone_number` or
7387
+ * `username`. A username alone is enough.
7376
7388
  * @param payload.scopes - Optional scopes to request
7377
7389
  * @returns Promise with authorization response containing tokens
7378
7390
  * May answer an email verification step instead of tokens: check it with
@@ -7383,9 +7395,7 @@ export declare class Passflow {
7383
7395
  * ```typescript
7384
7396
  * try {
7385
7397
  * const response = await passflow.signUp({
7386
- * email: 'newuser@example.com',
7387
- * password: 'secure-password',
7388
- * username: 'newuser'
7398
+ * user: { username: 'newuser', password: 'secure-password' },
7389
7399
  * });
7390
7400
  * console.log('Account created', response.access_token);
7391
7401
  * } catch (error) {
@@ -8258,10 +8268,14 @@ export declare class Passflow {
8258
8268
  /** The `sid` of the stored access token, else of the stored ID token; undefined when neither is readable. */
8259
8269
  private currentSessionId;
8260
8270
  /**
8261
- * Join a tenant invitation
8271
+ * Join a tenant invitation and save the tokens the join issues, like a sign-in.
8272
+ *
8273
+ * On a PKCE app it sends a code challenge and exchanges the code the join answers with. An
8274
+ * emailed-code answer (`isEmailVerificationStep`) is returned as it is; finish it with
8275
+ * `verifyEmailCode`.
8262
8276
  * @param token The invitation token
8263
8277
  * @param scopes Optional scopes to request
8264
- * @returns Promise with invite response
8278
+ * @returns Promise with the new token pair, or the email verification step
8265
8279
  */
8266
8280
  joinInvitation(token: string, scopes?: string[]): Promise<PassflowAuthorizationResponse>;
8267
8281
  /**
package/dist/index.d.ts CHANGED
@@ -1624,6 +1624,8 @@ export type PassflowUserPayload = {
1624
1624
  email: string;
1625
1625
  } | {
1626
1626
  phone_number: string;
1627
+ } | {
1628
+ username: string;
1627
1629
  });
1628
1630
  export type PassflowSignUpPayload = {
1629
1631
  user: PassflowUserPayload;
@@ -2257,6 +2259,7 @@ export type PassflowInviteResponse = {
2257
2259
  export type PassflowInvitePayload = {
2258
2260
  invite_token: string;
2259
2261
  scopes: string[];
2262
+ code_challenge?: string;
2260
2263
  };
2261
2264
  /**
2262
2265
  * One member of a tenant group, as listed in `PassflowTenantResponse.users_in_groups`:
@@ -2886,7 +2889,7 @@ type OperationErrorPayload = ErrorPayload & {
2886
2889
  operation: PassflowOperation;
2887
2890
  };
2888
2891
  /** Which call produced an `EmailVerificationRequired` event. */
2889
- type PassflowEmailVerificationOperation = 'sign-up' | 'sign-in' | 'reset-password';
2892
+ type PassflowEmailVerificationOperation = 'sign-up' | 'sign-in' | 'reset-password' | 'join-invitation';
2890
2893
  /**
2891
2894
  * Event-specific payload types
2892
2895
  */
@@ -3546,7 +3549,7 @@ export declare class TenantAPI {
3546
3549
  protected axiosClient: AxiosClient;
3547
3550
  constructor(config: PassflowConfig, storageManager?: StorageManager, deviceService?: DeviceService);
3548
3551
  setAppId(appId: string): void;
3549
- joinInvitation(token: string, scopes: string[]): Promise<PassflowAuthorizationResponse>;
3552
+ joinInvitation(token: string, scopes: string[], codeChallenge?: string): Promise<PassflowAuthorizationResponse>;
3550
3553
  createTenant(name: string): Promise<PassflowTenantResponse>;
3551
3554
  /**
3552
3555
  * Get tenant details
@@ -5261,6 +5264,15 @@ export declare class AuthService {
5261
5264
  */
5262
5265
  refreshToken(upgrade?: UpgradeRefreshField, pin?: UpgradeSessionPin): Promise<PassflowAuthorizationResponse>;
5263
5266
  sendPasswordResetEmail(payload: PassflowSendPasswordResetEmailPayload, options?: PassflowAuthOptions): Promise<PassflowSuccessResponse>;
5267
+ /**
5268
+ * Joins a tenant with an invitation and continues the session with the tokens the join issues.
5269
+ *
5270
+ * `join` posts the invitation; on a PKCE app it gets a code challenge, and the code the join
5271
+ * answers with is exchanged with the verifier. An emailed-code step is returned as it is, with
5272
+ * the verifier kept so `verifyEmailCode` finishes the join. Emits no event of its own beyond that
5273
+ * step's `EmailVerificationRequired`, and reports no error: the caller does.
5274
+ */
5275
+ joinInvitation(join: (codeChallenge?: string) => Promise<PassflowAuthorizationResponse>, scopes: string[]): Promise<PassflowAuthorizationResponse>;
5264
5276
  resetPassword(newPassword: string, scopes?: string[], token?: string): Promise<PassflowAuthorizationResponse>;
5265
5277
  passkeyRegister(payload: PassflowPasskeyRegisterStartPayload, options?: PassflowAuthOptions): Promise<PassflowAuthorizationResponse>;
5266
5278
  passkeyAuthenticate(payload: PassflowPasskeyAuthenticateStartPayload, options?: PassflowAuthOptions): Promise<PassflowAuthorizationResponse>;
@@ -5524,9 +5536,10 @@ export declare class TenantService {
5524
5536
  * Join a tenant invitation
5525
5537
  * @param token The invitation token
5526
5538
  * @param scopes Optional scopes to request
5539
+ * @param codeChallenge PKCE code challenge, sent only when given
5527
5540
  * @returns Promise with invite response
5528
5541
  */
5529
- joinInvitation(token: string, scopes?: string[]): Promise<PassflowAuthorizationResponse>;
5542
+ joinInvitation(token: string, scopes?: string[], codeChallenge?: string): Promise<PassflowAuthorizationResponse>;
5530
5543
  /**
5531
5544
  * Create a new tenant
5532
5545
  * @param name The name of the tenant
@@ -7367,12 +7380,11 @@ export declare class Passflow {
7367
7380
  */
7368
7381
  signIn(payload: PassflowSignInPayload, options?: PassflowAuthOptions): Promise<PassflowAuthorizationResponse>;
7369
7382
  /**
7370
- * Register a new user account with email and password.
7383
+ * Register a new user account with a password.
7371
7384
  *
7372
7385
  * @param payload - Registration details
7373
- * @param payload.email - User's email address
7374
- * @param payload.password - User's password
7375
- * @param payload.username - Optional username
7386
+ * @param payload.user - The new user: `password` and at least one of `email`, `phone_number` or
7387
+ * `username`. A username alone is enough.
7376
7388
  * @param payload.scopes - Optional scopes to request
7377
7389
  * @returns Promise with authorization response containing tokens
7378
7390
  * May answer an email verification step instead of tokens: check it with
@@ -7383,9 +7395,7 @@ export declare class Passflow {
7383
7395
  * ```typescript
7384
7396
  * try {
7385
7397
  * const response = await passflow.signUp({
7386
- * email: 'newuser@example.com',
7387
- * password: 'secure-password',
7388
- * username: 'newuser'
7398
+ * user: { username: 'newuser', password: 'secure-password' },
7389
7399
  * });
7390
7400
  * console.log('Account created', response.access_token);
7391
7401
  * } catch (error) {
@@ -8258,10 +8268,14 @@ export declare class Passflow {
8258
8268
  /** The `sid` of the stored access token, else of the stored ID token; undefined when neither is readable. */
8259
8269
  private currentSessionId;
8260
8270
  /**
8261
- * Join a tenant invitation
8271
+ * Join a tenant invitation and save the tokens the join issues, like a sign-in.
8272
+ *
8273
+ * On a PKCE app it sends a code challenge and exchanges the code the join answers with. An
8274
+ * emailed-code answer (`isEmailVerificationStep`) is returned as it is; finish it with
8275
+ * `verifyEmailCode`.
8262
8276
  * @param token The invitation token
8263
8277
  * @param scopes Optional scopes to request
8264
- * @returns Promise with invite response
8278
+ * @returns Promise with the new token pair, or the email verification step
8265
8279
  */
8266
8280
  joinInvitation(token: string, scopes?: string[]): Promise<PassflowAuthorizationResponse>;
8267
8281
  /**
package/dist/index.mjs CHANGED
@@ -11,7 +11,7 @@ var a = "__passflowAntiBot", o = (e, t) => {
11
11
  if (typeof e != "object" || !e) return;
12
12
  let t = e[a];
13
13
  return typeof t == "object" && t ? t : void 0;
14
- }, c = "0.49.2", l = "X-Passflow-Clientid", u = "Authorization", d = "X-Passflow-DeviceId", f = "X-Passflow-DeviceType", p = "X-Passflow-Anti-Bot", m = "X-Passflow-Agent-Tool", h = "X-Passflow-Device-Proof", g = "X-Passflow-Fingerprint-Event", _ = "X-Passflow-Stytch-Telemetry", v = "passflow_auth", y = c, b = [
14
+ }, c = "0.49.4", l = "X-Passflow-Clientid", u = "Authorization", d = "X-Passflow-DeviceId", f = "X-Passflow-DeviceType", p = "X-Passflow-Anti-Bot", m = "X-Passflow-Agent-Tool", h = "X-Passflow-Device-Proof", g = "X-Passflow-Fingerprint-Event", _ = "X-Passflow-Stytch-Telemetry", v = "passflow_auth", y = c, b = [
15
15
  "id",
16
16
  "offline",
17
17
  "openid"
@@ -1443,12 +1443,13 @@ var Pt = /* @__PURE__ */ function(e) {
1443
1443
  setAppId(e) {
1444
1444
  this.axiosClient.setAppId(e);
1445
1445
  }
1446
- joinInvitation(e, t) {
1447
- let n = {
1446
+ joinInvitation(e, t, n) {
1447
+ let r = {
1448
1448
  invite_token: e,
1449
- scopes: t
1449
+ scopes: t,
1450
+ ...n ? { code_challenge: n } : {}
1450
1451
  };
1451
- return this.axiosClient.post(R.joinInvitation, n);
1452
+ return this.axiosClient.post(R.joinInvitation, r);
1452
1453
  }
1453
1454
  createTenant(e) {
1454
1455
  let t = { name: e };
@@ -5396,6 +5397,12 @@ var _o = 10, vo = "The sign-in answered with a PKCE code, but its verifier is go
5396
5397
  throw W(this.subscribeStore, t), e;
5397
5398
  }
5398
5399
  }
5400
+ async joinInvitation(e, t) {
5401
+ let n = await this.startPkce(), r = await e(n?.challenge);
5402
+ if (this.handleEmailVerificationStep(r, "join-invitation", void 0, n, t)) return r;
5403
+ let i = await this.exchangeCode(r, n);
5404
+ return await this.processAuthResponse(i, t), i;
5405
+ }
5399
5406
  async resetPassword(e, t, n) {
5400
5407
  this.subscribeStore.notify(G.SignInStart, {});
5401
5408
  let r = n ?? bo(this.platform.getCurrentUrl()), i = t ?? this.scopes;
@@ -6012,10 +6019,10 @@ var Eo = class {
6012
6019
  }
6013
6020
  throw this.logger.error(`${n}:`, t), t instanceof Error ? t : Error(String(t));
6014
6021
  }
6015
- async joinInvitation(e, t) {
6022
+ async joinInvitation(e, t, n) {
6016
6023
  try {
6017
- let n = t ?? this.scopes;
6018
- return await this.tenantApi.joinInvitation(e, n);
6024
+ let r = t ?? this.scopes;
6025
+ return n ? await this.tenantApi.joinInvitation(e, r, n) : await this.tenantApi.joinInvitation(e, r);
6019
6026
  } catch (e) {
6020
6027
  this.handlePassflowError(e, "Join invitation failed");
6021
6028
  }
@@ -8540,8 +8547,8 @@ var Eo = class {
8540
8547
  }
8541
8548
  async joinInvitation(e, t) {
8542
8549
  try {
8543
- let n = await this.tenant.joinInvitation(e, t);
8544
- return n.scopes = t ?? this.scopes, await this.authService.applyTokens(n), n;
8550
+ let n = t ?? this.scopes;
8551
+ return await this.authService.joinInvitation((t) => this.tenant.joinInvitation(e, n, t), n);
8545
8552
  } catch (e) {
8546
8553
  this.handleError(e, "invitation.join", "Join invitation");
8547
8554
  }