All files / client/methods register.js

7.14% Statements 1/14
0% Branches 0/9
33.33% Functions 1/3
7.14% Lines 1/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                  12x                                                                            
/* @flow */
 
import invariant from "invariant";
import type { MethodApi } from "../types";
import { isEmail } from "../../utils";
 
type registrationOptions = { invite?: string, ref?: number };
 
export default ({ client }: MethodApi) =>
  (
    email: string,
    password: string,
    options: registrationOptions = {}
  ): Promise<number> =>
    {
      invariant(
        typeof email === "string" && isEmail(email),
        "`email` must be provided."
      );
      invariant(password, "`password` is required.");
      invariant(password.length, "`password` is required.");
 
      let params: any = {
        mail: email,
        password: password,
        getauth: 1,
        logout: 1,
        termsaccepted: "yes"
      };
 
      if (options.invite) {
        params.invite = options.invite;
      }
 
      if (options.ref) {
        params.ref = options.ref;
      }
 
      if (ENV === "web") {
        params.os = 4;
        params.device = navigator.userAgent;
      }
 
      return client
        .api("register", { params: params })
        .then(response => response.userid);
    };