@edraj/tsdmart 2.7.0 → 2.8.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/README.md CHANGED
@@ -19,6 +19,12 @@ make sure you define `axiosDmartInstance` with your axios instance before import
19
19
  * `login(shortname: string, password: string) -> Promise<LoginResponse>` - Performs a login action (shortname).
20
20
  * `loginBy(credentials: dict, password: string) -> Promise<LoginResponse>` - Performs a login action but altering the default identifier that you can customise.
21
21
  * `logout() -> Promise<ApiResponse>` - Performs a logout action.
22
+ * `otp_request(request: SendOTPRequest,acceptLanguage: string | null = null) -> Promise<ApiResponse | null>` - Requests an OTP (One Time Password) for login.
23
+ * `otp_request_login(request: SendOTPRequest,acceptLanguage: string | null = null) -> Promise<ApiResponse | null>` - Requests an OTP for login and returns a login response.
24
+ * `password_reset_request(request: PasswordResetRequest) -> Promise<ApiResponse | null>` - Requests a password reset.
25
+ * `confirm_otp(request: ConfirmOTPRequest) -> Promise<ApiResponse | null>` - Confirms the OTP (One Time Password) for login or password reset.
26
+ * `user_reset(shortname: string) -> Promise<ApiResponse | null>` - Resets the user password by sending an OTP to the user's email.
27
+ * `validate_password(password: string) -> Promise<ApiResponse | null>` - Validates the password.
22
28
  * `create_user(request: any) -> Promise<ActionResponse>` - Creates a new user.
23
29
  * `update_user(request: any) -> Promise<ActionResponse>` - Updates an existing user.
24
30
  * `check_existing(prop: string, value: string) -> Promise<ResponseEntry | null>` - Checks if a user exists.
package/dmart.model.ts CHANGED
@@ -47,6 +47,21 @@ export enum UserType {
47
47
  bot = "bot",
48
48
  }
49
49
 
50
+ export interface SendOTPRequest {
51
+ msisdn?: string;
52
+ email?: string;
53
+ }
54
+
55
+ export interface PasswordResetRequest {
56
+ msisdn?: string;
57
+ shortname?: string;
58
+ email?: string;
59
+ }
60
+
61
+ export interface ConfirmOTPRequest {
62
+ code: string
63
+ }
64
+
50
65
  export type LoginResponseRecord = ApiResponseRecord & {
51
66
  attributes: {
52
67
  access_token: string;
package/dmart.service.ts CHANGED
@@ -1,19 +1,22 @@
1
1
  import {AxiosInstance} from "axios";
2
2
  import {
3
- ActionRequest,
4
- ActionResponse,
5
- ApiQueryResponse,
6
- ApiResponse,
7
- ContentType,
8
- headers,
9
- LoginResponse,
10
- ProfileResponse,
11
- QueryRequest,
12
- QueryType,
13
- ResourceType,
14
- ResponseEntry,
15
- SortyType,
16
- Status,
3
+ ActionRequest, ActionRequestRecord,
4
+ ActionResponse,
5
+ ApiQueryResponse,
6
+ ApiResponse,
7
+ ConfirmOTPRequest,
8
+ ContentType,
9
+ headers,
10
+ LoginResponse,
11
+ PasswordResetRequest,
12
+ ProfileResponse,
13
+ QueryRequest,
14
+ QueryType,
15
+ ResourceType,
16
+ ResponseEntry,
17
+ SendOTPRequest,
18
+ SortyType,
19
+ Status,
17
20
  } from "./dmart.model";
18
21
 
19
22
 
@@ -100,7 +103,7 @@ export class Dmart {
100
103
  }
101
104
  }
102
105
 
103
- public static async create_user(request: any) {
106
+ public static async create_user(request: ActionRequestRecord) {
104
107
  try {
105
108
  const { data } = await Dmart.axiosDmartInstance.post<ActionResponse>(
106
109
  `user/create`,
@@ -113,7 +116,7 @@ export class Dmart {
113
116
  }
114
117
  }
115
118
 
116
- public static async update_user(request: any) {
119
+ public static async update_user(request: ActionRequestRecord) {
117
120
  try {
118
121
  const { data } = await Dmart.axiosDmartInstance.post<ActionResponse>(
119
122
  `user/profile`,
@@ -510,4 +513,98 @@ export class Dmart {
510
513
  throw error;
511
514
  }
512
515
  }
516
+
517
+ public static async otp_request(
518
+ request: SendOTPRequest,
519
+ acceptLanguage: string | null = null
520
+ ) {
521
+ try {
522
+ const requestHeaders = { ...headers };
523
+ if (acceptLanguage) {
524
+ requestHeaders['Accept-Language'] = acceptLanguage;
525
+ }
526
+
527
+ const { data } = await Dmart.axiosDmartInstance.post<ApiResponse>(
528
+ `user/otp-request`,
529
+ request,
530
+ { headers: requestHeaders }
531
+ );
532
+ return data;
533
+ } catch (error: any) {
534
+ throw error;
535
+ }
536
+ }
537
+
538
+ public static async otp_request_login(
539
+ request: SendOTPRequest,
540
+ acceptLanguage: string | null = null
541
+ ) {
542
+ try {
543
+ const requestHeaders = { ...headers };
544
+ if (acceptLanguage) {
545
+ requestHeaders['Accept-Language'] = acceptLanguage;
546
+ }
547
+
548
+ const { data } = await Dmart.axiosDmartInstance.post<ApiResponse>(
549
+ `user/otp-request-login`,
550
+ request,
551
+ { headers: requestHeaders }
552
+ );
553
+ return data;
554
+ } catch (error: any) {
555
+ throw error;
556
+ }
557
+ }
558
+
559
+ public static async password_reset_request(request: PasswordResetRequest) {
560
+ try {
561
+ const { data } = await Dmart.axiosDmartInstance.post<ApiResponse>(
562
+ `user/password-reset-request`,
563
+ request,
564
+ { headers }
565
+ );
566
+ return data;
567
+ } catch (error: any) {
568
+ throw error;
569
+ }
570
+ }
571
+
572
+ public static async confirm_otp(request: ConfirmOTPRequest) {
573
+ try {
574
+ const { data } = await Dmart.axiosDmartInstance.post<ApiResponse>(
575
+ `user/otp-confirm`,
576
+ request,
577
+ { headers }
578
+ );
579
+ return data;
580
+ } catch (error: any) {
581
+ throw error;
582
+ }
583
+ }
584
+
585
+ public static async user_reset(shortname: string) {
586
+ try {
587
+ const { data } = await Dmart.axiosDmartInstance.post<ApiResponse>(
588
+ `user/reset`,
589
+ { shortname },
590
+ { headers }
591
+ );
592
+ return data;
593
+ } catch (error: any) {
594
+ throw error;
595
+ }
596
+ }
597
+
598
+ public static async validate_password(password: string) {
599
+ try {
600
+ const { data } = await Dmart.axiosDmartInstance.post<ApiResponse>(
601
+ `user/validate_password`,
602
+ { password },
603
+ { headers }
604
+ );
605
+ return data;
606
+ } catch (error: any) {
607
+ throw error;
608
+ }
609
+ }
513
610
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edraj/tsdmart",
3
- "version": "2.7.0",
3
+ "version": "2.8.0",
4
4
  "description": "A TypeScript implementation of the Dmart that depends on axios.",
5
5
  "author": "Kefah T. Issa",
6
6
  "email": "kefah.issa@gmail.com",