money-lover-app-client 1.0.5 → 1.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/bundle.js +2 -2
- package/dist/bundle.js.map +1 -1
- package/dist/client.d.ts +6 -6
- package/dist/commands/categories.d.ts +2 -2
- package/dist/commands/transactions.d.ts +2 -2
- package/dist/commands/wallets.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/interfaces/account.d.ts +7 -0
- package/dist/interfaces/category-parent.d.ts +7 -0
- package/dist/interfaces/category.d.ts +3 -2
- package/dist/interfaces/transaction.d.ts +18 -1
- package/dist/interfaces/user-snippet.d.ts +4 -0
- package/dist/interfaces/wallet.d.ts +3 -6
- package/package.json +1 -1
- package/dist/client.js +0 -95
- package/dist/commands/categories.js +0 -13
- package/dist/commands/login.js +0 -24
- package/dist/commands/logout.js +0 -6
- package/dist/commands/transactions.js +0 -26
- package/dist/commands/wallets.js +0 -15
- package/dist/index.js +0 -1
- package/dist/interfaces/category-type.js +0 -6
- package/dist/interfaces/category.js +0 -1
- package/dist/interfaces/client-state.d.ts +0 -3
- package/dist/interfaces/client-state.js +0 -1
- package/dist/interfaces/transaction.js +0 -1
- package/dist/interfaces/user-profile.js +0 -1
- package/dist/interfaces/wallet.js +0 -1
- package/dist/state.d.ts +0 -3
- package/dist/state.js +0 -19
- package/dist/utils.js +0 -12
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Category } from "./interfaces/category";
|
|
2
|
+
import { UpsertTransaction } from "./interfaces/transaction";
|
|
3
|
+
import { Wallet } from "./interfaces/wallet";
|
|
4
4
|
declare class MoneyLoverClient {
|
|
5
5
|
private _jwtToken;
|
|
6
6
|
constructor();
|
|
@@ -10,10 +10,10 @@ declare class MoneyLoverClient {
|
|
|
10
10
|
isTokenValid(): boolean;
|
|
11
11
|
getToken(): string | null;
|
|
12
12
|
getUserInfo(): Promise<any>;
|
|
13
|
-
getWallets(): Promise<
|
|
14
|
-
getCategories(walletId: string): Promise<
|
|
13
|
+
getWallets(): Promise<Wallet[]>;
|
|
14
|
+
getCategories(walletId: string): Promise<Category[]>;
|
|
15
15
|
getTransactions(walletId: string, startDate: Date, endDate: Date): Promise<any>;
|
|
16
|
-
addTransaction(transaction:
|
|
16
|
+
addTransaction(transaction: UpsertTransaction): Promise<UpsertTransaction>;
|
|
17
17
|
}
|
|
18
18
|
export default MoneyLoverClient;
|
|
19
19
|
export declare const NewMoneyLoverClient: () => MoneyLoverClient;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import MoneyLoverClient from "../client";
|
|
2
|
-
import {
|
|
3
|
-
declare const getCategories: (client: MoneyLoverClient, walletId: string) => Promise<
|
|
2
|
+
import { Category } from "../interfaces/category";
|
|
3
|
+
declare const getCategories: (client: MoneyLoverClient, walletId: string) => Promise<Category[]>;
|
|
4
4
|
export default getCategories;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import MoneyLoverClient from "../client";
|
|
2
|
-
import {
|
|
2
|
+
import { UpsertTransaction } from "../interfaces/transaction";
|
|
3
3
|
declare const getTransactions: (client: MoneyLoverClient, walletId: string, startDate: Date, endDate: Date) => Promise<any>;
|
|
4
|
-
declare const addTransaction: (client: MoneyLoverClient, transaction:
|
|
4
|
+
declare const addTransaction: (client: MoneyLoverClient, transaction: UpsertTransaction) => Promise<UpsertTransaction>;
|
|
5
5
|
export { getTransactions, addTransaction };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,9 +4,9 @@ import login from "./commands/login";
|
|
|
4
4
|
import logout from "./commands/logout";
|
|
5
5
|
import { addTransaction, getTransactions } from "./commands/transactions";
|
|
6
6
|
import getWallets from "./commands/wallets";
|
|
7
|
-
import {
|
|
7
|
+
import { Category } from "./interfaces/category";
|
|
8
8
|
import { CategoryType } from "./interfaces/category-type";
|
|
9
|
-
import {
|
|
9
|
+
import { UpsertTransaction } from "./interfaces/transaction";
|
|
10
10
|
import { UserProfile } from "./interfaces/user-profile";
|
|
11
|
-
import {
|
|
12
|
-
export { MoneyLoverClient, NewMoneyLoverClient, getCategories, login, logout, getTransactions, addTransaction, getWallets, CategoryType,
|
|
11
|
+
import { Wallet } from "./interfaces/wallet";
|
|
12
|
+
export { MoneyLoverClient, NewMoneyLoverClient, getCategories, login, logout, getTransactions, addTransaction, getWallets, CategoryType, Category, UpsertTransaction, UserProfile, Wallet, };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { CategoryParent } from "./category-parent";
|
|
2
|
+
export interface Category {
|
|
2
3
|
/** Internal unique identifier for the specific item */
|
|
3
4
|
_id: string;
|
|
4
5
|
/** Display name (e.g., "Tejas") */
|
|
@@ -20,6 +21,6 @@ export interface MoneyLoverCategory {
|
|
|
20
21
|
/** Duplicate of _id, often used for legacy or specific API compatibility */
|
|
21
22
|
id: string;
|
|
22
23
|
/** Optional parent category ID for hierarchical categorization */
|
|
23
|
-
parent?:
|
|
24
|
+
parent?: CategoryParent;
|
|
24
25
|
exclude_accounts: string[];
|
|
25
26
|
}
|
|
@@ -1,7 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
import { Account } from "./account";
|
|
2
|
+
import { Category } from "./category";
|
|
3
|
+
import { UserSnippet } from "./user-snippet";
|
|
4
|
+
export interface UpsertTransaction {
|
|
2
5
|
account: string;
|
|
3
6
|
category: string;
|
|
4
7
|
amount: string;
|
|
5
8
|
note: string;
|
|
6
9
|
date: Date;
|
|
7
10
|
}
|
|
11
|
+
export interface Transaction {
|
|
12
|
+
_id: string;
|
|
13
|
+
note: string;
|
|
14
|
+
account: Account;
|
|
15
|
+
category: Category;
|
|
16
|
+
amount: number;
|
|
17
|
+
displayDate: string;
|
|
18
|
+
with: any[];
|
|
19
|
+
campaign: any[];
|
|
20
|
+
lastEditBy: UserSnippet;
|
|
21
|
+
exclude_report: boolean;
|
|
22
|
+
images: any[];
|
|
23
|
+
createdAt: string;
|
|
24
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { UserSnippet } from "./user-snippet";
|
|
2
|
+
export interface Wallet {
|
|
2
3
|
_id: string;
|
|
3
4
|
name: string;
|
|
4
5
|
currency_id: number;
|
|
@@ -9,16 +10,12 @@ export interface MoneyLoverWallet {
|
|
|
9
10
|
account_type: number;
|
|
10
11
|
exclude_total: boolean;
|
|
11
12
|
icon: string;
|
|
12
|
-
listUser:
|
|
13
|
+
listUser: UserSnippet[];
|
|
13
14
|
createdAt: string;
|
|
14
15
|
updateAt: string;
|
|
15
16
|
isDelete: boolean;
|
|
16
17
|
balance: MoneyLoverBankTransaction[];
|
|
17
18
|
}
|
|
18
|
-
export interface MoneyLoverObjectUser {
|
|
19
|
-
_id: string;
|
|
20
|
-
email: string;
|
|
21
|
-
}
|
|
22
19
|
export interface MoneyLoverBankTransaction {
|
|
23
20
|
date: string;
|
|
24
21
|
valueDate: string;
|
package/package.json
CHANGED
package/dist/client.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import jwt from "jsonwebtoken";
|
|
2
|
-
import { formatDate } from "./utils";
|
|
3
|
-
const moneyLoverUrl = "https://web.moneylover.me";
|
|
4
|
-
const moneyLoverTokenUrl = "https://oauth.moneylover.me";
|
|
5
|
-
class MoneyLoverClient {
|
|
6
|
-
constructor(jwtToken = null) {
|
|
7
|
-
this._jwtToken = null;
|
|
8
|
-
this._jwtToken = jwtToken;
|
|
9
|
-
}
|
|
10
|
-
async _postRequest(path, body = null, headers = {}) {
|
|
11
|
-
const res = await fetch(`${moneyLoverUrl}/api${path}`, {
|
|
12
|
-
method: "POST",
|
|
13
|
-
headers: {
|
|
14
|
-
authorization: `AuthJWT ${this._jwtToken}`,
|
|
15
|
-
"cache-Control": "no-cache, max-age=0, no-store, no-transform, must-revalidate",
|
|
16
|
-
"Content-Type": "application/json",
|
|
17
|
-
...headers,
|
|
18
|
-
},
|
|
19
|
-
body: JSON.stringify(body),
|
|
20
|
-
});
|
|
21
|
-
const data = await res.json();
|
|
22
|
-
if (data.error != null && data.error !== 0) {
|
|
23
|
-
const error = new Error(`Error ${data.error}, ${data.msg}`);
|
|
24
|
-
error.name = "MoneyLoverError";
|
|
25
|
-
error.message = data.msg;
|
|
26
|
-
throw error;
|
|
27
|
-
}
|
|
28
|
-
else if (data.e != null) {
|
|
29
|
-
const error = new Error(`Error ${data.e}, ${data.message}`);
|
|
30
|
-
error.name = "MoneyLoverError";
|
|
31
|
-
error.message = data.message;
|
|
32
|
-
throw error;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
return data.data;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
static async getToken(email, password) {
|
|
39
|
-
const loginUrlRes = await fetch(`${moneyLoverUrl}/api/user/login-url`, {
|
|
40
|
-
method: "POST",
|
|
41
|
-
});
|
|
42
|
-
const loginUrlData = await loginUrlRes.json();
|
|
43
|
-
const res = await fetch(`${moneyLoverTokenUrl}/token`, {
|
|
44
|
-
method: "POST",
|
|
45
|
-
headers: {
|
|
46
|
-
authorization: `Bearer ${loginUrlData.data.request_token}`,
|
|
47
|
-
client: loginUrlData.data.login_url.match("client=(.+?)&")[1],
|
|
48
|
-
"Content-Type": "application/json",
|
|
49
|
-
},
|
|
50
|
-
body: JSON.stringify({ email, password }),
|
|
51
|
-
});
|
|
52
|
-
const tokenData = await res.json();
|
|
53
|
-
return tokenData.access_token;
|
|
54
|
-
}
|
|
55
|
-
isTokenValid() {
|
|
56
|
-
if (this._jwtToken != null) {
|
|
57
|
-
// Check if token is expired
|
|
58
|
-
const jwtToken = jwt.decode(this._jwtToken);
|
|
59
|
-
if (!jwtToken.exp) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
return jwtToken.exp * 1000 > Date.now();
|
|
63
|
-
}
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
getUserInfo() {
|
|
67
|
-
return this._postRequest("/user/info");
|
|
68
|
-
}
|
|
69
|
-
getWallets() {
|
|
70
|
-
return this._postRequest("/wallet/list");
|
|
71
|
-
}
|
|
72
|
-
getCategories(walletId) {
|
|
73
|
-
return this._postRequest("/category/list-all", { walletId: walletId });
|
|
74
|
-
}
|
|
75
|
-
getTransactions(walletId, startDate, endDate) {
|
|
76
|
-
return this._postRequest("/transaction/list", {
|
|
77
|
-
startDate: startDate.toISOString().substr(0, 10),
|
|
78
|
-
endDate: endDate.toISOString().substr(0, 10),
|
|
79
|
-
walletId, // "all" to get the transactions of all wallets
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
addTransaction(transaction) {
|
|
83
|
-
return this._postRequest("/transaction/add", JSON.stringify({
|
|
84
|
-
with: [],
|
|
85
|
-
account: transaction.account,
|
|
86
|
-
category: transaction.category,
|
|
87
|
-
amount: transaction.amount,
|
|
88
|
-
note: transaction.note,
|
|
89
|
-
displayDate: formatDate(transaction.date),
|
|
90
|
-
}), {
|
|
91
|
-
"Content-Type": "application/json",
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
export default MoneyLoverClient;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const getCategories = async (client, walletId) => {
|
|
2
|
-
if (!client) {
|
|
3
|
-
throw new Error("Not logged in");
|
|
4
|
-
}
|
|
5
|
-
if (!client.isTokenValid()) {
|
|
6
|
-
throw new Error("Token has expired");
|
|
7
|
-
}
|
|
8
|
-
const allCategories = await client.getCategories(walletId);
|
|
9
|
-
// Api may return all categories even when the walletId is specified,
|
|
10
|
-
// so we filter them here to return only the categories that belong to the specified walletId.
|
|
11
|
-
return allCategories.filter((category) => category.walletId === walletId);
|
|
12
|
-
};
|
|
13
|
-
export default getCategories;
|
package/dist/commands/login.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import MoneyLoverClient from "../client";
|
|
2
|
-
import jwt from "jsonwebtoken";
|
|
3
|
-
const debug = process.env.DEBUG === "true";
|
|
4
|
-
const login = async (username, password) => {
|
|
5
|
-
let token;
|
|
6
|
-
token = await MoneyLoverClient.getToken(username, password);
|
|
7
|
-
try {
|
|
8
|
-
const jwtToken = jwt.decode(token);
|
|
9
|
-
const ml = new MoneyLoverClient(token);
|
|
10
|
-
const userInfo = await ml.getUserInfo();
|
|
11
|
-
if (debug) {
|
|
12
|
-
if (!jwtToken.exp) {
|
|
13
|
-
throw new Error("Invalid JWT token: missing exp field");
|
|
14
|
-
}
|
|
15
|
-
console.log(`MoneyLoverClient: Logged in as ${userInfo.email} until ${new Date(jwtToken.exp * 1000)}`);
|
|
16
|
-
}
|
|
17
|
-
return userInfo;
|
|
18
|
-
}
|
|
19
|
-
catch (e) {
|
|
20
|
-
console.error("MoneyLoverClient: Login failed", e);
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
export default login;
|
package/dist/commands/logout.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const getTransactions = async (client, walletId, startDate, endDate) => {
|
|
2
|
-
if (!client) {
|
|
3
|
-
throw new Error("MoneyLoverClient: Not logged in");
|
|
4
|
-
}
|
|
5
|
-
if (!client.isTokenValid()) {
|
|
6
|
-
throw new Error("MoneyLoverClient: Token has expired");
|
|
7
|
-
}
|
|
8
|
-
if (!walletId) {
|
|
9
|
-
// Default to all
|
|
10
|
-
walletId = "all";
|
|
11
|
-
}
|
|
12
|
-
return await client.getTransactions(walletId, startDate, endDate);
|
|
13
|
-
};
|
|
14
|
-
const addTransaction = async (client, transaction) => {
|
|
15
|
-
if (!client) {
|
|
16
|
-
throw new Error("MoneyLoverClient: Not logged in");
|
|
17
|
-
}
|
|
18
|
-
if (!client.isTokenValid()) {
|
|
19
|
-
throw new Error("MoneyLoverClient: Token has expired");
|
|
20
|
-
}
|
|
21
|
-
if (!transaction.account || !transaction.category) {
|
|
22
|
-
throw new Error("MoneyLoverClient: Transaction must have account and category");
|
|
23
|
-
}
|
|
24
|
-
return await client.addTransaction(transaction);
|
|
25
|
-
};
|
|
26
|
-
export { getTransactions, addTransaction };
|
package/dist/commands/wallets.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const debug = process.env.DEBUG === "true";
|
|
2
|
-
const getWallets = async (client) => {
|
|
3
|
-
if (!client) {
|
|
4
|
-
throw new Error("MoneyLoverClient: Not logged in");
|
|
5
|
-
}
|
|
6
|
-
if (!client.isTokenValid()) {
|
|
7
|
-
throw new Error("MoneyLoverClient: Token has expired");
|
|
8
|
-
}
|
|
9
|
-
const wallets = await client.getWallets();
|
|
10
|
-
if (debug) {
|
|
11
|
-
console.log(`MoneyLoverClient: Retrieved ${wallets.length} wallets`);
|
|
12
|
-
}
|
|
13
|
-
return wallets;
|
|
14
|
-
};
|
|
15
|
-
export default getWallets;
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/state.d.ts
DELETED
package/dist/state.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getState = getState;
|
|
4
|
-
exports.setState = setState;
|
|
5
|
-
exports.clearState = clearState;
|
|
6
|
-
let state = {
|
|
7
|
-
jwtToken: null,
|
|
8
|
-
};
|
|
9
|
-
function getState(key) {
|
|
10
|
-
return state[key];
|
|
11
|
-
}
|
|
12
|
-
function setState(key, value) {
|
|
13
|
-
state[key] = value;
|
|
14
|
-
}
|
|
15
|
-
function clearState() {
|
|
16
|
-
state = {
|
|
17
|
-
jwtToken: null,
|
|
18
|
-
};
|
|
19
|
-
}
|
package/dist/utils.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
function formatDate(date) {
|
|
2
|
-
const d = new Date(date);
|
|
3
|
-
let month = "" + (d.getMonth() + 1);
|
|
4
|
-
let day = "" + d.getDate();
|
|
5
|
-
const year = d.getFullYear();
|
|
6
|
-
if (month.length < 2)
|
|
7
|
-
month = "0" + month;
|
|
8
|
-
if (day.length < 2)
|
|
9
|
-
day = "0" + day;
|
|
10
|
-
return [year, month, day].join("-");
|
|
11
|
-
}
|
|
12
|
-
export { formatDate };
|