@bibike/erp-sdk 1.0.0 → 1.1.0

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 CHANGED
@@ -29,14 +29,37 @@ interface DateRangeParams {
29
29
  [key: string]: string | number | boolean | undefined;
30
30
  }
31
31
  interface LoginCredentials {
32
- email: string;
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
- login(credentials: LoginCredentials): Promise<AuthResponse>;
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
- email: string;
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
- login(credentials: LoginCredentials): Promise<AuthResponse>;
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,55 @@ 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", credentials);
348
+ const response = await this.request("auth", "login", "POST", {
349
+ login: credentials.login,
350
+ password: credentials.password,
351
+ two_factor_code: credentials.two_factor_code
352
+ });
353
+ const rawResponse = response;
354
+ if (rawResponse.requires_2fa) {
355
+ return {
356
+ success: false,
357
+ requires_2fa: true,
358
+ temp_token: rawResponse.temp_token,
359
+ methods: rawResponse.methods
360
+ };
361
+ }
345
362
  if (response.data?.token) {
346
363
  this.token = response.data.token;
347
364
  }
348
- return response.data;
365
+ return {
366
+ success: true,
367
+ data: response.data
368
+ };
369
+ }
370
+ /**
371
+ * Verify 2FA code after initial login
372
+ */
373
+ async verify2FA(input) {
374
+ const response = await this.request("auth", "verify_2fa", "POST", input);
375
+ if (response.data?.token) {
376
+ this.token = response.data.token;
377
+ }
378
+ return {
379
+ success: true,
380
+ data: response.data
381
+ };
382
+ }
383
+ /**
384
+ * Request 2FA code via specific method (SMS/email)
385
+ */
386
+ async request2FACode(tempToken, method) {
387
+ const response = await this.request("auth", "request_2fa_code", "POST", {
388
+ temp_token: tempToken,
389
+ method
390
+ });
391
+ return { success: true, message: response.data?.message };
349
392
  }
350
393
  async logout() {
351
394
  await this.request("auth", "logout", "POST");
@@ -358,6 +401,9 @@ var BibikeClient = class {
358
401
  setToken(token) {
359
402
  this.token = token;
360
403
  }
404
+ getToken() {
405
+ return this.token;
406
+ }
361
407
  // ============ Core Request Method ============
362
408
  async request(resource, action, method = "GET", body, params) {
363
409
  const url = new URL(this.baseUrl);
package/dist/index.mjs CHANGED
@@ -313,12 +313,55 @@ 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", credentials);
321
+ const response = await this.request("auth", "login", "POST", {
322
+ login: credentials.login,
323
+ password: credentials.password,
324
+ two_factor_code: credentials.two_factor_code
325
+ });
326
+ const rawResponse = response;
327
+ if (rawResponse.requires_2fa) {
328
+ return {
329
+ success: false,
330
+ requires_2fa: true,
331
+ temp_token: rawResponse.temp_token,
332
+ methods: rawResponse.methods
333
+ };
334
+ }
318
335
  if (response.data?.token) {
319
336
  this.token = response.data.token;
320
337
  }
321
- return response.data;
338
+ return {
339
+ success: true,
340
+ data: response.data
341
+ };
342
+ }
343
+ /**
344
+ * Verify 2FA code after initial login
345
+ */
346
+ async verify2FA(input) {
347
+ const response = await this.request("auth", "verify_2fa", "POST", input);
348
+ if (response.data?.token) {
349
+ this.token = response.data.token;
350
+ }
351
+ return {
352
+ success: true,
353
+ data: response.data
354
+ };
355
+ }
356
+ /**
357
+ * Request 2FA code via specific method (SMS/email)
358
+ */
359
+ async request2FACode(tempToken, method) {
360
+ const response = await this.request("auth", "request_2fa_code", "POST", {
361
+ temp_token: tempToken,
362
+ method
363
+ });
364
+ return { success: true, message: response.data?.message };
322
365
  }
323
366
  async logout() {
324
367
  await this.request("auth", "logout", "POST");
@@ -331,6 +374,9 @@ var BibikeClient = class {
331
374
  setToken(token) {
332
375
  this.token = token;
333
376
  }
377
+ getToken() {
378
+ return this.token;
379
+ }
334
380
  // ============ Core Request Method ============
335
381
  async request(resource, action, method = "GET", body, params) {
336
382
  const url = new URL(this.baseUrl);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bibike/erp-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "TypeScript SDK for Bibike ERP API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",