@edraj/tsdmart 1.0.15 → 1.0.17
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/CHANGELOG.md +1 -1
- package/README.md +2 -2
- package/a +2 -0
- package/index.ts +37 -31
- package/package.json +2 -2
- package/test.ts +46 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -4,8 +4,8 @@ A TypeScript implementation of the Dmart that depends on axios.
|
|
|
4
4
|
|
|
5
5
|
## APIs
|
|
6
6
|
|
|
7
|
-
* `login(shortname: string, password: string) -> Promise<
|
|
8
|
-
* `loginBy(credentials: dict, password: string) -> Promise<
|
|
7
|
+
* `login(shortname: string, password: string) -> Promise<LoginResponse>` - Performs a login action (shortname).
|
|
8
|
+
* `loginBy(credentials: dict, password: string) -> Promise<LoginResponse>` - Performs a login action but altering the default identifier that you can customise.
|
|
9
9
|
* `logout() -> Promise<ApiResponse>` - Performs a logout action.
|
|
10
10
|
* `create_user(request: any) -> Promise<ActionResponse>` - Creates a new user.
|
|
11
11
|
* `update_user(request: any) -> Promise<ActionResponse>` - Updates an existing user.
|
package/index.ts
CHANGED
|
@@ -49,7 +49,7 @@ export type LoginResponseRecord = ApiResponseRecord & {
|
|
|
49
49
|
};
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
type LoginResponse = ApiResponse & { records : Array<LoginResponseRecord> };
|
|
53
53
|
|
|
54
54
|
export type Permission = {
|
|
55
55
|
allowed_actions: Array<ActionType>;
|
|
@@ -94,9 +94,9 @@ export type ProfileResponse = ApiResponse & {
|
|
|
94
94
|
records: Array<ProfileResponseRecord>;
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
-
let headers: { [key: string]: string } = {
|
|
97
|
+
export let headers: { [key: string]: string } = {
|
|
98
98
|
"Content-type": "application/json",
|
|
99
|
-
|
|
99
|
+
"Authorization": ""
|
|
100
100
|
};
|
|
101
101
|
|
|
102
102
|
export type AggregationReducer = {
|
|
@@ -328,23 +328,29 @@ export default class Dmart {
|
|
|
328
328
|
|
|
329
329
|
public static async login(shortname: string, password: string) {
|
|
330
330
|
try {
|
|
331
|
-
const
|
|
332
|
-
|
|
333
|
-
|
|
331
|
+
const response = await axios.post<LoginResponse>(`${this.baseURL}/user/login`, {shortname, password}, {headers});
|
|
332
|
+
const data: LoginResponse = response.data;
|
|
333
|
+
if (data.status == Status.success && data.records.length > 0) {
|
|
334
|
+
headers['Authorization'] = "Bearer " + data.records[0].attributes.access_token;
|
|
335
|
+
}
|
|
334
336
|
return data;
|
|
335
337
|
} catch (error: any) {
|
|
336
|
-
throw
|
|
338
|
+
throw error.response.data
|
|
337
339
|
}
|
|
338
340
|
}
|
|
339
341
|
|
|
340
342
|
public static async loginBy(credentials: any, password: string) {
|
|
341
343
|
try {
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
344
|
+
const response = await axios.post<LoginResponse>(
|
|
345
|
+
`${this.baseURL}/user/login`, {...credentials, password}, {headers}
|
|
346
|
+
);
|
|
347
|
+
const data: LoginResponse = response.data;
|
|
348
|
+
if (data.status == Status.success && data.records.length > 0) {
|
|
349
|
+
headers['Authorization'] = "Bearer " + data.records[0].attributes.access_token;
|
|
350
|
+
}
|
|
345
351
|
return data;
|
|
346
352
|
} catch (error: any) {
|
|
347
|
-
throw
|
|
353
|
+
throw error.response.data
|
|
348
354
|
}
|
|
349
355
|
}
|
|
350
356
|
|
|
@@ -357,7 +363,7 @@ export default class Dmart {
|
|
|
357
363
|
);
|
|
358
364
|
return data;
|
|
359
365
|
} catch (error: any) {
|
|
360
|
-
throw
|
|
366
|
+
throw error.response.data
|
|
361
367
|
}
|
|
362
368
|
}
|
|
363
369
|
|
|
@@ -370,7 +376,7 @@ export default class Dmart {
|
|
|
370
376
|
);
|
|
371
377
|
return data;
|
|
372
378
|
} catch (error: any) {
|
|
373
|
-
throw
|
|
379
|
+
throw error.response.data
|
|
374
380
|
}
|
|
375
381
|
}
|
|
376
382
|
|
|
@@ -383,7 +389,7 @@ export default class Dmart {
|
|
|
383
389
|
);
|
|
384
390
|
return data;
|
|
385
391
|
} catch (error: any) {
|
|
386
|
-
throw
|
|
392
|
+
throw error.response.data
|
|
387
393
|
}
|
|
388
394
|
}
|
|
389
395
|
|
|
@@ -395,7 +401,7 @@ export default class Dmart {
|
|
|
395
401
|
);
|
|
396
402
|
return data;
|
|
397
403
|
} catch (error: any) {
|
|
398
|
-
throw
|
|
404
|
+
throw error.response.data
|
|
399
405
|
}
|
|
400
406
|
}
|
|
401
407
|
|
|
@@ -419,7 +425,7 @@ export default class Dmart {
|
|
|
419
425
|
}
|
|
420
426
|
return data;
|
|
421
427
|
} catch (error: any) {
|
|
422
|
-
throw
|
|
428
|
+
throw error.response.data
|
|
423
429
|
}
|
|
424
430
|
}
|
|
425
431
|
|
|
@@ -437,7 +443,7 @@ export default class Dmart {
|
|
|
437
443
|
);
|
|
438
444
|
return data;
|
|
439
445
|
} catch (error: any) {
|
|
440
|
-
throw
|
|
446
|
+
throw error.response.data
|
|
441
447
|
}
|
|
442
448
|
}
|
|
443
449
|
|
|
@@ -453,7 +459,7 @@ export default class Dmart {
|
|
|
453
459
|
);
|
|
454
460
|
return data;
|
|
455
461
|
} catch (error: any) {
|
|
456
|
-
throw
|
|
462
|
+
throw error.response.data
|
|
457
463
|
}
|
|
458
464
|
}
|
|
459
465
|
|
|
@@ -466,7 +472,7 @@ export default class Dmart {
|
|
|
466
472
|
);
|
|
467
473
|
return data;
|
|
468
474
|
} catch (error: any) {
|
|
469
|
-
throw
|
|
475
|
+
throw error.response.data
|
|
470
476
|
}
|
|
471
477
|
}
|
|
472
478
|
|
|
@@ -479,7 +485,7 @@ export default class Dmart {
|
|
|
479
485
|
);
|
|
480
486
|
return data;
|
|
481
487
|
} catch (error: any) {
|
|
482
|
-
throw
|
|
488
|
+
throw error.response.data
|
|
483
489
|
}
|
|
484
490
|
}
|
|
485
491
|
|
|
@@ -502,7 +508,7 @@ export default class Dmart {
|
|
|
502
508
|
);
|
|
503
509
|
return data;
|
|
504
510
|
} catch (error: any) {
|
|
505
|
-
throw
|
|
511
|
+
throw error.response.data
|
|
506
512
|
}
|
|
507
513
|
}
|
|
508
514
|
|
|
@@ -551,7 +557,7 @@ export default class Dmart {
|
|
|
551
557
|
|
|
552
558
|
return data;
|
|
553
559
|
} catch (error: any) {
|
|
554
|
-
throw
|
|
560
|
+
throw error.response.data
|
|
555
561
|
}
|
|
556
562
|
}
|
|
557
563
|
|
|
@@ -584,7 +590,7 @@ export default class Dmart {
|
|
|
584
590
|
);
|
|
585
591
|
return data;
|
|
586
592
|
} catch (error: any) {
|
|
587
|
-
throw
|
|
593
|
+
throw error.response.data
|
|
588
594
|
}
|
|
589
595
|
}
|
|
590
596
|
|
|
@@ -641,7 +647,7 @@ export default class Dmart {
|
|
|
641
647
|
>(`${this.baseURL}/managed/health/${space_name}`, {headers});
|
|
642
648
|
return data;
|
|
643
649
|
} catch (error: any) {
|
|
644
|
-
throw
|
|
650
|
+
throw error.response.data
|
|
645
651
|
}
|
|
646
652
|
}
|
|
647
653
|
|
|
@@ -659,7 +665,7 @@ export default class Dmart {
|
|
|
659
665
|
);
|
|
660
666
|
return data;
|
|
661
667
|
} catch (error: any) {
|
|
662
|
-
throw
|
|
668
|
+
throw error.response.data
|
|
663
669
|
}
|
|
664
670
|
}
|
|
665
671
|
|
|
@@ -678,7 +684,7 @@ export default class Dmart {
|
|
|
678
684
|
);
|
|
679
685
|
return data;
|
|
680
686
|
} catch (error: any) {
|
|
681
|
-
throw
|
|
687
|
+
throw error.response.data
|
|
682
688
|
}
|
|
683
689
|
}
|
|
684
690
|
|
|
@@ -697,7 +703,7 @@ export default class Dmart {
|
|
|
697
703
|
);
|
|
698
704
|
return data;
|
|
699
705
|
}catch (error: any) {
|
|
700
|
-
throw
|
|
706
|
+
throw error.response.data
|
|
701
707
|
}
|
|
702
708
|
}
|
|
703
709
|
|
|
@@ -726,7 +732,7 @@ export default class Dmart {
|
|
|
726
732
|
);
|
|
727
733
|
return data;
|
|
728
734
|
} catch (error: any) {
|
|
729
|
-
throw
|
|
735
|
+
throw error.response.data
|
|
730
736
|
}
|
|
731
737
|
}
|
|
732
738
|
|
|
@@ -744,7 +750,7 @@ export default class Dmart {
|
|
|
744
750
|
);
|
|
745
751
|
return data;
|
|
746
752
|
} catch (error: any) {
|
|
747
|
-
throw
|
|
753
|
+
throw error.response.data
|
|
748
754
|
}
|
|
749
755
|
}
|
|
750
756
|
|
|
@@ -755,7 +761,7 @@ export default class Dmart {
|
|
|
755
761
|
});
|
|
756
762
|
return data;
|
|
757
763
|
} catch (error: any) {
|
|
758
|
-
throw
|
|
764
|
+
throw error.response.data
|
|
759
765
|
}
|
|
760
766
|
}
|
|
761
767
|
|
|
@@ -766,7 +772,7 @@ export default class Dmart {
|
|
|
766
772
|
});
|
|
767
773
|
return data;
|
|
768
774
|
} catch (error: any) {
|
|
769
|
-
throw
|
|
775
|
+
throw error.response.data
|
|
770
776
|
}
|
|
771
777
|
}
|
|
772
778
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edraj/tsdmart",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
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",
|
|
@@ -21,6 +21,6 @@
|
|
|
21
21
|
"typescript": "^5.4.2"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"axios": "^1.
|
|
24
|
+
"axios": "^1.9.0"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/test.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import Dmart from "./index";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Dmart.baseURL = 'http://localhost:8282';
|
|
5
|
+
|
|
6
|
+
const r = await Dmart.login('dmart', 'Test1234')
|
|
7
|
+
console.log({r});
|
|
8
|
+
const request:any = {
|
|
9
|
+
space_name: "management",
|
|
10
|
+
request_type: "update",
|
|
11
|
+
records: [
|
|
12
|
+
{
|
|
13
|
+
resource_type: "user",
|
|
14
|
+
shortname: "zainebfrontend",
|
|
15
|
+
subpath: "/users",
|
|
16
|
+
attributes: {
|
|
17
|
+
description: {
|
|
18
|
+
ar: "desc ar",
|
|
19
|
+
en: "HelloWorld en",
|
|
20
|
+
ku: "desc ku"
|
|
21
|
+
},
|
|
22
|
+
displayname: {
|
|
23
|
+
ar: "name ar",
|
|
24
|
+
en: "myName en",
|
|
25
|
+
ku: "name ku"
|
|
26
|
+
},
|
|
27
|
+
is_active: true,
|
|
28
|
+
invitation: "",
|
|
29
|
+
payload: {
|
|
30
|
+
body: {
|
|
31
|
+
email: "zainebb@gmail.com",
|
|
32
|
+
first_name: "Jo",
|
|
33
|
+
last_name: "Do",
|
|
34
|
+
mobile: "792211703",
|
|
35
|
+
language: "english"
|
|
36
|
+
},
|
|
37
|
+
content_type: "json",
|
|
38
|
+
// schema_shortname: "user"
|
|
39
|
+
},
|
|
40
|
+
tags: []
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
};
|
|
45
|
+
const u = await Dmart.request(request);
|
|
46
|
+
console.log({u});
|