@edraj/tsdmart 1.0.16 → 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 +15 -9
- 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,9 +328,11 @@ 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
338
|
throw error.response.data
|
|
@@ -339,9 +341,13 @@ export default class Dmart {
|
|
|
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
353
|
throw error.response.data
|
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});
|