timber-node 0.0.6 → 0.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.
@@ -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.BillPaymentService = void 0;
7
- const form_data_1 = __importDefault(require("form-data"));
4
+ const getFormData_1 = require("./utils/getFormData");
8
5
  /**
9
6
  * Service for Bill Payment
10
7
  *
@@ -62,7 +59,7 @@ class BillPaymentService {
62
59
  * ```
63
60
  */
64
61
  async create(data) {
65
- const formData = new form_data_1.default();
62
+ const { formData, headers } = await (0, getFormData_1.getFormData)();
66
63
  formData.append('invoice', data.invoice);
67
64
  formData.append('date', data.date);
68
65
  formData.append('payment_method', data.payment_method);
@@ -83,7 +80,7 @@ class BillPaymentService {
83
80
  formData.append('file', data.file[0]);
84
81
  }
85
82
  return await this.http.post('/customer/purchase/payment-record', formData, {
86
- headers: formData.getHeaders(),
83
+ headers,
87
84
  });
88
85
  }
89
86
  /**
@@ -101,7 +98,7 @@ class BillPaymentService {
101
98
  * ```
102
99
  */
103
100
  async update(id, data) {
104
- const formData = new form_data_1.default();
101
+ const { formData, headers } = await (0, getFormData_1.getFormData)();
105
102
  formData.append('invoice', data.invoice);
106
103
  formData.append('date', data.date);
107
104
  formData.append('payment_method', data.payment_method);
@@ -122,7 +119,7 @@ class BillPaymentService {
122
119
  formData.append('file', data.file[0]);
123
120
  }
124
121
  return await this.http.put(`/customer/purchase/payment-record/${id}`, formData, {
125
- headers: formData.getHeaders(),
122
+ headers,
126
123
  });
127
124
  }
128
125
  /**
package/dist/customer.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CustomerService = void 0;
4
+ const getFormData_1 = require("./utils/getFormData");
4
5
  /**
5
6
  * Service for Customer
6
7
  *
@@ -44,7 +45,18 @@ class CustomerService {
44
45
  * ```
45
46
  */
46
47
  async create(data) {
47
- return await this.http.post('/customer/customer', data);
48
+ const { formData, headers } = await (0, getFormData_1.getFormData)();
49
+ Object.entries(data).forEach(([key, value]) => {
50
+ if (value instanceof File) {
51
+ formData.append(key, value);
52
+ }
53
+ else {
54
+ formData.append(key, value);
55
+ }
56
+ });
57
+ return await this.http.post('/customer/customer', formData, {
58
+ headers,
59
+ });
48
60
  }
49
61
  /**
50
62
  * Update an existing customer.
@@ -61,7 +73,18 @@ class CustomerService {
61
73
  * ```
62
74
  */
63
75
  async update(id, data) {
64
- return await this.http.put(`/customer/customer/${id}`, data);
76
+ const { formData, headers } = await (0, getFormData_1.getFormData)();
77
+ Object.entries(data).forEach(([key, value]) => {
78
+ if (value instanceof File) {
79
+ formData.append(key, value);
80
+ }
81
+ else {
82
+ formData.append(key, value);
83
+ }
84
+ });
85
+ return await this.http.put(`/customer/customer/${id}`, formData, {
86
+ headers,
87
+ });
65
88
  }
66
89
  /**
67
90
  * Delete an customer by ID.
package/dist/invoice.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.InvoiceService = void 0;
7
- const form_data_1 = __importDefault(require("form-data"));
4
+ const getFormData_1 = require("./utils/getFormData");
8
5
  /**
9
6
  * Service for Invoice
10
7
  *
@@ -51,7 +48,7 @@ class InvoiceService {
51
48
  return await this.http.get(`/customer/invoice/${id}`);
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
  for (const key in data) {
56
53
  const value = data[key];
57
54
  if (key === 'items' || key === 'customer' || key === 'biller') {
@@ -69,11 +66,11 @@ class InvoiceService {
69
66
  }
70
67
  }
71
68
  return await this.http.post('/customer/invoice', formData, {
72
- headers: formData.getHeaders(),
69
+ headers,
73
70
  });
74
71
  }
75
72
  async update(id, data) {
76
- const formData = new form_data_1.default();
73
+ const { formData, headers } = await (0, getFormData_1.getFormData)();
77
74
  for (const key in data) {
78
75
  const value = data[key];
79
76
  if (key === 'items' || key === 'customer' || key === 'biller') {
@@ -91,7 +88,7 @@ class InvoiceService {
91
88
  }
92
89
  }
93
90
  return await this.http.put(`/customer/invoice/${id}`, data, {
94
- headers: formData.getHeaders(),
91
+ headers,
95
92
  });
96
93
  }
97
94
  /**
@@ -5,6 +5,7 @@ export interface InvoicePaymentData {
5
5
  payment_method: string;
6
6
  cheque_no?: string;
7
7
  cheque_date?: string;
8
+ cheque_due_date?: string;
8
9
  bank_name?: string;
9
10
  file?: string;
10
11
  amount: string;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InvoicePaymentService = void 0;
4
+ const getFormData_1 = require("./utils/getFormData");
4
5
  /**
5
6
  * Service for Invoice Payment
6
7
  *
@@ -58,7 +59,29 @@ class InvoicePaymentService {
58
59
  * ```
59
60
  */
60
61
  async create(data) {
61
- return await this.http.post('/customer/invoice/payment-records', data);
62
+ const { formData, headers } = await (0, getFormData_1.getFormData)();
63
+ formData.append('invoice', data.invoice);
64
+ formData.append('date', data.date);
65
+ formData.append('payment_method', data.payment_method);
66
+ if (data.cheque_no) {
67
+ formData.append('cheque_no', data.cheque_no);
68
+ }
69
+ if (data.cheque_date) {
70
+ formData.append('cheque_date', data.cheque_date);
71
+ }
72
+ if (data.cheque_due_date) {
73
+ formData.append('cheque_due_date', data.cheque_due_date);
74
+ }
75
+ if (data.bank_name) {
76
+ formData.append('bank_name', data.bank_name);
77
+ }
78
+ formData.append('amount', data.amount.toString());
79
+ if (data.file) {
80
+ formData.append('file', data.file[0]);
81
+ }
82
+ return await this.http.post('/customer/invoice/payment-records', formData, {
83
+ headers,
84
+ });
62
85
  }
63
86
  /**
64
87
  * Update an existing invoice payment.
@@ -75,7 +98,37 @@ class InvoicePaymentService {
75
98
  * ```
76
99
  */
77
100
  async update(id, data) {
78
- return await this.http.put(`/customer/invoice/payment-records/${id}`, data);
101
+ const { formData, headers } = await (0, getFormData_1.getFormData)();
102
+ if (data.invoice) {
103
+ formData.append('invoice', data.invoice);
104
+ }
105
+ if (data.date) {
106
+ formData.append('date', data.date);
107
+ }
108
+ if (data.payment_method) {
109
+ formData.append('payment_method', data.payment_method);
110
+ }
111
+ if (data.cheque_no) {
112
+ formData.append('cheque_no', data.cheque_no);
113
+ }
114
+ if (data.cheque_date) {
115
+ formData.append('cheque_date', data.cheque_date);
116
+ }
117
+ if (data.cheque_due_date) {
118
+ formData.append('cheque_due_date', data.cheque_due_date);
119
+ }
120
+ if (data.bank_name) {
121
+ formData.append('bank_name', data.bank_name);
122
+ }
123
+ if (data === null || data === void 0 ? void 0 : data.amount) {
124
+ formData.append('amount', data === null || data === void 0 ? void 0 : data.amount.toString());
125
+ }
126
+ if (data.file) {
127
+ formData.append('file', data.file[0]);
128
+ }
129
+ return await this.http.put(`/customer/invoice/payment-records/${id}`, formData, {
130
+ headers,
131
+ });
79
132
  }
80
133
  /**
81
134
  * Delete an invoice payment by ID.
@@ -0,0 +1,6 @@
1
+ type UniversalFormData = FormData | import('form-data');
2
+ export declare function getFormData(): Promise<{
3
+ formData: UniversalFormData;
4
+ headers: Record<string, string>;
5
+ }>;
6
+ export {};
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.getFormData = getFormData;
37
+ async function getFormData() {
38
+ if (typeof window === 'undefined') {
39
+ const FormDataNode = (await Promise.resolve().then(() => __importStar(require('form-data')))).default;
40
+ const formData = new FormDataNode();
41
+ return { formData, headers: formData.getHeaders() };
42
+ }
43
+ else {
44
+ const formData = new FormData();
45
+ return { formData, headers: {} };
46
+ }
47
+ }
@@ -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.VendorPaymentService = void 0;
7
- const form_data_1 = __importDefault(require("form-data"));
4
+ const getFormData_1 = require("./utils/getFormData");
8
5
  /**
9
6
  * Service for Vendor Payment
10
7
  *
@@ -112,7 +109,7 @@ class VendorPaymentService {
112
109
  * ```
113
110
  */
114
111
  async create(data) {
115
- const formData = new form_data_1.default();
112
+ const { formData, headers } = await (0, getFormData_1.getFormData)();
116
113
  try {
117
114
  Object.entries(data).forEach(([key, value]) => {
118
115
  if (key === 'customer' || key === 'biller') {
@@ -154,7 +151,7 @@ class VendorPaymentService {
154
151
  formData.append('file', data.logo);
155
152
  }
156
153
  return await this.http.post('/customer/purchase', formData, {
157
- headers: formData.getHeaders(),
154
+ headers,
158
155
  });
159
156
  }
160
157
  /**
@@ -172,7 +169,7 @@ class VendorPaymentService {
172
169
  * ```
173
170
  */
174
171
  async update(id, data) {
175
- const formData = new form_data_1.default();
172
+ const { formData, headers } = await (0, getFormData_1.getFormData)();
176
173
  try {
177
174
  Object.entries(data).forEach(([key, value]) => {
178
175
  if (key === 'customer' || key === 'biller') {
@@ -214,7 +211,7 @@ class VendorPaymentService {
214
211
  formData.append('file', data.logo);
215
212
  }
216
213
  return await this.http.put(`/customer/purchase/${id}`, formData, {
217
- headers: formData.getHeaders(),
214
+ headers,
218
215
  });
219
216
  }
220
217
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "timber-node",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Simplifying accounting and tax filing for businesses",
5
5
  "keywords": [
6
6
  "timber"