@bibike/erp-sdk 1.0.0 → 1.1.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.
- package/dist/index.d.mts +42 -3
- package/dist/index.d.ts +42 -3
- package/dist/index.js +50 -2
- package/dist/index.mjs +50 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -29,14 +29,37 @@ interface DateRangeParams {
|
|
|
29
29
|
[key: string]: string | number | boolean | undefined;
|
|
30
30
|
}
|
|
31
31
|
interface LoginCredentials {
|
|
32
|
-
|
|
32
|
+
/** Email or username */
|
|
33
|
+
login: string;
|
|
33
34
|
password: string;
|
|
35
|
+
/** 2FA code if required */
|
|
36
|
+
two_factor_code?: string;
|
|
34
37
|
}
|
|
35
38
|
interface AuthResponse {
|
|
36
39
|
token: string;
|
|
37
40
|
user: User;
|
|
38
41
|
expires_at: string;
|
|
39
42
|
}
|
|
43
|
+
interface TwoFactorRequiredResponse {
|
|
44
|
+
requires_2fa: true;
|
|
45
|
+
/** Temporary token to use when submitting 2FA code */
|
|
46
|
+
temp_token: string;
|
|
47
|
+
/** Available 2FA methods */
|
|
48
|
+
methods: ('totp' | 'sms' | 'email')[];
|
|
49
|
+
}
|
|
50
|
+
interface LoginResponse {
|
|
51
|
+
success: boolean;
|
|
52
|
+
data?: AuthResponse;
|
|
53
|
+
requires_2fa?: boolean;
|
|
54
|
+
temp_token?: string;
|
|
55
|
+
methods?: ('totp' | 'sms' | 'email')[];
|
|
56
|
+
message?: string;
|
|
57
|
+
}
|
|
58
|
+
interface TwoFactorVerifyInput {
|
|
59
|
+
temp_token: string;
|
|
60
|
+
code: string;
|
|
61
|
+
method?: 'totp' | 'sms' | 'email';
|
|
62
|
+
}
|
|
40
63
|
interface User {
|
|
41
64
|
id: number;
|
|
42
65
|
email: string;
|
|
@@ -537,10 +560,26 @@ declare class BibikeClient {
|
|
|
537
560
|
private timeout;
|
|
538
561
|
private customHeaders;
|
|
539
562
|
constructor(config: BibikeConfig);
|
|
540
|
-
|
|
563
|
+
/**
|
|
564
|
+
* Login with email/username and password
|
|
565
|
+
* Returns LoginResponse which may indicate 2FA is required
|
|
566
|
+
*/
|
|
567
|
+
login(credentials: LoginCredentials): Promise<LoginResponse>;
|
|
568
|
+
/**
|
|
569
|
+
* Verify 2FA code after initial login
|
|
570
|
+
*/
|
|
571
|
+
verify2FA(input: TwoFactorVerifyInput): Promise<LoginResponse>;
|
|
572
|
+
/**
|
|
573
|
+
* Request 2FA code via specific method (SMS/email)
|
|
574
|
+
*/
|
|
575
|
+
request2FACode(tempToken: string, method: 'sms' | 'email'): Promise<{
|
|
576
|
+
success: boolean;
|
|
577
|
+
message?: string;
|
|
578
|
+
}>;
|
|
541
579
|
logout(): Promise<void>;
|
|
542
580
|
me(): Promise<User>;
|
|
543
581
|
setToken(token: string): void;
|
|
582
|
+
getToken(): string | null;
|
|
544
583
|
readonly products: {
|
|
545
584
|
list: (params?: PaginationParams & {
|
|
546
585
|
search?: string;
|
|
@@ -745,4 +784,4 @@ declare class BibikeApiError extends Error {
|
|
|
745
784
|
constructor(message: string, statusCode: number, code?: string | undefined);
|
|
746
785
|
}
|
|
747
786
|
|
|
748
|
-
export { type Account, type Activity, type ApiResponse, type Attendance, type AuthResponse, BibikeApiError, BibikeClient, type BibikeConfig, type CreateAdjustmentInput, type CreateCustomerInput, type CreateJournalEntryInput, type CreateProductInput, type CreatePurchaseOrderInput, type CreateSaleInput, type CreateSupplierInput, type CreateTransferInput, type CreateWebhookInput, type Customer, type DashboardStats, type DateRangeParams, type Department, type Employee, type InventoryItem, type InventoryReport, type JournalEntry, type JournalLine, type Lead, type LeaveRequest, type Location, type LoginCredentials, type Opportunity, type POSSession, type PaginatedResponse, type PaginationParams, type Position, type Product, type ProfitLossReport, type PurchaseOrder, type PurchaseOrderItem, type PurchaseRequisition, type Quotation, type Sale, type SaleItem, type SalesOrder, type SalesReport, type Shop, type StockAdjustment, type StockTransfer, type StockTransferItem, type Supplier, type TaxRate, type UpdateProductInput, type User, type Warehouse, type Webhook, type WebhookDelivery, type WebhookEvent };
|
|
787
|
+
export { type Account, type Activity, type ApiResponse, type Attendance, type AuthResponse, BibikeApiError, BibikeClient, type BibikeConfig, type CreateAdjustmentInput, type CreateCustomerInput, type CreateJournalEntryInput, type CreateProductInput, type CreatePurchaseOrderInput, type CreateSaleInput, type CreateSupplierInput, type CreateTransferInput, type CreateWebhookInput, type Customer, type DashboardStats, type DateRangeParams, type Department, type Employee, type InventoryItem, type InventoryReport, type JournalEntry, type JournalLine, type Lead, type LeaveRequest, type Location, type LoginCredentials, type LoginResponse, type Opportunity, type POSSession, type PaginatedResponse, type PaginationParams, type Position, type Product, type ProfitLossReport, type PurchaseOrder, type PurchaseOrderItem, type PurchaseRequisition, type Quotation, type Sale, type SaleItem, type SalesOrder, type SalesReport, type Shop, type StockAdjustment, type StockTransfer, type StockTransferItem, type Supplier, type TaxRate, type TwoFactorRequiredResponse, type TwoFactorVerifyInput, type UpdateProductInput, type User, type Warehouse, type Webhook, type WebhookDelivery, type WebhookEvent };
|
package/dist/index.d.ts
CHANGED
|
@@ -29,14 +29,37 @@ interface DateRangeParams {
|
|
|
29
29
|
[key: string]: string | number | boolean | undefined;
|
|
30
30
|
}
|
|
31
31
|
interface LoginCredentials {
|
|
32
|
-
|
|
32
|
+
/** Email or username */
|
|
33
|
+
login: string;
|
|
33
34
|
password: string;
|
|
35
|
+
/** 2FA code if required */
|
|
36
|
+
two_factor_code?: string;
|
|
34
37
|
}
|
|
35
38
|
interface AuthResponse {
|
|
36
39
|
token: string;
|
|
37
40
|
user: User;
|
|
38
41
|
expires_at: string;
|
|
39
42
|
}
|
|
43
|
+
interface TwoFactorRequiredResponse {
|
|
44
|
+
requires_2fa: true;
|
|
45
|
+
/** Temporary token to use when submitting 2FA code */
|
|
46
|
+
temp_token: string;
|
|
47
|
+
/** Available 2FA methods */
|
|
48
|
+
methods: ('totp' | 'sms' | 'email')[];
|
|
49
|
+
}
|
|
50
|
+
interface LoginResponse {
|
|
51
|
+
success: boolean;
|
|
52
|
+
data?: AuthResponse;
|
|
53
|
+
requires_2fa?: boolean;
|
|
54
|
+
temp_token?: string;
|
|
55
|
+
methods?: ('totp' | 'sms' | 'email')[];
|
|
56
|
+
message?: string;
|
|
57
|
+
}
|
|
58
|
+
interface TwoFactorVerifyInput {
|
|
59
|
+
temp_token: string;
|
|
60
|
+
code: string;
|
|
61
|
+
method?: 'totp' | 'sms' | 'email';
|
|
62
|
+
}
|
|
40
63
|
interface User {
|
|
41
64
|
id: number;
|
|
42
65
|
email: string;
|
|
@@ -537,10 +560,26 @@ declare class BibikeClient {
|
|
|
537
560
|
private timeout;
|
|
538
561
|
private customHeaders;
|
|
539
562
|
constructor(config: BibikeConfig);
|
|
540
|
-
|
|
563
|
+
/**
|
|
564
|
+
* Login with email/username and password
|
|
565
|
+
* Returns LoginResponse which may indicate 2FA is required
|
|
566
|
+
*/
|
|
567
|
+
login(credentials: LoginCredentials): Promise<LoginResponse>;
|
|
568
|
+
/**
|
|
569
|
+
* Verify 2FA code after initial login
|
|
570
|
+
*/
|
|
571
|
+
verify2FA(input: TwoFactorVerifyInput): Promise<LoginResponse>;
|
|
572
|
+
/**
|
|
573
|
+
* Request 2FA code via specific method (SMS/email)
|
|
574
|
+
*/
|
|
575
|
+
request2FACode(tempToken: string, method: 'sms' | 'email'): Promise<{
|
|
576
|
+
success: boolean;
|
|
577
|
+
message?: string;
|
|
578
|
+
}>;
|
|
541
579
|
logout(): Promise<void>;
|
|
542
580
|
me(): Promise<User>;
|
|
543
581
|
setToken(token: string): void;
|
|
582
|
+
getToken(): string | null;
|
|
544
583
|
readonly products: {
|
|
545
584
|
list: (params?: PaginationParams & {
|
|
546
585
|
search?: string;
|
|
@@ -745,4 +784,4 @@ declare class BibikeApiError extends Error {
|
|
|
745
784
|
constructor(message: string, statusCode: number, code?: string | undefined);
|
|
746
785
|
}
|
|
747
786
|
|
|
748
|
-
export { type Account, type Activity, type ApiResponse, type Attendance, type AuthResponse, BibikeApiError, BibikeClient, type BibikeConfig, type CreateAdjustmentInput, type CreateCustomerInput, type CreateJournalEntryInput, type CreateProductInput, type CreatePurchaseOrderInput, type CreateSaleInput, type CreateSupplierInput, type CreateTransferInput, type CreateWebhookInput, type Customer, type DashboardStats, type DateRangeParams, type Department, type Employee, type InventoryItem, type InventoryReport, type JournalEntry, type JournalLine, type Lead, type LeaveRequest, type Location, type LoginCredentials, type Opportunity, type POSSession, type PaginatedResponse, type PaginationParams, type Position, type Product, type ProfitLossReport, type PurchaseOrder, type PurchaseOrderItem, type PurchaseRequisition, type Quotation, type Sale, type SaleItem, type SalesOrder, type SalesReport, type Shop, type StockAdjustment, type StockTransfer, type StockTransferItem, type Supplier, type TaxRate, type UpdateProductInput, type User, type Warehouse, type Webhook, type WebhookDelivery, type WebhookEvent };
|
|
787
|
+
export { type Account, type Activity, type ApiResponse, type Attendance, type AuthResponse, BibikeApiError, BibikeClient, type BibikeConfig, type CreateAdjustmentInput, type CreateCustomerInput, type CreateJournalEntryInput, type CreateProductInput, type CreatePurchaseOrderInput, type CreateSaleInput, type CreateSupplierInput, type CreateTransferInput, type CreateWebhookInput, type Customer, type DashboardStats, type DateRangeParams, type Department, type Employee, type InventoryItem, type InventoryReport, type JournalEntry, type JournalLine, type Lead, type LeaveRequest, type Location, type LoginCredentials, type LoginResponse, type Opportunity, type POSSession, type PaginatedResponse, type PaginationParams, type Position, type Product, type ProfitLossReport, type PurchaseOrder, type PurchaseOrderItem, type PurchaseRequisition, type Quotation, type Sale, type SaleItem, type SalesOrder, type SalesReport, type Shop, type StockAdjustment, type StockTransfer, type StockTransferItem, type Supplier, type TaxRate, type TwoFactorRequiredResponse, type TwoFactorVerifyInput, type UpdateProductInput, type User, type Warehouse, type Webhook, type WebhookDelivery, type WebhookEvent };
|
package/dist/index.js
CHANGED
|
@@ -340,12 +340,57 @@ var BibikeClient = class {
|
|
|
340
340
|
this.customHeaders = config.headers || {};
|
|
341
341
|
}
|
|
342
342
|
// ============ Auth ============
|
|
343
|
+
/**
|
|
344
|
+
* Login with email/username and password
|
|
345
|
+
* Returns LoginResponse which may indicate 2FA is required
|
|
346
|
+
*/
|
|
343
347
|
async login(credentials) {
|
|
344
|
-
const response = await this.request("auth", "login", "POST",
|
|
348
|
+
const response = await this.request("auth", "login", "POST", {
|
|
349
|
+
// Send both for backwards compatibility with older API versions
|
|
350
|
+
username: credentials.login,
|
|
351
|
+
login: credentials.login,
|
|
352
|
+
password: credentials.password,
|
|
353
|
+
two_factor_code: credentials.two_factor_code
|
|
354
|
+
});
|
|
355
|
+
const rawResponse = response;
|
|
356
|
+
if (rawResponse.requires_2fa) {
|
|
357
|
+
return {
|
|
358
|
+
success: false,
|
|
359
|
+
requires_2fa: true,
|
|
360
|
+
temp_token: rawResponse.temp_token,
|
|
361
|
+
methods: rawResponse.methods
|
|
362
|
+
};
|
|
363
|
+
}
|
|
345
364
|
if (response.data?.token) {
|
|
346
365
|
this.token = response.data.token;
|
|
347
366
|
}
|
|
348
|
-
return
|
|
367
|
+
return {
|
|
368
|
+
success: true,
|
|
369
|
+
data: response.data
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Verify 2FA code after initial login
|
|
374
|
+
*/
|
|
375
|
+
async verify2FA(input) {
|
|
376
|
+
const response = await this.request("auth", "verify_2fa", "POST", input);
|
|
377
|
+
if (response.data?.token) {
|
|
378
|
+
this.token = response.data.token;
|
|
379
|
+
}
|
|
380
|
+
return {
|
|
381
|
+
success: true,
|
|
382
|
+
data: response.data
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Request 2FA code via specific method (SMS/email)
|
|
387
|
+
*/
|
|
388
|
+
async request2FACode(tempToken, method) {
|
|
389
|
+
const response = await this.request("auth", "request_2fa_code", "POST", {
|
|
390
|
+
temp_token: tempToken,
|
|
391
|
+
method
|
|
392
|
+
});
|
|
393
|
+
return { success: true, message: response.data?.message };
|
|
349
394
|
}
|
|
350
395
|
async logout() {
|
|
351
396
|
await this.request("auth", "logout", "POST");
|
|
@@ -358,6 +403,9 @@ var BibikeClient = class {
|
|
|
358
403
|
setToken(token) {
|
|
359
404
|
this.token = token;
|
|
360
405
|
}
|
|
406
|
+
getToken() {
|
|
407
|
+
return this.token;
|
|
408
|
+
}
|
|
361
409
|
// ============ Core Request Method ============
|
|
362
410
|
async request(resource, action, method = "GET", body, params) {
|
|
363
411
|
const url = new URL(this.baseUrl);
|
package/dist/index.mjs
CHANGED
|
@@ -313,12 +313,57 @@ var BibikeClient = class {
|
|
|
313
313
|
this.customHeaders = config.headers || {};
|
|
314
314
|
}
|
|
315
315
|
// ============ Auth ============
|
|
316
|
+
/**
|
|
317
|
+
* Login with email/username and password
|
|
318
|
+
* Returns LoginResponse which may indicate 2FA is required
|
|
319
|
+
*/
|
|
316
320
|
async login(credentials) {
|
|
317
|
-
const response = await this.request("auth", "login", "POST",
|
|
321
|
+
const response = await this.request("auth", "login", "POST", {
|
|
322
|
+
// Send both for backwards compatibility with older API versions
|
|
323
|
+
username: credentials.login,
|
|
324
|
+
login: credentials.login,
|
|
325
|
+
password: credentials.password,
|
|
326
|
+
two_factor_code: credentials.two_factor_code
|
|
327
|
+
});
|
|
328
|
+
const rawResponse = response;
|
|
329
|
+
if (rawResponse.requires_2fa) {
|
|
330
|
+
return {
|
|
331
|
+
success: false,
|
|
332
|
+
requires_2fa: true,
|
|
333
|
+
temp_token: rawResponse.temp_token,
|
|
334
|
+
methods: rawResponse.methods
|
|
335
|
+
};
|
|
336
|
+
}
|
|
318
337
|
if (response.data?.token) {
|
|
319
338
|
this.token = response.data.token;
|
|
320
339
|
}
|
|
321
|
-
return
|
|
340
|
+
return {
|
|
341
|
+
success: true,
|
|
342
|
+
data: response.data
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Verify 2FA code after initial login
|
|
347
|
+
*/
|
|
348
|
+
async verify2FA(input) {
|
|
349
|
+
const response = await this.request("auth", "verify_2fa", "POST", input);
|
|
350
|
+
if (response.data?.token) {
|
|
351
|
+
this.token = response.data.token;
|
|
352
|
+
}
|
|
353
|
+
return {
|
|
354
|
+
success: true,
|
|
355
|
+
data: response.data
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Request 2FA code via specific method (SMS/email)
|
|
360
|
+
*/
|
|
361
|
+
async request2FACode(tempToken, method) {
|
|
362
|
+
const response = await this.request("auth", "request_2fa_code", "POST", {
|
|
363
|
+
temp_token: tempToken,
|
|
364
|
+
method
|
|
365
|
+
});
|
|
366
|
+
return { success: true, message: response.data?.message };
|
|
322
367
|
}
|
|
323
368
|
async logout() {
|
|
324
369
|
await this.request("auth", "logout", "POST");
|
|
@@ -331,6 +376,9 @@ var BibikeClient = class {
|
|
|
331
376
|
setToken(token) {
|
|
332
377
|
this.token = token;
|
|
333
378
|
}
|
|
379
|
+
getToken() {
|
|
380
|
+
return this.token;
|
|
381
|
+
}
|
|
334
382
|
// ============ Core Request Method ============
|
|
335
383
|
async request(resource, action, method = "GET", body, params) {
|
|
336
384
|
const url = new URL(this.baseUrl);
|