timber-node 0.1.7 → 0.1.9

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.
@@ -1,7 +1,7 @@
1
1
  import { AxiosInstance, AxiosProgressEvent, AxiosResponse, CancelToken } from 'axios';
2
2
  export interface BankStatementData {
3
3
  file: File | string;
4
- progressCallback?: (progressEvent: AxiosProgressEvent) => void;
4
+ progressCallback?: (_progressEvent: AxiosProgressEvent) => void;
5
5
  cancelToken?: CancelToken;
6
6
  }
7
7
  export interface BankStatement extends BankStatementData {
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.BankStatementService = void 0;
7
- const form_data_1 = __importDefault(require("form-data"));
4
+ const getFormData_1 = require("./utils/getFormData");
8
5
  /**
9
6
  * Service for BankStatement
10
7
  *
@@ -51,7 +48,7 @@ class BankStatementService {
51
48
  * ```
52
49
  */
53
50
  async create(data) {
54
- const formData = new form_data_1.default();
51
+ const { formData, headers } = await (0, getFormData_1.getFormData)();
55
52
  if (data === null || data === void 0 ? void 0 : data.file) {
56
53
  formData.append('file', data.file);
57
54
  }
@@ -59,7 +56,7 @@ class BankStatementService {
59
56
  throw new Error('File is required');
60
57
  }
61
58
  return await this.http.post('/customer/reconcile/bank-statement', formData, {
62
- headers: formData.getHeaders(),
59
+ headers,
63
60
  cancelToken: data.cancelToken,
64
61
  onUploadProgress: data.progressCallback,
65
62
  });
@@ -9,7 +9,7 @@ export interface CreateBillPaymentRequest {
9
9
  amount: number;
10
10
  bank_name?: string;
11
11
  is_paid: boolean;
12
- file: [File];
12
+ file: File;
13
13
  }
14
14
  export type UpdateBillPaymentRequest = Partial<CreateBillPaymentRequest>;
15
15
  export interface BillPayment {
@@ -77,7 +77,7 @@ class BillPaymentService {
77
77
  }
78
78
  formData.append('amount', data.amount.toString());
79
79
  if (data.file) {
80
- formData.append('file', data.file[0]);
80
+ formData.append('file', data.file);
81
81
  }
82
82
  return await this.http.post('/customer/purchase/payment-record', formData, {
83
83
  headers,
@@ -116,7 +116,7 @@ class BillPaymentService {
116
116
  }
117
117
  formData.append('amount', data.amount.toString());
118
118
  if (data.file) {
119
- formData.append('file', data.file[0]);
119
+ formData.append('file', data.file);
120
120
  }
121
121
  return await this.http.put(`/customer/purchase/payment-record/${id}`, formData, {
122
122
  headers,
package/dist/cheque.js CHANGED
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.ChequeService = void 0;
7
- const form_data_1 = __importDefault(require("form-data"));
4
+ const getFormData_1 = require("./utils/getFormData");
8
5
  /**
9
6
  * Service for Cheque
10
7
  *
@@ -51,7 +48,7 @@ class ChequeService {
51
48
  * ```
52
49
  */
53
50
  async create(data) {
54
- const formData = new form_data_1.default();
51
+ const { formData, headers } = await (0, getFormData_1.getFormData)();
55
52
  if (data === null || data === void 0 ? void 0 : data.file) {
56
53
  formData.append('file', data.file);
57
54
  }
@@ -59,7 +56,7 @@ class ChequeService {
59
56
  throw new Error('File is required');
60
57
  }
61
58
  return await this.http.post('/customer/reconcile/cheque', formData, {
62
- headers: formData.getHeaders(),
59
+ headers,
63
60
  cancelToken: data.cancelToken,
64
61
  onUploadProgress: data.progressCallback,
65
62
  });
package/dist/index.d.ts CHANGED
@@ -12,6 +12,8 @@ import { EmployeeService } from './employee';
12
12
  import { ChequeService } from './cheque';
13
13
  import { BankStatementService } from './bankStatement';
14
14
  import { CompanyService } from './company';
15
+ import { InvoiceNumberService } from './invoiceNumber';
16
+ import { InvoiceTemplateService } from './invoiceTemplates';
15
17
  declare class TimberClient {
16
18
  expense: ExpenseService;
17
19
  expenseCategory: ExpenseCategoryService;
@@ -27,6 +29,8 @@ declare class TimberClient {
27
29
  cheque: ChequeService;
28
30
  bankStatement: BankStatementService;
29
31
  company: CompanyService;
32
+ invoiceNumber: InvoiceNumberService;
33
+ invoiceTemplate: InvoiceTemplateService;
30
34
  constructor(apiKey: string, options?: {
31
35
  baseURL?: string;
32
36
  });
package/dist/index.js CHANGED
@@ -19,6 +19,8 @@ const employee_1 = require("./employee");
19
19
  const cheque_1 = require("./cheque");
20
20
  const bankStatement_1 = require("./bankStatement");
21
21
  const company_1 = require("./company");
22
+ const invoiceNumber_1 = require("./invoiceNumber");
23
+ const invoiceTemplates_1 = require("./invoiceTemplates");
22
24
  class TimberClient {
23
25
  constructor(apiKey, options = {}) {
24
26
  const baseURL = `${options.baseURL || 'http://localhost:4010'}/api/v1/user/sdk`;
@@ -26,9 +28,9 @@ class TimberClient {
26
28
  baseURL: baseURL,
27
29
  headers: {
28
30
  Authorization: `ApiKey ${apiKey}`,
29
- 'Content-Type': 'application/json',
30
31
  },
31
32
  });
33
+ delete http.defaults.headers.post['Content-Type'];
32
34
  this.expense = new expense_1.ExpenseService(http);
33
35
  this.expenseCategory = new expenseCategory_1.ExpenseCategoryService(http);
34
36
  this.rawExpense = new rawExpense_1.RawExpenseService(http);
@@ -43,6 +45,8 @@ class TimberClient {
43
45
  this.cheque = new cheque_1.ChequeService(http);
44
46
  this.bankStatement = new bankStatement_1.BankStatementService(http);
45
47
  this.company = new company_1.CompanyService(http);
48
+ this.invoiceNumber = new invoiceNumber_1.InvoiceNumberService(http);
49
+ this.invoiceTemplate = new invoiceTemplates_1.InvoiceTemplateService(http);
46
50
  }
47
51
  }
48
52
  const createClient = (apiKey, options = {}) => {
@@ -0,0 +1,78 @@
1
+ import { AxiosInstance, AxiosResponse } from 'axios';
2
+ export interface CreateInvoiceNumberRequest {
3
+ enabled: boolean;
4
+ next_number: number;
5
+ sequence_length: number;
6
+ prefix: string;
7
+ }
8
+ export type UpdateInvoiceNumberRequest = Partial<CreateInvoiceNumberRequest>;
9
+ export interface InvoiceNumber {
10
+ _id: string;
11
+ company: string;
12
+ enabled: boolean;
13
+ next_number: number;
14
+ sequence_length: number;
15
+ prefix: string;
16
+ created_at: string;
17
+ updated_at: string;
18
+ }
19
+ export interface InvoiceNumberQueryParams {
20
+ search?: string;
21
+ }
22
+ export type NextNumberResponse = {
23
+ enabled: boolean;
24
+ next_invoice_number: number;
25
+ };
26
+ /**
27
+ * Service for Invoice Number
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const { createClient } = require('timber-sdk-dev');
32
+ * const client = createClient('your-api-key');
33
+ * const invoiceNumber = await client.invoiceNumber.get();
34
+ * console.log(invoiceNumber.data);
35
+ */
36
+ export declare class InvoiceNumberService {
37
+ private http;
38
+ constructor(http: AxiosInstance);
39
+ /**
40
+ * Fetch a single invoice number.
41
+ *
42
+ * @returns Invoice number object
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const invoiceNumber = await client.invoiceNumber.get();
47
+ * console.log(invoiceNumber.data);
48
+ * ```
49
+ */
50
+ get(): Promise<AxiosResponse<InvoiceNumber>>;
51
+ /**
52
+ * Fetch next invoice number.
53
+ *
54
+ * @returns Invoice number object
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const invoiceNumber = await client.invoiceNumber.next();
59
+ * console.log(invoiceNumber.data);
60
+ * ```
61
+ */
62
+ next(): Promise<AxiosResponse<NextNumberResponse>>;
63
+ /**
64
+ * Update an existing invoice number.
65
+ *
66
+ * @param id
67
+ * @param data
68
+ * @returns
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * const updates = { enabled: true };
73
+ * const updated = await client.InvoiceNumber.update(updates);
74
+ * console.log(updated.data);
75
+ * ```
76
+ */
77
+ update(data: CreateInvoiceNumberRequest): Promise<AxiosResponse<InvoiceNumber>>;
78
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvoiceNumberService = void 0;
4
+ /**
5
+ * Service for Invoice Number
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const { createClient } = require('timber-sdk-dev');
10
+ * const client = createClient('your-api-key');
11
+ * const invoiceNumber = await client.invoiceNumber.get();
12
+ * console.log(invoiceNumber.data);
13
+ */
14
+ class InvoiceNumberService {
15
+ constructor(http) {
16
+ this.http = http;
17
+ }
18
+ /**
19
+ * Fetch a single invoice number.
20
+ *
21
+ * @returns Invoice number object
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * const invoiceNumber = await client.invoiceNumber.get();
26
+ * console.log(invoiceNumber.data);
27
+ * ```
28
+ */
29
+ async get() {
30
+ return await this.http.get(`/customer/invoice-number`);
31
+ }
32
+ /**
33
+ * Fetch next invoice number.
34
+ *
35
+ * @returns Invoice number object
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const invoiceNumber = await client.invoiceNumber.next();
40
+ * console.log(invoiceNumber.data);
41
+ * ```
42
+ */
43
+ async next() {
44
+ return await this.http.get(`/customer/invoice-number/next`);
45
+ }
46
+ /**
47
+ * Update an existing invoice number.
48
+ *
49
+ * @param id
50
+ * @param data
51
+ * @returns
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * const updates = { enabled: true };
56
+ * const updated = await client.InvoiceNumber.update(updates);
57
+ * console.log(updated.data);
58
+ * ```
59
+ */
60
+ async update(data) {
61
+ return await this.http.patch(`/customer/invoice-number`, data);
62
+ }
63
+ }
64
+ exports.InvoiceNumberService = InvoiceNumberService;
@@ -77,7 +77,7 @@ class InvoicePaymentService {
77
77
  }
78
78
  formData.append('amount', data.amount.toString());
79
79
  if (data.file) {
80
- formData.append('file', data.file[0]);
80
+ formData.append('file', data.file);
81
81
  }
82
82
  return await this.http.post('/customer/invoice/payment-records', formData, {
83
83
  headers,
@@ -124,7 +124,7 @@ class InvoicePaymentService {
124
124
  formData.append('amount', data === null || data === void 0 ? void 0 : data.amount.toString());
125
125
  }
126
126
  if (data.file) {
127
- formData.append('file', data.file[0]);
127
+ formData.append('file', data.file);
128
128
  }
129
129
  return await this.http.put(`/customer/invoice/payment-records/${id}`, formData, {
130
130
  headers,
@@ -0,0 +1,143 @@
1
+ import { AxiosInstance, AxiosResponse } from 'axios';
2
+ export interface CreateInvoiceTemplateRequest {
3
+ terms: [
4
+ {
5
+ name: string;
6
+ content: string;
7
+ }
8
+ ];
9
+ notes: [
10
+ {
11
+ name: string;
12
+ content: string;
13
+ }
14
+ ];
15
+ type?: 'terms' | 'notes';
16
+ }
17
+ export type UpdateInvoiceTemplateRequest = Partial<CreateInvoiceTemplateRequest>;
18
+ export interface InvoiceTemplate {
19
+ _id: string;
20
+ company: string;
21
+ terms: [
22
+ {
23
+ name: string;
24
+ content: string;
25
+ }
26
+ ];
27
+ notes: [
28
+ {
29
+ name: string;
30
+ content: string;
31
+ }
32
+ ];
33
+ created_at: string;
34
+ updated_at: string;
35
+ }
36
+ export interface InvoiceTemplateQueryParams {
37
+ page?: number;
38
+ limit?: number;
39
+ sort?: string;
40
+ search?: string;
41
+ filters?: string;
42
+ }
43
+ /**
44
+ * Service for Invoice Template
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const { createClient } = require('timber-sdk-dev');
49
+ * const client = createClient('your-api-key');
50
+ * const InvoiceTemplate = await client.InvoiceTemplate.list({ page: 1, limit: 10 });
51
+ * console.log(InvoiceTemplate.data);
52
+ * ```
53
+ */
54
+ export declare class InvoiceTemplateService {
55
+ private http;
56
+ constructor(http: AxiosInstance);
57
+ /**
58
+ * Fetch a paginated list of invoice templates.
59
+ * @param params
60
+ * @returns
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * const invoiceTemplates = await client.InvoiceTemplate.list();
65
+ * console.log(invoiceTemplates.data);
66
+ * ```
67
+ */
68
+ list(params: InvoiceTemplateQueryParams): Promise<AxiosResponse<InvoiceTemplate>>;
69
+ /**
70
+ * Fetch a single invoice template by ID.
71
+ *
72
+ * @param id
73
+ * @returns
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * const invoiceTemplate = await client.InvoiceTemplate.get('invoice_template_id_here');
78
+ * console.log(invoiceTemplate.data);
79
+ * ``` */
80
+ get(id: string): Promise<AxiosResponse<InvoiceTemplate>>;
81
+ /**
82
+ * Create a new invoice template.
83
+ *
84
+ * @param data
85
+ * @returns
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * const newInvoiceTemplate = {
90
+ * terms: [
91
+ * {
92
+ * name: "Terms",
93
+ * content: "Terms content"
94
+ * }
95
+ * ],
96
+ * notes: [
97
+ * {
98
+ * name: "Notes",
99
+ * content: "Notes content"
100
+ * }
101
+ * ]
102
+ * };
103
+ * const response = await client.InvoiceTemplate.create(newInvoiceTemplate);
104
+ * console.log(response.data);
105
+ * ```
106
+ */
107
+ create(data: CreateInvoiceTemplateRequest): Promise<AxiosResponse<InvoiceTemplate>>;
108
+ /**
109
+ * Update an existing invoice template.
110
+ *
111
+ * @param id
112
+ * @param data
113
+ * @returns
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * const updates = { type: "notes", notes: [
118
+ * {
119
+ * name: "Notes",
120
+ * content: "Notes content"
121
+ * }
122
+ * ]};
123
+ * const updated = await client.InvoiceTemplate.update('invoice_template_id_here', updates);
124
+ * console.log(updated.data);
125
+ * ```
126
+ */
127
+ update(id: string, data: CreateInvoiceTemplateRequest): Promise<AxiosResponse<InvoiceTemplate>>;
128
+ /**
129
+ * Delete an invoice template by ID.
130
+ *
131
+ * @param id
132
+ * @returns
133
+ *
134
+ * @example
135
+ * ```ts
136
+ * const response = await client.InvoiceTemplate.delete('expense_category_id_here');
137
+ * console.log(response.data.message);
138
+ * ```
139
+ */
140
+ delete(id: string): Promise<AxiosResponse<{
141
+ message: string;
142
+ }>>;
143
+ }
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvoiceTemplateService = void 0;
4
+ /**
5
+ * Service for Invoice Template
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const { createClient } = require('timber-sdk-dev');
10
+ * const client = createClient('your-api-key');
11
+ * const InvoiceTemplate = await client.InvoiceTemplate.list({ page: 1, limit: 10 });
12
+ * console.log(InvoiceTemplate.data);
13
+ * ```
14
+ */
15
+ class InvoiceTemplateService {
16
+ constructor(http) {
17
+ this.http = http;
18
+ }
19
+ /**
20
+ * Fetch a paginated list of invoice templates.
21
+ * @param params
22
+ * @returns
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const invoiceTemplates = await client.InvoiceTemplate.list();
27
+ * console.log(invoiceTemplates.data);
28
+ * ```
29
+ */
30
+ async list(params) {
31
+ return await this.http.get('/customer/invoice-template', {
32
+ params,
33
+ });
34
+ }
35
+ /**
36
+ * Fetch a single invoice template by ID.
37
+ *
38
+ * @param id
39
+ * @returns
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * const invoiceTemplate = await client.InvoiceTemplate.get('invoice_template_id_here');
44
+ * console.log(invoiceTemplate.data);
45
+ * ``` */
46
+ async get(id) {
47
+ return await this.http.get(`/customer/invoice-template/${id}`);
48
+ }
49
+ /**
50
+ * Create a new invoice template.
51
+ *
52
+ * @param data
53
+ * @returns
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * const newInvoiceTemplate = {
58
+ * terms: [
59
+ * {
60
+ * name: "Terms",
61
+ * content: "Terms content"
62
+ * }
63
+ * ],
64
+ * notes: [
65
+ * {
66
+ * name: "Notes",
67
+ * content: "Notes content"
68
+ * }
69
+ * ]
70
+ * };
71
+ * const response = await client.InvoiceTemplate.create(newInvoiceTemplate);
72
+ * console.log(response.data);
73
+ * ```
74
+ */
75
+ async create(data) {
76
+ return await this.http.post('/customer/invoice-template', data);
77
+ }
78
+ /**
79
+ * Update an existing invoice template.
80
+ *
81
+ * @param id
82
+ * @param data
83
+ * @returns
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * const updates = { type: "notes", notes: [
88
+ * {
89
+ * name: "Notes",
90
+ * content: "Notes content"
91
+ * }
92
+ * ]};
93
+ * const updated = await client.InvoiceTemplate.update('invoice_template_id_here', updates);
94
+ * console.log(updated.data);
95
+ * ```
96
+ */
97
+ async update(id, data) {
98
+ return await this.http.put(`/customer/invoice-template/${id}`, data);
99
+ }
100
+ /**
101
+ * Delete an invoice template by ID.
102
+ *
103
+ * @param id
104
+ * @returns
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * const response = await client.InvoiceTemplate.delete('expense_category_id_here');
109
+ * console.log(response.data.message);
110
+ * ```
111
+ */
112
+ async delete(id) {
113
+ return await this.http.delete(`/customer/invoice-template/${id}`);
114
+ }
115
+ }
116
+ exports.InvoiceTemplateService = InvoiceTemplateService;
@@ -1,6 +1,12 @@
1
- type UniversalFormData = FormData | import('form-data');
2
- export declare function getFormData(): Promise<{
3
- formData: UniversalFormData;
1
+ export type BrowserFormDataResult = {
2
+ formData: FormData;
3
+ headers: undefined;
4
+ env: 'browser';
5
+ };
6
+ export type NodeFormDataResult = {
7
+ formData: import('form-data');
4
8
  headers: Record<string, string>;
5
- }>;
6
- export {};
9
+ env: 'node';
10
+ };
11
+ export type FormDataResult = BrowserFormDataResult | NodeFormDataResult;
12
+ export declare function getFormData(): Promise<FormDataResult>;
@@ -38,10 +38,10 @@ async function getFormData() {
38
38
  if (typeof window === 'undefined') {
39
39
  const FormDataNode = (await Promise.resolve().then(() => __importStar(require('form-data')))).default;
40
40
  const formData = new FormDataNode();
41
- return { formData, headers: formData.getHeaders() };
41
+ return { formData, headers: formData.getHeaders(), env: 'node' };
42
42
  }
43
43
  else {
44
44
  const formData = new FormData();
45
- return { formData, headers: {} };
45
+ return { formData, headers: undefined, env: 'browser' };
46
46
  }
47
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "timber-node",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Simplifying accounting and tax filing for businesses",
5
5
  "keywords": [
6
6
  "timber"