@fabriktor/fx 0.0.5 → 0.0.6

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.
@@ -2,6 +2,12 @@ import type { InUser, UpsertResult } from "@fabriktor/schema";
2
2
  import type { Op } from "@fabriktor/client";
3
3
  import type { AuthEmailOptions, AuthOperator } from "../auth/auth";
4
4
  import type { UsersFXOperator } from "../users/users";
5
+ export type SignInMode = "email" | "username";
6
+ export type SignInOptions = {
7
+ mode: SignInMode;
8
+ identifier: string;
9
+ password: string;
10
+ };
5
11
  export type SignUpAndBootstrapOptions = AuthEmailOptions & {
6
12
  in: InUser;
7
13
  };
@@ -11,7 +17,7 @@ export type SessionFXOptions = {
11
17
  };
12
18
  export interface SessionFXOperator {
13
19
  signUpAndBootstrap(opts: SignUpAndBootstrapOptions): Promise<Op<UpsertResult>>;
14
- signIn(opts: AuthEmailOptions): Promise<void>;
20
+ signIn(opts: SignInOptions): Promise<void>;
15
21
  signOut(): Promise<void>;
16
22
  }
17
23
  export declare class SessionFX implements SessionFXOperator {
@@ -19,7 +25,7 @@ export declare class SessionFX implements SessionFXOperator {
19
25
  private users;
20
26
  constructor(opts: SessionFXOptions);
21
27
  signUpAndBootstrap(opts: SignUpAndBootstrapOptions): Promise<Op<UpsertResult>>;
22
- signIn(opts: AuthEmailOptions): Promise<void>;
28
+ signIn(opts: SignInOptions): Promise<void>;
23
29
  signOut(): Promise<void>;
24
30
  }
25
31
  export declare function newSessionFX(opts: SessionFXOptions): SessionFX;
@@ -20,7 +20,15 @@ export class SessionFX {
20
20
  });
21
21
  }
22
22
  async signIn(opts) {
23
- await this.auth.signIn(opts);
23
+ const email = opts.mode === "email"
24
+ ? opts.identifier
25
+ : await this.users.resolveUsername({
26
+ username: opts.identifier,
27
+ });
28
+ await this.auth.signIn({
29
+ email,
30
+ password: opts.password,
31
+ });
24
32
  await this.users.sync();
25
33
  }
26
34
  async signOut() {
@@ -9,10 +9,14 @@ export type UsersFXOptions = {
9
9
  export type BootstrapOptions = {
10
10
  in: InUser;
11
11
  };
12
+ export type ResolveUsernameOptions = {
13
+ username: string;
14
+ };
12
15
  export interface UsersFXOperator {
13
16
  bootstrap(opts: BootstrapOptions): Promise<Op<UpsertResult>>;
14
17
  sync(): Promise<OperationResult>;
15
18
  sendEmailVerification(): Promise<void>;
19
+ resolveUsername(opts: ResolveUsernameOptions): Promise<string>;
16
20
  }
17
21
  export declare class UsersFX implements UsersFXOperator {
18
22
  private base_url;
@@ -22,5 +26,6 @@ export declare class UsersFX implements UsersFXOperator {
22
26
  bootstrap(opts: BootstrapOptions): Promise<Op<UpsertResult>>;
23
27
  sync(): Promise<OperationResult>;
24
28
  sendEmailVerification(): Promise<void>;
29
+ resolveUsername(opts: ResolveUsernameOptions): Promise<string>;
25
30
  }
26
31
  export declare function newUsersFX(opts: UsersFXOptions): UsersFX;
@@ -34,6 +34,16 @@ export class UsersFX {
34
34
  token,
35
35
  });
36
36
  }
37
+ async resolveUsername(opts) {
38
+ const out = await this.users.resolveUsername({
39
+ base_url: this.base_url,
40
+ username: opts.username,
41
+ });
42
+ if (out.value === undefined) {
43
+ throw new Error("Unable to resolve username.");
44
+ }
45
+ return out.value;
46
+ }
37
47
  }
38
48
  export function newUsersFX(opts) {
39
49
  return new UsersFX(opts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/fx",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "![Fabriktor Logo](./img/fabriktor-character.gif)",
5
5
  "type": "module",
6
6
  "exports": {
@@ -17,7 +17,7 @@
17
17
  "typescript": "^6.0.3"
18
18
  },
19
19
  "dependencies": {
20
- "@fabriktor/client": "^0.0.6",
20
+ "@fabriktor/client": "^0.0.7",
21
21
  "@fabriktor/schema": "^0.0.10"
22
22
  }
23
23
  }