lombongo-api-client 0.0.2 → 0.0.3
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/esm/base.js +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
package/dist/esm/base.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"axios";class s{constructor(t){this.observers=[],this.authState={authenticated:!1},this.client=t}notifyObservers(){for(const t of this.observers)t(this.authState)}onAuthStateChange(t){this.observers.push(t)}async createUser(t){const s=this.client.lombongoIdBaseUrl,e=await this.client.request("post","/users",t,{},s);return this.authState={authenticated:!0,user:t},this.notifyObservers(),e}async login(t){const s=this._loginFactory(t);return await s(t)}async _verifyToken(t){const s=this.client.lombongoIdBaseUrl;return this.client.request("post","/token",{token:t},{},s)}async _loginWithEmailAndPassword(t,s){const e=this.client.lombongoIdBaseUrl;return this.client.request("post","/users",{email:t,password:s},{},e)}async _loginWithUsernameAndPassword(t,s){const e=this.client.lombongoIdBaseUrl;return this.client.request("post","/users",{username:t,password:s},{},e)}_loginFactory(t){if(!("email"in t)&&!("username"in t))throw new Error("Login credentials must include either an email or a username.");return async t=>{if(t.email)return this._loginWithEmailAndPassword(t.email,t.password);if(t.username)return this._loginWithUsernameAndPassword(t.username,t.password);throw new Error("Invalid login credentials provided.")}}}class e{constructor({baseUrl:t,token:e,lombongoIdBaseUrl:r}){this.baseUrl=t,this.token=e,this.lombongoIdBaseUrl=r,this.auth=new s(this)}static init(t){return e.instance?(t?.token&&(e.instance.token=t.token),t?.baseUrl&&(e.instance.baseUrl=t.baseUrl),t?.lombongoIdBaseUrl&&(e.instance.lombongoIdBaseUrl=t.lombongoIdBaseUrl),e.instance):(e.instance=new e(t),e.instance)}async request(s,e,r={},i={},n){const o=`${n||this.baseUrl}${e}`,a={...i,headers:{"Content-Type":"application/json",...this.token?{Authorization:`Bearer ${this.token}`}:{},...i.headers},method:s,url:o,...r&&{data:r}};return t(a)}setToken(t){this.token=t}}export{e as default};
|
|
1
|
+
import t from"axios";class s{constructor(t){this.observers=[],this.authState={authenticated:!1},this.client=t}notifyObservers(){for(const t of this.observers)t(this.authState)}listobservers(){for(const t of this.observers)console.log(t)}onAuthStateChange(t){this.observers.push(t)}async createUser(t){const s=this.client.lombongoIdBaseUrl,e=await this.client.request("post","/users",t,{},s);return this.authState={authenticated:!0,user:t},this.notifyObservers(),e}async login(t){const s=this._loginFactory(t);return await s(t)}async _verifyToken(t){const s=this.client.lombongoIdBaseUrl;return this.client.request("post","/token",{token:t},{},s)}async _loginWithEmailAndPassword(t,s){const e=this.client.lombongoIdBaseUrl;return this.client.request("post","/users",{email:t,password:s},{},e)}async _loginWithUsernameAndPassword(t,s){const e=this.client.lombongoIdBaseUrl;return this.client.request("post","/users",{username:t,password:s},{},e)}_loginFactory(t){if(!("email"in t)&&!("username"in t))throw new Error("Login credentials must include either an email or a username.");return async t=>{if(t.email)return this._loginWithEmailAndPassword(t.email,t.password);if(t.username)return this._loginWithUsernameAndPassword(t.username,t.password);throw new Error("Invalid login credentials provided.")}}}class e{constructor({baseUrl:t,token:e,lombongoIdBaseUrl:r}){this.baseUrl=t,this.token=e,this.lombongoIdBaseUrl=r,this.auth=new s(this)}static init(t){return e.instance?(t?.token&&(e.instance.token=t.token),t?.baseUrl&&(e.instance.baseUrl=t.baseUrl),t?.lombongoIdBaseUrl&&(e.instance.lombongoIdBaseUrl=t.lombongoIdBaseUrl),e.instance):(e.instance=new e(t),e.instance)}async request(s,e,r={},i={},n){const o=`${n||this.baseUrl}${e}`,a={...i,headers:{"Content-Type":"application/json",...this.token?{Authorization:`Bearer ${this.token}`}:{},...i.headers},method:s,url:o,...r&&{data:r}};return t(a)}setToken(t){this.token=t}}export{e as default};
|
package/dist/types.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ type CreateUser = {
|
|
|
4
4
|
email: string;
|
|
5
5
|
password: string;
|
|
6
6
|
username: string;
|
|
7
|
-
fullname?: string;
|
|
8
7
|
};
|
|
9
8
|
type LoginParameter = {
|
|
10
9
|
email?: string;
|
|
@@ -21,6 +20,7 @@ declare class Auth {
|
|
|
21
20
|
private authState;
|
|
22
21
|
constructor(client: ApiClient);
|
|
23
22
|
private notifyObservers;
|
|
23
|
+
listobservers(): void;
|
|
24
24
|
onAuthStateChange(observer: (authState: AuthState) => void): void;
|
|
25
25
|
createUser(user: CreateUser): Promise<object>;
|
|
26
26
|
login(credentials: LoginParameter): Promise<object>;
|