lombongo-api-client 0.0.47 → 0.0.49
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 +27 -23
- package/package.json +2 -2
package/dist/esm/base.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"axios";class s{constructor(t){this.client=t,this.endpoint="/accounts"}async getAccounts(){return await this.client.request("get",this.endpoint)}async createAoaAccount(){return await this.client.request("post",this.endpoint,{currency:"aoa"},{})}async createEurAccount(){return await this.client.request("post",this.endpoint,{currency:"eur"},{})}}class i{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)}isAuthenticated(){return Boolean(this.client.token)}async signOut(){const t=this.client.lombongoIdBaseUrl,s=this.client.getToken();s&&await this.client.request("post","/users/logout",{token:s},{},t),delete this.client.token,this.authState.authenticated=!1,this.authState.user=void 0,this.authState.token=void 0,this._notifyObservers()}async createUser(t){const s=this.client.lombongoIdBaseUrl,i=await this.client.request("post","/users",t,{},s);return delete t.password,this.authState={authenticated:!0,user:t,token:i.
|
|
1
|
+
import t from"axios";class s{constructor(t){this.client=t,this.endpoint="/accounts"}async getAccounts(){return await this.client.request("get",this.endpoint)}async createAoaAccount(){return await this.client.request("post",this.endpoint,{currency:"aoa"},{})}async createEurAccount(){return await this.client.request("post",this.endpoint,{currency:"eur"},{})}}class i{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)}isAuthenticated(){return Boolean(this.client.token)}async signOut(){const t=this.client.lombongoIdBaseUrl,s=this.client.getToken();s&&await this.client.request("post","/users/logout",{token:s},{},t),delete this.client.token,this.authState.authenticated=!1,this.authState.user=void 0,this.authState.token=void 0,this._notifyObservers()}async createUser(t){const s=this.client.lombongoIdBaseUrl,i=(await this.client.request("post","/users",t,{},s)).data;return delete t.password,this.authState={authenticated:!0,user:t,token:i.token},this._notifyObservers(),i}async login(t){const s=this._loginFactory(t),i=await s(t);return this.authState={authenticated:!0,user:{email:i.email,username:i.username},token:i.token},this._notifyObservers(),i}async verifyToken(t){const s=this.client.lombongoIdBaseUrl;return await this.client.request("post","/token",{token:t},{},s)}async _loginWithEmailAndPassword(t,s){const i=this.client.lombongoIdBaseUrl;return await this.client.request("post","/users/login",{email:t,password:s},{},i)}async _loginWithUsernameAndPassword(t,s){const i=this.client.lombongoIdBaseUrl;return await this.client.request("post","/users/login",{username:t,password:s},{},i)}_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(t){this.client=t,this.endpoint="/beneficiaries"}async getBeneficiaries(){return await this.client.request("get",this.endpoint)}async createBeneficiary(t,s){return await this.client.request("post",this.endpoint,{name:t,iban:s})}}class n{constructor(t){this.client=t,this.endpoint="/current-commission"}async getCurrentCommission(){return await this.client.request("get",this.endpoint)}}class r{constructor(t){this.client=t,this.endpoint="/currencies"}async getCurrencies(){return await this.client.request("get",this.endpoint)}}class a{constructor(t){this.client=t,this.endpoint="/fx-rates"}async getFxRates(){return await this.client.request("get",this.endpoint)}async getFxRate(t,s){return await this.client.request("post",this.endpoint,{originalCurrencyId:t,finalCurrencyId:s})}}class o{constructor(t){this.client=t,this.endpoint="/transactions"}async doCrossCurrency(t){const s=`${this.endpoint}/cross-currency`;return await this.client.request("post",s,t)}async getFXConfig(t,s,i){const e=`${this.endpoint}/sepa/config`;return await this.client.request("post",e,{originalCurrencyId:t,finalCurrencyId:s,amount:i})}}class c{constructor(t){this.client=t,this.endpoint="/payment-methods"}async getPaymentMethods(){return await this.client.request("get",this.endpoint)}async getPaymentMethodsByCurrency(t){const s=`${this.endpoint}/currency/${t}`;return await this.client.request("get",s)}}class h{constructor(t){this.client=t,this.endpoint="/api/plaid/"}async createPaymentInitiationLinkToken(t){const s=this.endpoint+"create_link_token";return await this.client.request("post",s,{payment_id:t})}async createPaymentInitiation(t){const s=this.endpoint+"payment_initiation/payment/create";return await this.client.request("post",s,{amount:t})}}class u{constructor({baseUrl:t,token:u,lombongoIdBaseUrl:y}){this.baseUrl=t,this.token=u,this.lombongoIdBaseUrl=y,this.auth=new i(this),this.accounts=new s(this),this.currencies=new r(this),this.currentCommision=new n(this),this.fxRates=new a(this),this.paymentMethods=new c(this),this.transactions=new o(this),this.plaid=new h(this),this.beneficiaries=new e(this)}static init(t){return u.instance?(t?.token&&(u.instance.token=t.token),t?.baseUrl&&(u.instance.baseUrl=t.baseUrl),t?.lombongoIdBaseUrl&&(u.instance.lombongoIdBaseUrl=t.lombongoIdBaseUrl),u.instance):(u.instance=new u(t),u.instance)}async request(s,i,e={},n={},r){const a=`${r||this.baseUrl}${i}`,o={...n,headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`,...n.headers},method:s,url:a};return"GET"!==s.toUpperCase()&&Object.keys(e).length>0&&(o.data=e),await t(o)}setToken(t){this.token=t}getToken(){return this.token}}export{u as default};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
1
|
+
import { AxiosResponse, AxiosRequestConfig } from 'axios';
|
|
2
2
|
|
|
3
3
|
declare class Account {
|
|
4
4
|
private client;
|
|
5
5
|
private endpoint;
|
|
6
6
|
constructor(client: ApiClient);
|
|
7
|
-
getAccounts(): Promise<
|
|
8
|
-
createAoaAccount(): Promise<
|
|
9
|
-
createEurAccount(): Promise<
|
|
7
|
+
getAccounts(): Promise<AxiosResponse>;
|
|
8
|
+
createAoaAccount(): Promise<AxiosResponse>;
|
|
9
|
+
createEurAccount(): Promise<AxiosResponse>;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
type CreateUser = {
|
|
@@ -14,6 +14,10 @@ type CreateUser = {
|
|
|
14
14
|
password: string;
|
|
15
15
|
username?: string;
|
|
16
16
|
};
|
|
17
|
+
type CreatedUser = {
|
|
18
|
+
user: CreateUser;
|
|
19
|
+
token: string;
|
|
20
|
+
};
|
|
17
21
|
type LoginParameter = {
|
|
18
22
|
email?: string;
|
|
19
23
|
password: string;
|
|
@@ -34,11 +38,11 @@ declare class Auth {
|
|
|
34
38
|
onAuthStateChange(observer: (authState: AuthState) => void): void;
|
|
35
39
|
isAuthenticated(): boolean;
|
|
36
40
|
signOut(): Promise<void>;
|
|
37
|
-
createUser(user: CreateUser): Promise<
|
|
38
|
-
login(credentials: LoginParameter): Promise<
|
|
39
|
-
verifyToken(token: string): Promise<
|
|
40
|
-
_loginWithEmailAndPassword(email: string, password: string): Promise<
|
|
41
|
-
_loginWithUsernameAndPassword(username: string, password: string): Promise<
|
|
41
|
+
createUser(user: CreateUser): Promise<CreatedUser>;
|
|
42
|
+
login(credentials: LoginParameter): Promise<Partial<CreatedUser>>;
|
|
43
|
+
verifyToken(token: string): Promise<AxiosResponse>;
|
|
44
|
+
_loginWithEmailAndPassword(email: string, password: string): Promise<AxiosResponse>;
|
|
45
|
+
_loginWithUsernameAndPassword(username: string, password: string): Promise<AxiosResponse>;
|
|
42
46
|
_loginFactory(credentials: LoginParameter): (credentials: LoginParameter) => Promise<object>;
|
|
43
47
|
}
|
|
44
48
|
|
|
@@ -46,30 +50,30 @@ declare class Beneficiaries {
|
|
|
46
50
|
private readonly client;
|
|
47
51
|
private endpoint;
|
|
48
52
|
constructor(client: ApiClient);
|
|
49
|
-
getBeneficiaries(): Promise<
|
|
50
|
-
createBeneficiary(name: string, iban: string): Promise<
|
|
53
|
+
getBeneficiaries(): Promise<AxiosResponse>;
|
|
54
|
+
createBeneficiary(name: string, iban: string): Promise<AxiosResponse>;
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
declare class CurrentCommision {
|
|
54
58
|
private client;
|
|
55
59
|
private endpoint;
|
|
56
60
|
constructor(client: ApiClient);
|
|
57
|
-
getCurrentCommission(): Promise<
|
|
61
|
+
getCurrentCommission(): Promise<AxiosResponse>;
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
declare class Currencies {
|
|
61
65
|
private readonly client;
|
|
62
66
|
private endpoint;
|
|
63
67
|
constructor(client: ApiClient);
|
|
64
|
-
getCurrencies(): Promise<
|
|
68
|
+
getCurrencies(): Promise<AxiosResponse>;
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
declare class FxRate {
|
|
68
72
|
private readonly client;
|
|
69
73
|
private endpoint;
|
|
70
74
|
constructor(client: ApiClient);
|
|
71
|
-
getFxRates(): Promise<
|
|
72
|
-
getFxRate(originalCurrencyId: number, finalCurrencyId: number): Promise<
|
|
75
|
+
getFxRates(): Promise<AxiosResponse>;
|
|
76
|
+
getFxRate(originalCurrencyId: number, finalCurrencyId: number): Promise<AxiosResponse>;
|
|
73
77
|
}
|
|
74
78
|
|
|
75
79
|
interface ITransactionParams {
|
|
@@ -90,31 +94,31 @@ interface ICrosscurrencyParams extends ITransactionParams {
|
|
|
90
94
|
}
|
|
91
95
|
interface ICrosscurrencyPostParams extends ICrosscurrencyParams {
|
|
92
96
|
payment_method_id: number;
|
|
93
|
-
phone_number
|
|
97
|
+
phone_number?: number;
|
|
94
98
|
}
|
|
95
99
|
|
|
96
100
|
declare class Transactions {
|
|
97
101
|
private readonly client;
|
|
98
102
|
private endpoint;
|
|
99
103
|
constructor(client: ApiClient);
|
|
100
|
-
doCrossCurrency(doCrossCurrency: ICrosscurrencyPostParams): Promise<
|
|
101
|
-
getFXConfig(originalCurrencyId: number, finalCurrencyId: number, amount: number): Promise<
|
|
104
|
+
doCrossCurrency(doCrossCurrency: ICrosscurrencyPostParams): Promise<AxiosResponse>;
|
|
105
|
+
getFXConfig(originalCurrencyId: number, finalCurrencyId: number, amount: number): Promise<AxiosResponse>;
|
|
102
106
|
}
|
|
103
107
|
|
|
104
108
|
declare class PaymentMethod {
|
|
105
109
|
private client;
|
|
106
110
|
private endpoint;
|
|
107
111
|
constructor(client: ApiClient);
|
|
108
|
-
getPaymentMethods(): Promise<
|
|
109
|
-
getPaymentMethodsByCurrency(currencyId: number): Promise<
|
|
112
|
+
getPaymentMethods(): Promise<AxiosResponse>;
|
|
113
|
+
getPaymentMethodsByCurrency(currencyId: number): Promise<AxiosResponse>;
|
|
110
114
|
}
|
|
111
115
|
|
|
112
116
|
declare class Plaid {
|
|
113
117
|
private readonly client;
|
|
114
118
|
private endpoint;
|
|
115
119
|
constructor(client: ApiClient);
|
|
116
|
-
createPaymentInitiationLinkToken(paymentId: string): Promise<
|
|
117
|
-
createPaymentInitiation(amount: number): Promise<
|
|
120
|
+
createPaymentInitiationLinkToken(paymentId: string): Promise<AxiosResponse>;
|
|
121
|
+
createPaymentInitiation(amount: number): Promise<AxiosResponse>;
|
|
118
122
|
}
|
|
119
123
|
|
|
120
124
|
interface ApiClientOptions {
|
|
@@ -142,7 +146,7 @@ declare class ApiClient {
|
|
|
142
146
|
plaid: Plaid;
|
|
143
147
|
private constructor();
|
|
144
148
|
static init(options: ApiClientOptions): ApiClient;
|
|
145
|
-
request(method: Method, endpoint: string, body?: object, options?: CustomRequestInit, overrideBaseUrl?: string): Promise<
|
|
149
|
+
request(method: Method, endpoint: string, body?: object, options?: CustomRequestInit, overrideBaseUrl?: string): Promise<AxiosResponse>;
|
|
146
150
|
setToken(token: string): void;
|
|
147
151
|
getToken(): string | undefined;
|
|
148
152
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lombongo-api-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.49",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/esm/base.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"license": "ISC",
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@types/jest": "^29.5.12",
|
|
32
|
-
"axios": "^1.
|
|
32
|
+
"axios": "^1.7.2",
|
|
33
33
|
"jest": "^29.7.0",
|
|
34
34
|
"ts-jest": "^29.1.2",
|
|
35
35
|
"ts-node": "^10.9.2"
|