@fabriktor/fx 0.0.5 → 0.0.7

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/src/fx.d.ts CHANGED
@@ -7,6 +7,10 @@ export type FXOptions = {
7
7
  auth: AuthOperator;
8
8
  users: UsersOperator;
9
9
  };
10
+ export type DefaultFXOptions = {
11
+ base_url: string;
12
+ auth: AuthOperator;
13
+ };
10
14
  export interface FXOperator {
11
15
  users: UsersFXOperator;
12
16
  session: SessionFXOperator;
@@ -17,3 +21,4 @@ export declare class FX implements FXOperator {
17
21
  constructor(opts: FXOptions);
18
22
  }
19
23
  export declare function newFX(opts: FXOptions): FX;
24
+ export declare function newDefaultFX(opts: DefaultFXOptions): FX;
package/dist/src/fx.js CHANGED
@@ -3,6 +3,7 @@
3
3
  // Licensed under the Apache License, Version 2.0 (the "License"); you may
4
4
  // not use this file except in compliance with the License. You may obtain
5
5
  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ import { newHTTPClient, newUsersClient } from "@fabriktor/client";
6
7
  import { newSessionFX } from "./session/session";
7
8
  import { newUsersFX } from "./users/users";
8
9
  export class FX {
@@ -23,3 +24,12 @@ export class FX {
23
24
  export function newFX(opts) {
24
25
  return new FX(opts);
25
26
  }
27
+ export function newDefaultFX(opts) {
28
+ return newFX({
29
+ base_url: opts.base_url,
30
+ auth: opts.auth,
31
+ users: newUsersClient({
32
+ http: newHTTPClient(),
33
+ }),
34
+ });
35
+ }
@@ -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.7",
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
  }