timber-node 0.4.0 → 0.4.2
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/README.md +3 -3
- package/dist/auth.d.ts +99 -0
- package/dist/auth.js +70 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +15 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ console.log(expenses.data);
|
|
|
26
26
|
|
|
27
27
|
## Authentication
|
|
28
28
|
|
|
29
|
-
Timber uses API Key-based authentication. Generate this API key from your Timber profile settings.
|
|
29
|
+
Timber uses API Key-based authentication. Generate this API key from your Timber profile developer settings.
|
|
30
30
|
|
|
31
31
|
```typescript
|
|
32
32
|
const client = createClient('your-api-key');
|
|
@@ -62,11 +62,11 @@ Each service provides common operations like `create`, `get`, `list`, `update`,
|
|
|
62
62
|
|
|
63
63
|
```typescript
|
|
64
64
|
const response = await client.expense.create({
|
|
65
|
-
type: '
|
|
65
|
+
type: 'Travel',
|
|
66
66
|
merchant: 'Uber',
|
|
67
67
|
category: 'Transportation',
|
|
68
68
|
date: '2025-06-23',
|
|
69
|
-
payment_method: '
|
|
69
|
+
payment_method: 'cash',
|
|
70
70
|
amount: 45.75,
|
|
71
71
|
});
|
|
72
72
|
console.log(response.data);
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosResponse } from 'axios';
|
|
2
|
+
export interface RegisterUserRequest {
|
|
3
|
+
name: string;
|
|
4
|
+
email: string;
|
|
5
|
+
partner: string;
|
|
6
|
+
plan: string;
|
|
7
|
+
domains: string[];
|
|
8
|
+
company: {
|
|
9
|
+
name: string;
|
|
10
|
+
email: string;
|
|
11
|
+
language: 'English' | 'Arabic';
|
|
12
|
+
currency: string;
|
|
13
|
+
tax_number: string;
|
|
14
|
+
address: string;
|
|
15
|
+
city: string;
|
|
16
|
+
state: string;
|
|
17
|
+
zip_code?: string;
|
|
18
|
+
country: string;
|
|
19
|
+
financial_start_date: string;
|
|
20
|
+
license_expiry: string;
|
|
21
|
+
license_issue_date: string;
|
|
22
|
+
sector: string[];
|
|
23
|
+
user_role: string;
|
|
24
|
+
business_years: string;
|
|
25
|
+
size: string;
|
|
26
|
+
current_method: string;
|
|
27
|
+
purpose: string;
|
|
28
|
+
country_code: string;
|
|
29
|
+
mobile: string;
|
|
30
|
+
logo?: string;
|
|
31
|
+
license: string;
|
|
32
|
+
license_number: string;
|
|
33
|
+
license_authority: string;
|
|
34
|
+
trn: string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** Service for registering users
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const { createClient } = require('timber-sdk-dev');
|
|
42
|
+
* const client = createClient('your-api-key');
|
|
43
|
+
* const response = await client.auth.create()
|
|
44
|
+
* console.log(response.data);
|
|
45
|
+
*/
|
|
46
|
+
export declare class AuthService {
|
|
47
|
+
private http;
|
|
48
|
+
constructor(http: AxiosInstance);
|
|
49
|
+
/**
|
|
50
|
+
* Register a new user.
|
|
51
|
+
*
|
|
52
|
+
* @param data - User registration payload
|
|
53
|
+
* @returns The created user and api_key for sdk
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const registerUserRequest: RegisterUserRequest = {
|
|
58
|
+
* name: "test",
|
|
59
|
+
* email: "test@test.com",
|
|
60
|
+
* partner: "test",
|
|
61
|
+
* plan: "test",
|
|
62
|
+
* domains: ["test"],
|
|
63
|
+
* company: {
|
|
64
|
+
* name: "test",
|
|
65
|
+
* email: "test@test.com",
|
|
66
|
+
* language: "English",
|
|
67
|
+
* currency: "USD",
|
|
68
|
+
* tax_number: "123456789",
|
|
69
|
+
* address: "123 Main St",
|
|
70
|
+
* city: "New York",
|
|
71
|
+
* state: "NY",
|
|
72
|
+
* zip_code: "10001",
|
|
73
|
+
* country: "USA",
|
|
74
|
+
* financial_start_date: "2023-01-01",
|
|
75
|
+
* license_expiry: "2023-01-01",
|
|
76
|
+
* license_issue_date: "2023-01-01",
|
|
77
|
+
* sector: ["product", "service"],
|
|
78
|
+
* user_role: "CEO",
|
|
79
|
+
* business_years: "1-2",
|
|
80
|
+
* size: "small",
|
|
81
|
+
* current_method: "accountant",
|
|
82
|
+
* purpose: "testing",
|
|
83
|
+
* country_code: "US",
|
|
84
|
+
* mobile: "1234567890",
|
|
85
|
+
* logo: "https://example.com/logo.png",
|
|
86
|
+
* license: "https://example.com/license.png",
|
|
87
|
+
* license_number: "123456789",
|
|
88
|
+
* license_authority: "NY",
|
|
89
|
+
* trn: "123456789",
|
|
90
|
+
* },
|
|
91
|
+
* };
|
|
92
|
+
* const { createClient } = require('timber-sdk-dev');
|
|
93
|
+
* const client = createClient('your-api-key');
|
|
94
|
+
* const response = await client.auth.create(registerUserRequest)
|
|
95
|
+
* console.log(response.data);
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
create(data: RegisterUserRequest): Promise<AxiosResponse<any>>;
|
|
99
|
+
}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthService = void 0;
|
|
4
|
+
/** Service for registering users
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const { createClient } = require('timber-sdk-dev');
|
|
9
|
+
* const client = createClient('your-api-key');
|
|
10
|
+
* const response = await client.auth.create()
|
|
11
|
+
* console.log(response.data);
|
|
12
|
+
*/
|
|
13
|
+
class AuthService {
|
|
14
|
+
constructor(http) {
|
|
15
|
+
this.http = http;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Register a new user.
|
|
19
|
+
*
|
|
20
|
+
* @param data - User registration payload
|
|
21
|
+
* @returns The created user and api_key for sdk
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const registerUserRequest: RegisterUserRequest = {
|
|
26
|
+
* name: "test",
|
|
27
|
+
* email: "test@test.com",
|
|
28
|
+
* partner: "test",
|
|
29
|
+
* plan: "test",
|
|
30
|
+
* domains: ["test"],
|
|
31
|
+
* company: {
|
|
32
|
+
* name: "test",
|
|
33
|
+
* email: "test@test.com",
|
|
34
|
+
* language: "English",
|
|
35
|
+
* currency: "USD",
|
|
36
|
+
* tax_number: "123456789",
|
|
37
|
+
* address: "123 Main St",
|
|
38
|
+
* city: "New York",
|
|
39
|
+
* state: "NY",
|
|
40
|
+
* zip_code: "10001",
|
|
41
|
+
* country: "USA",
|
|
42
|
+
* financial_start_date: "2023-01-01",
|
|
43
|
+
* license_expiry: "2023-01-01",
|
|
44
|
+
* license_issue_date: "2023-01-01",
|
|
45
|
+
* sector: ["product", "service"],
|
|
46
|
+
* user_role: "CEO",
|
|
47
|
+
* business_years: "1-2",
|
|
48
|
+
* size: "small",
|
|
49
|
+
* current_method: "accountant",
|
|
50
|
+
* purpose: "testing",
|
|
51
|
+
* country_code: "US",
|
|
52
|
+
* mobile: "1234567890",
|
|
53
|
+
* logo: "https://example.com/logo.png",
|
|
54
|
+
* license: "https://example.com/license.png",
|
|
55
|
+
* license_number: "123456789",
|
|
56
|
+
* license_authority: "NY",
|
|
57
|
+
* trn: "123456789",
|
|
58
|
+
* },
|
|
59
|
+
* };
|
|
60
|
+
* const { createClient } = require('timber-sdk-dev');
|
|
61
|
+
* const client = createClient('your-api-key');
|
|
62
|
+
* const response = await client.auth.create(registerUserRequest)
|
|
63
|
+
* console.log(response.data);
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
async create(data) {
|
|
67
|
+
return await this.http.post('/auth/register', data);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.AuthService = AuthService;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AuthService } from './auth';
|
|
1
2
|
import { ExpenseService } from './expense';
|
|
2
3
|
import { RawExpenseService } from './rawExpense';
|
|
3
4
|
import { VendorPaymentService } from './vendorPayment';
|
|
@@ -16,6 +17,7 @@ import { InvoiceNumberService } from './invoiceNumber';
|
|
|
16
17
|
import { InvoiceTemplateService } from './invoiceTemplates';
|
|
17
18
|
import { InvoiceItemService } from './invoiceItem';
|
|
18
19
|
declare class TimberClient {
|
|
20
|
+
auth: AuthService;
|
|
19
21
|
expense: ExpenseService;
|
|
20
22
|
expenseCategory: ExpenseCategoryService;
|
|
21
23
|
rawExpense: RawExpenseService;
|
|
@@ -35,8 +37,12 @@ declare class TimberClient {
|
|
|
35
37
|
invoiceItem: InvoiceItemService;
|
|
36
38
|
constructor(apiKey: string, options?: {
|
|
37
39
|
baseURL?: string;
|
|
40
|
+
partnerAPIKey?: string;
|
|
38
41
|
});
|
|
39
42
|
}
|
|
40
|
-
export declare const createClient: (apiKey: string, options?: {
|
|
43
|
+
export declare const createClient: (apiKey: string, options?: {
|
|
44
|
+
partnerAPIKey: string;
|
|
45
|
+
baseURL: string;
|
|
46
|
+
}) => TimberClient;
|
|
41
47
|
export type TimberClientType = InstanceType<typeof TimberClient>;
|
|
42
48
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createClient = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const auth_1 = require("./auth");
|
|
8
9
|
const expense_1 = require("./expense");
|
|
9
10
|
const rawExpense_1 = require("./rawExpense");
|
|
10
11
|
const vendorPayment_1 = require("./vendorPayment");
|
|
@@ -25,6 +26,7 @@ const invoiceItem_1 = require("./invoiceItem");
|
|
|
25
26
|
class TimberClient {
|
|
26
27
|
constructor(apiKey, options = {}) {
|
|
27
28
|
const baseURL = `${options.baseURL || 'https://api.timber.me'}/api/v1/user/sdk`;
|
|
29
|
+
// Create HTTP client for regular services (non-auth)
|
|
28
30
|
const http = axios_1.default.create({
|
|
29
31
|
baseURL: baseURL,
|
|
30
32
|
headers: {
|
|
@@ -32,9 +34,17 @@ class TimberClient {
|
|
|
32
34
|
},
|
|
33
35
|
});
|
|
34
36
|
delete http.defaults.headers.post['Content-Type'];
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
// Create HTTP client for auth service only (with partner API key if provided)
|
|
38
|
+
const authHttp = axios_1.default.create({
|
|
39
|
+
baseURL: baseURL,
|
|
40
|
+
headers: {
|
|
41
|
+
Authorization: (options === null || options === void 0 ? void 0 : options.partnerAPIKey)
|
|
42
|
+
? `Bearer ${options.partnerAPIKey}`
|
|
43
|
+
: `ApiKey ${apiKey}`,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
delete authHttp.defaults.headers.post['Content-Type'];
|
|
47
|
+
this.auth = new auth_1.AuthService(authHttp);
|
|
38
48
|
this.expense = new expense_1.ExpenseService(http);
|
|
39
49
|
this.expenseCategory = new expenseCategory_1.ExpenseCategoryService(http);
|
|
40
50
|
this.rawExpense = new rawExpense_1.RawExpenseService(http);
|
|
@@ -54,8 +64,8 @@ class TimberClient {
|
|
|
54
64
|
this.invoiceItem = new invoiceItem_1.InvoiceItemService(http);
|
|
55
65
|
}
|
|
56
66
|
}
|
|
57
|
-
const createClient = (apiKey, options = {}) => {
|
|
58
|
-
if (!apiKey) {
|
|
67
|
+
const createClient = (apiKey, options = { partnerAPIKey: '', baseURL: '' }) => {
|
|
68
|
+
if (!apiKey && !options.partnerAPIKey) {
|
|
59
69
|
throw new Error('API key is required');
|
|
60
70
|
}
|
|
61
71
|
return new TimberClient(apiKey, options);
|