@edraj/tsdmart 2.7.1 → 3.0.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 +6 -0
- package/dmart.model.ts +15 -0
- package/dmart.service.ts +113 -18
- package/package.json +1 -1
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
|
@@ -4,14 +4,16 @@ import {
|
|
|
4
4
|
ActionResponse,
|
|
5
5
|
ApiQueryResponse,
|
|
6
6
|
ApiResponse,
|
|
7
|
-
|
|
7
|
+
ConfirmOTPRequest,
|
|
8
8
|
headers,
|
|
9
9
|
LoginResponse,
|
|
10
|
+
PasswordResetRequest,
|
|
10
11
|
ProfileResponse,
|
|
11
12
|
QueryRequest,
|
|
12
13
|
QueryType,
|
|
13
14
|
ResourceType,
|
|
14
15
|
ResponseEntry,
|
|
16
|
+
SendOTPRequest,
|
|
15
17
|
SortyType,
|
|
16
18
|
Status,
|
|
17
19
|
} from "./dmart.model";
|
|
@@ -272,29 +274,28 @@ export class Dmart {
|
|
|
272
274
|
}
|
|
273
275
|
|
|
274
276
|
|
|
275
|
-
|
|
276
277
|
public static async upload_with_payload(
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
): Promise<ApiResponse> {
|
|
278
|
+
space_name: string,
|
|
279
|
+
subpath: string,
|
|
280
|
+
shortname: string,
|
|
281
|
+
resource_type: ResourceType,
|
|
282
|
+
payload_file: File,
|
|
283
|
+
attributes?: Record<string, any>|null,
|
|
284
|
+
scope: string = "managed"
|
|
285
|
+
) {
|
|
286
286
|
const request_record_body: any = {
|
|
287
287
|
resource_type,
|
|
288
288
|
subpath,
|
|
289
289
|
shortname,
|
|
290
|
-
attributes:
|
|
290
|
+
attributes: attributes,
|
|
291
291
|
};
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
292
|
+
|
|
293
|
+
if (attributes !== null && Object.keys(attributes!).length === 0) {
|
|
294
|
+
request_record_body.attributes = {is_active: true, payload: { body: {} }};
|
|
295
|
+
} else {
|
|
296
|
+
if(!Object.keys(attributes!).includes('is_active')){
|
|
297
|
+
request_record_body.attributes.is_active = true;
|
|
298
|
+
}
|
|
298
299
|
}
|
|
299
300
|
|
|
300
301
|
const request_record = new Blob([JSON.stringify(request_record_body)], {
|
|
@@ -510,4 +511,98 @@ export class Dmart {
|
|
|
510
511
|
throw error;
|
|
511
512
|
}
|
|
512
513
|
}
|
|
514
|
+
|
|
515
|
+
public static async otp_request(
|
|
516
|
+
request: SendOTPRequest,
|
|
517
|
+
acceptLanguage: string | null = null
|
|
518
|
+
) {
|
|
519
|
+
try {
|
|
520
|
+
const requestHeaders = { ...headers };
|
|
521
|
+
if (acceptLanguage) {
|
|
522
|
+
requestHeaders['Accept-Language'] = acceptLanguage;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
const { data } = await Dmart.axiosDmartInstance.post<ApiResponse>(
|
|
526
|
+
`user/otp-request`,
|
|
527
|
+
request,
|
|
528
|
+
{ headers: requestHeaders }
|
|
529
|
+
);
|
|
530
|
+
return data;
|
|
531
|
+
} catch (error: any) {
|
|
532
|
+
throw error;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
public static async otp_request_login(
|
|
537
|
+
request: SendOTPRequest,
|
|
538
|
+
acceptLanguage: string | null = null
|
|
539
|
+
) {
|
|
540
|
+
try {
|
|
541
|
+
const requestHeaders = { ...headers };
|
|
542
|
+
if (acceptLanguage) {
|
|
543
|
+
requestHeaders['Accept-Language'] = acceptLanguage;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
const { data } = await Dmart.axiosDmartInstance.post<ApiResponse>(
|
|
547
|
+
`user/otp-request-login`,
|
|
548
|
+
request,
|
|
549
|
+
{ headers: requestHeaders }
|
|
550
|
+
);
|
|
551
|
+
return data;
|
|
552
|
+
} catch (error: any) {
|
|
553
|
+
throw error;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
public static async password_reset_request(request: PasswordResetRequest) {
|
|
558
|
+
try {
|
|
559
|
+
const { data } = await Dmart.axiosDmartInstance.post<ApiResponse>(
|
|
560
|
+
`user/password-reset-request`,
|
|
561
|
+
request,
|
|
562
|
+
{ headers }
|
|
563
|
+
);
|
|
564
|
+
return data;
|
|
565
|
+
} catch (error: any) {
|
|
566
|
+
throw error;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
public static async confirm_otp(request: ConfirmOTPRequest) {
|
|
571
|
+
try {
|
|
572
|
+
const { data } = await Dmart.axiosDmartInstance.post<ApiResponse>(
|
|
573
|
+
`user/otp-confirm`,
|
|
574
|
+
request,
|
|
575
|
+
{ headers }
|
|
576
|
+
);
|
|
577
|
+
return data;
|
|
578
|
+
} catch (error: any) {
|
|
579
|
+
throw error;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
public static async user_reset(shortname: string) {
|
|
584
|
+
try {
|
|
585
|
+
const { data } = await Dmart.axiosDmartInstance.post<ApiResponse>(
|
|
586
|
+
`user/reset`,
|
|
587
|
+
{ shortname },
|
|
588
|
+
{ headers }
|
|
589
|
+
);
|
|
590
|
+
return data;
|
|
591
|
+
} catch (error: any) {
|
|
592
|
+
throw error;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
public static async validate_password(password: string) {
|
|
597
|
+
try {
|
|
598
|
+
const { data } = await Dmart.axiosDmartInstance.post<ApiResponse>(
|
|
599
|
+
`user/validate_password`,
|
|
600
|
+
{ password },
|
|
601
|
+
{ headers }
|
|
602
|
+
);
|
|
603
|
+
return data;
|
|
604
|
+
} catch (error: any) {
|
|
605
|
+
throw error;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
513
608
|
}
|