timber-node 0.0.1

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.
@@ -0,0 +1,116 @@
1
+ import { AxiosInstance, AxiosResponse } from "axios";
2
+ export interface CreateExpenseRequest {
3
+ type: string;
4
+ merchant: string;
5
+ category: string;
6
+ date: string;
7
+ payment_method: string;
8
+ amount: number;
9
+ }
10
+ export type UpdateExpenseRequest = Partial<CreateExpenseRequest>;
11
+ export interface Expense {
12
+ _id: string;
13
+ user: string;
14
+ company: string;
15
+ merchant: string;
16
+ created_at: string;
17
+ updated_at: string;
18
+ }
19
+ export interface ExpenseQueryParams {
20
+ page: number;
21
+ limit: number;
22
+ sort: string;
23
+ filters: string;
24
+ }
25
+ /**
26
+ * Service for managing Expenses.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const { createClient } = require('timber-sdk-dev');
31
+ * const client = createClient('your-api-key');
32
+ * const expenses = await client.expense.list({ page: 1, limit: 10 });
33
+ * console.log(expenses.data);
34
+ * ```
35
+ */
36
+ export declare class ExpenseService {
37
+ private http;
38
+ constructor(http: AxiosInstance);
39
+ /**
40
+ * Fetch a paginated list of expenses.
41
+ *
42
+ * @param params - Query options like page, limit, filters, sort.
43
+ * @returns List of expenses matching the query.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const expenses = await client.expense.list({ page: 1, limit: 5 });
48
+ * console.log(expenses.data);
49
+ * ```
50
+ */
51
+ list(params: ExpenseQueryParams): Promise<AxiosResponse<Expense[]>>;
52
+ /**
53
+ * Fetch a single expense by ID.
54
+ *
55
+ * @param id - Expense ID
56
+ * @returns Expense object
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const expense = await client.expense.get('expense_id_here');
61
+ * console.log(expense.data);
62
+ * ```
63
+ */
64
+ get(id: string): Promise<AxiosResponse<Expense>>;
65
+ /**
66
+ * Create a new expense.
67
+ *
68
+ * @param data - Expense creation payload
69
+ * @returns The created expense
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * const newExpense = {
74
+ * type: "travel",
75
+ * merchant: "Uber",
76
+ * category: "Transportation",
77
+ * date: "2025-06-23",
78
+ * payment_method: "credit_card",
79
+ * amount: 45.75,
80
+ * };
81
+ * const response = await client.expense.create(newExpense);
82
+ * console.log(response.data);
83
+ * ```
84
+ */
85
+ create(data: CreateExpenseRequest): Promise<AxiosResponse<Expense>>;
86
+ /**
87
+ * Update an existing expense.
88
+ *
89
+ * @param id - Expense ID
90
+ * @param data - Partial update data
91
+ * @returns Updated expense
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * const updates = { amount: 50.0 };
96
+ * const updated = await client.expense.update('expense_id_here', updates);
97
+ * console.log(updated.data);
98
+ * ```
99
+ */
100
+ update(id: string, data: UpdateExpenseRequest): Promise<AxiosResponse<Expense>>;
101
+ /**
102
+ * Delete an expense by ID.
103
+ *
104
+ * @param id - Expense ID
105
+ * @returns Confirmation message
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * const response = await client.expense.delete('expense_id_here');
110
+ * console.log(response.data.message);
111
+ * ```
112
+ */
113
+ delete(id: string): Promise<AxiosResponse<{
114
+ message: string;
115
+ }>>;
116
+ }
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExpenseService = void 0;
4
+ /**
5
+ * Service for managing Expenses.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const { createClient } = require('timber-sdk-dev');
10
+ * const client = createClient('your-api-key');
11
+ * const expenses = await client.expense.list({ page: 1, limit: 10 });
12
+ * console.log(expenses.data);
13
+ * ```
14
+ */
15
+ class ExpenseService {
16
+ constructor(http) {
17
+ this.http = http;
18
+ }
19
+ /**
20
+ * Fetch a paginated list of expenses.
21
+ *
22
+ * @param params - Query options like page, limit, filters, sort.
23
+ * @returns List of expenses matching the query.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const expenses = await client.expense.list({ page: 1, limit: 5 });
28
+ * console.log(expenses.data);
29
+ * ```
30
+ */
31
+ async list(params) {
32
+ return await this.http.get("/customer/expense", { params });
33
+ }
34
+ /**
35
+ * Fetch a single expense by ID.
36
+ *
37
+ * @param id - Expense ID
38
+ * @returns Expense object
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * const expense = await client.expense.get('expense_id_here');
43
+ * console.log(expense.data);
44
+ * ```
45
+ */
46
+ async get(id) {
47
+ return await this.http.get(`/customer/expense/${id}`);
48
+ }
49
+ /**
50
+ * Create a new expense.
51
+ *
52
+ * @param data - Expense creation payload
53
+ * @returns The created expense
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * const newExpense = {
58
+ * type: "travel",
59
+ * merchant: "Uber",
60
+ * category: "Transportation",
61
+ * date: "2025-06-23",
62
+ * payment_method: "credit_card",
63
+ * amount: 45.75,
64
+ * };
65
+ * const response = await client.expense.create(newExpense);
66
+ * console.log(response.data);
67
+ * ```
68
+ */
69
+ async create(data) {
70
+ return await this.http.post("/customer/expense", data);
71
+ }
72
+ /**
73
+ * Update an existing expense.
74
+ *
75
+ * @param id - Expense ID
76
+ * @param data - Partial update data
77
+ * @returns Updated expense
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * const updates = { amount: 50.0 };
82
+ * const updated = await client.expense.update('expense_id_here', updates);
83
+ * console.log(updated.data);
84
+ * ```
85
+ */
86
+ async update(id, data) {
87
+ return await this.http.put(`/customer/expense/${id}`, data);
88
+ }
89
+ /**
90
+ * Delete an expense by ID.
91
+ *
92
+ * @param id - Expense ID
93
+ * @returns Confirmation message
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * const response = await client.expense.delete('expense_id_here');
98
+ * console.log(response.data.message);
99
+ * ```
100
+ */
101
+ async delete(id) {
102
+ return await this.http.patch(`/customer/expense/${id}`);
103
+ }
104
+ }
105
+ exports.ExpenseService = ExpenseService;
@@ -0,0 +1,95 @@
1
+ import { AxiosInstance, AxiosResponse } from "axios";
2
+ export interface CreateExpenseCategoryRequest {
3
+ category: string;
4
+ }
5
+ export type UpdateExpenseCategoryRequest = Partial<CreateExpenseCategoryRequest>;
6
+ export interface ExpenseCategory {
7
+ _id: string;
8
+ company: string;
9
+ category: {
10
+ label: string;
11
+ value: string;
12
+ };
13
+ created_at: string;
14
+ updated_at: string;
15
+ }
16
+ export interface ExpenseCategoryQueryParams {
17
+ page: number;
18
+ limit: number;
19
+ sort: string;
20
+ filters: string;
21
+ }
22
+ /**
23
+ * Service for Expense Category
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const { createClient } = require('timber-sdk-dev');
28
+ * const client = createClient('your-api-key');
29
+ * const expenseCategory = await client.expenseCategory.list({ page: 1, limit: 10 });
30
+ * console.log(expenseCategory.data);
31
+ * ```
32
+ */
33
+ export declare class ExpenseCategoryService {
34
+ private http;
35
+ constructor(http: AxiosInstance);
36
+ /**
37
+ * Fetch a paginated list of expense categories.
38
+ *
39
+ * @param params
40
+ * @returns
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const expenseCategories = await client.expenseCategory.list({ page: 1, limit: 5 });
45
+ * console.log(expenseCategories.data);
46
+ * ```
47
+ */
48
+ list(params: ExpenseCategoryQueryParams): Promise<AxiosResponse<ExpenseCategory[]>>;
49
+ /**
50
+ * Create a new expense category.
51
+ *
52
+ * @param data
53
+ * @returns
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * const newExpenseCategory = {
58
+ * category: "Travel"
59
+ * };
60
+ * const response = await client.expenseCategory.create(newExpenseCategory);
61
+ * console.log(response.data);
62
+ * ```
63
+ */
64
+ create(data: CreateExpenseCategoryRequest): Promise<AxiosResponse<ExpenseCategory>>;
65
+ /**
66
+ * Update an existing expense category.
67
+ *
68
+ * @param id
69
+ * @param data
70
+ * @returns
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * const updates = { category: "Food" };
75
+ * const updated = await client.expenseCategory.update('expense_category_id_here', updates);
76
+ * console.log(updated.data);
77
+ * ```
78
+ */
79
+ update(id: string, data: CreateExpenseCategoryRequest): Promise<AxiosResponse<ExpenseCategory>>;
80
+ /**
81
+ * Delete an expense category by ID.
82
+ *
83
+ * @param id
84
+ * @returns
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * const response = await client.expenseCategory.delete('expense_category_id_here');
89
+ * console.log(response.data.message);
90
+ * ```
91
+ */
92
+ delete(id: string): Promise<AxiosResponse<{
93
+ message: string;
94
+ }>>;
95
+ }
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExpenseCategoryService = void 0;
4
+ /**
5
+ * Service for Expense Category
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const { createClient } = require('timber-sdk-dev');
10
+ * const client = createClient('your-api-key');
11
+ * const expenseCategory = await client.expenseCategory.list({ page: 1, limit: 10 });
12
+ * console.log(expenseCategory.data);
13
+ * ```
14
+ */
15
+ class ExpenseCategoryService {
16
+ constructor(http) {
17
+ this.http = http;
18
+ }
19
+ /**
20
+ * Fetch a paginated list of expense categories.
21
+ *
22
+ * @param params
23
+ * @returns
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const expenseCategories = await client.expenseCategory.list({ page: 1, limit: 5 });
28
+ * console.log(expenseCategories.data);
29
+ * ```
30
+ */
31
+ async list(params) {
32
+ return await this.http.get("/customer/expense/category", {
33
+ params,
34
+ });
35
+ }
36
+ /**
37
+ * Create a new expense category.
38
+ *
39
+ * @param data
40
+ * @returns
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const newExpenseCategory = {
45
+ * category: "Travel"
46
+ * };
47
+ * const response = await client.expenseCategory.create(newExpenseCategory);
48
+ * console.log(response.data);
49
+ * ```
50
+ */
51
+ async create(data) {
52
+ return await this.http.post("/customer/expense/category", data);
53
+ }
54
+ /**
55
+ * Update an existing expense category.
56
+ *
57
+ * @param id
58
+ * @param data
59
+ * @returns
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * const updates = { category: "Food" };
64
+ * const updated = await client.expenseCategory.update('expense_category_id_here', updates);
65
+ * console.log(updated.data);
66
+ * ```
67
+ */
68
+ async update(id, data) {
69
+ return await this.http.put(`/customer/expense/category/${id}`, data);
70
+ }
71
+ /**
72
+ * Delete an expense category by ID.
73
+ *
74
+ * @param id
75
+ * @returns
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * const response = await client.expenseCategory.delete('expense_category_id_here');
80
+ * console.log(response.data.message);
81
+ * ```
82
+ */
83
+ async delete(id) {
84
+ return await this.http.delete(`/customer/expense/category/${id}`);
85
+ }
86
+ }
87
+ exports.ExpenseCategoryService = ExpenseCategoryService;
@@ -0,0 +1,29 @@
1
+ import { ExpenseService } from "./expense";
2
+ import { RawExpenseService } from "./rawExpense";
3
+ import { VendorPaymentService } from "./vendorPayment";
4
+ import { ExpenseCategoryService } from "./expenseCategory";
5
+ import { BillPaymentService } from "./billPayment";
6
+ import { InvoiceService } from "./invoice";
7
+ import { InvoicePaymentService } from "./invoicePayment";
8
+ import { CustomerService } from "./customer";
9
+ import { TaxRateService } from "./taxRate";
10
+ import { SalaryService } from "./salary";
11
+ import { EmployeeService } from "./employee";
12
+ declare class TimberClient {
13
+ expense: ExpenseService;
14
+ expenseCategory: ExpenseCategoryService;
15
+ rawExpense: RawExpenseService;
16
+ invoice: InvoiceService;
17
+ invoicePayment: InvoicePaymentService;
18
+ vendorPayment: VendorPaymentService;
19
+ billPayment: BillPaymentService;
20
+ customer: CustomerService;
21
+ taxRate: TaxRateService;
22
+ salary: SalaryService;
23
+ employee: EmployeeService;
24
+ constructor(apiKey: string, options?: {
25
+ baseURL?: string;
26
+ });
27
+ }
28
+ export declare const createClient: (apiKey: string, options?: {}) => TimberClient;
29
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createClient = void 0;
7
+ const dotenv_1 = __importDefault(require("dotenv"));
8
+ dotenv_1.default.config();
9
+ const axios_1 = __importDefault(require("axios"));
10
+ const expense_1 = require("./expense");
11
+ const rawExpense_1 = require("./rawExpense");
12
+ const vendorPayment_1 = require("./vendorPayment");
13
+ const expenseCategory_1 = require("./expenseCategory");
14
+ const billPayment_1 = require("./billPayment");
15
+ const invoice_1 = require("./invoice");
16
+ const invoicePayment_1 = require("./invoicePayment");
17
+ const customer_1 = require("./customer");
18
+ const taxRate_1 = require("./taxRate");
19
+ const salary_1 = require("./salary");
20
+ const employee_1 = require("./employee");
21
+ class TimberClient {
22
+ constructor(apiKey, options = {}) {
23
+ const baseURL = `${options.baseURL || "http://localhost:4010"}/api/v1/user/sdk`;
24
+ const http = axios_1.default.create({
25
+ baseURL: baseURL,
26
+ headers: {
27
+ Authorization: `ApiKey ${apiKey}`,
28
+ "Content-Type": "application/json",
29
+ },
30
+ });
31
+ this.expense = new expense_1.ExpenseService(http);
32
+ this.expenseCategory = new expenseCategory_1.ExpenseCategoryService(http);
33
+ this.rawExpense = new rawExpense_1.RawExpenseService(http);
34
+ this.vendorPayment = new vendorPayment_1.VendorPaymentService(http);
35
+ this.billPayment = new billPayment_1.BillPaymentService(http);
36
+ this.invoice = new invoice_1.InvoiceService(http);
37
+ this.invoicePayment = new invoicePayment_1.InvoicePaymentService(http);
38
+ this.customer = new customer_1.CustomerService(http);
39
+ this.taxRate = new taxRate_1.TaxRateService(http);
40
+ this.salary = new salary_1.SalaryService(http);
41
+ this.employee = new employee_1.EmployeeService(http);
42
+ }
43
+ }
44
+ const createClient = (apiKey, options = {}) => {
45
+ if (!apiKey) {
46
+ throw new Error("API key is required");
47
+ }
48
+ return new TimberClient(apiKey, options);
49
+ };
50
+ exports.createClient = createClient;
@@ -0,0 +1,109 @@
1
+ import { AxiosInstance, AxiosResponse } from "axios";
2
+ export type NewInvoiceItem = {
3
+ id: string;
4
+ title: string;
5
+ quantity: number;
6
+ rate: number;
7
+ vat: number;
8
+ discount: number;
9
+ total: number;
10
+ };
11
+ export interface InvoiceData {
12
+ mode: "create" | "edit";
13
+ payment_method: string;
14
+ title: string;
15
+ company: string;
16
+ isTitleChanged: boolean;
17
+ customer: {
18
+ customer_id?: string;
19
+ name: string;
20
+ email: string;
21
+ trn?: string;
22
+ country_code: string;
23
+ mobile: string;
24
+ address: string;
25
+ };
26
+ biller: {
27
+ biller_id?: string;
28
+ name: string;
29
+ email: string;
30
+ country_code: string;
31
+ mobile: string;
32
+ address: string;
33
+ trn?: string;
34
+ };
35
+ invoice_number: string;
36
+ invoice_date: any;
37
+ due_date: any | null;
38
+ currency: string;
39
+ items: NewInvoiceItem[];
40
+ terms: any;
41
+ notes: any;
42
+ sub_total: number;
43
+ vat_total: number;
44
+ discount_total: number;
45
+ shipping: number;
46
+ total: number;
47
+ amount_paid: number;
48
+ amount_due: number;
49
+ logo: any | null | File;
50
+ place_of_supply?: string;
51
+ wafeq: boolean;
52
+ zoho: boolean;
53
+ }
54
+ export interface Invoice extends InvoiceData {
55
+ _id: string;
56
+ created_at?: string;
57
+ updated_at?: string;
58
+ }
59
+ export interface InvoiceQueryParams {
60
+ page?: number;
61
+ limit?: number;
62
+ }
63
+ /**
64
+ * Service for Invoice
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * const { createClient } = require('timber-sdk-dev');
69
+ * const client = createClient('your-api-key');
70
+ * const invoice = await client.invoice.list({ page: 1, limit: 10 });
71
+ * console.log(invoice.data);
72
+ * ```
73
+ */
74
+ export declare class InvoiceService {
75
+ private http;
76
+ constructor(http: AxiosInstance);
77
+ /**
78
+ * Fetch a paginated list of invoices.
79
+ *
80
+ * @param params - Query options like page, limit, filters, sort.
81
+ * @returns List of invoices matching the query.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * const invoices = await client.invoice.list({ page: 1, limit: 5 });
86
+ * console.log(invoices.data);
87
+ * ```
88
+ */
89
+ list(params?: InvoiceQueryParams): Promise<AxiosResponse<Invoice[]>>;
90
+ create(data: InvoiceData): Promise<AxiosResponse<Invoice>>;
91
+ update(id: string, data: Partial<InvoiceData>): Promise<AxiosResponse<Invoice>>;
92
+ /**
93
+ * Delete an invoice by ID.
94
+ *
95
+ * @param id - Invoice ID
96
+ * @returns Confirmation message
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * const response = await client.invoice.delete('invoice_id_here');
101
+ * console.log(response.data.message);
102
+ * ```
103
+ */
104
+ delete(id: string, data: {
105
+ remarks: string;
106
+ }): Promise<AxiosResponse<{
107
+ message: string;
108
+ }>>;
109
+ }
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.InvoiceService = void 0;
7
+ const form_data_1 = __importDefault(require("form-data"));
8
+ /**
9
+ * Service for Invoice
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const { createClient } = require('timber-sdk-dev');
14
+ * const client = createClient('your-api-key');
15
+ * const invoice = await client.invoice.list({ page: 1, limit: 10 });
16
+ * console.log(invoice.data);
17
+ * ```
18
+ */
19
+ class InvoiceService {
20
+ constructor(http) {
21
+ this.http = http;
22
+ }
23
+ /**
24
+ * Fetch a paginated list of invoices.
25
+ *
26
+ * @param params - Query options like page, limit, filters, sort.
27
+ * @returns List of invoices matching the query.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const invoices = await client.invoice.list({ page: 1, limit: 5 });
32
+ * console.log(invoices.data);
33
+ * ```
34
+ */
35
+ async list(params = {}) {
36
+ return await this.http.get("/customer/invoice", { params });
37
+ }
38
+ async create(data) {
39
+ const formData = new form_data_1.default();
40
+ for (const key in data) {
41
+ const value = data[key];
42
+ if (key === "items" || key === "customer" || key === "biller") {
43
+ formData.append(key, JSON.stringify(value));
44
+ }
45
+ else if (key === "logo" && value && typeof value.pipe === "function") {
46
+ // This is a ReadStream
47
+ formData.append("logo", value);
48
+ }
49
+ else if (value instanceof Date) {
50
+ formData.append(key, value.toISOString());
51
+ }
52
+ else if (value !== undefined && value !== null) {
53
+ formData.append(key, value.toString());
54
+ }
55
+ }
56
+ return await this.http.post("/customer/invoice", formData, {
57
+ headers: formData.getHeaders(),
58
+ });
59
+ }
60
+ async update(id, data) {
61
+ const formData = new form_data_1.default();
62
+ for (const key in data) {
63
+ const value = data[key];
64
+ if (key === "items" || key === "customer" || key === "biller") {
65
+ formData.append(key, JSON.stringify(value));
66
+ }
67
+ else if (key === "logo" && value && typeof value.pipe === "function") {
68
+ // This is a ReadStream
69
+ formData.append("logo", value);
70
+ }
71
+ else if (value instanceof Date) {
72
+ formData.append(key, value.toISOString());
73
+ }
74
+ else if (value !== undefined && value !== null) {
75
+ formData.append(key, value.toString());
76
+ }
77
+ }
78
+ return await this.http.put(`/customer/invoice/${id}`, data, {
79
+ headers: formData.getHeaders(),
80
+ });
81
+ }
82
+ /**
83
+ * Delete an invoice by ID.
84
+ *
85
+ * @param id - Invoice ID
86
+ * @returns Confirmation message
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * const response = await client.invoice.delete('invoice_id_here');
91
+ * console.log(response.data.message);
92
+ * ```
93
+ */
94
+ async delete(id, data) {
95
+ return await this.http.delete(`/customer/invoice/${id}`, {
96
+ data,
97
+ });
98
+ }
99
+ }
100
+ exports.InvoiceService = InvoiceService;