@edraj/tsdmart 4.0.0 → 4.0.2
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 +187 -24
- package/dmart.service.ts +8 -8
- package/package.json +1 -1
- package/test.ts +21 -21
package/README.md
CHANGED
|
@@ -19,31 +19,194 @@ 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
|
-
* `
|
|
23
|
-
* `
|
|
24
|
-
* `
|
|
25
|
-
* `
|
|
26
|
-
* `
|
|
27
|
-
* `
|
|
28
|
-
* `
|
|
29
|
-
* `
|
|
30
|
-
* `
|
|
31
|
-
* `
|
|
22
|
+
* `otpRequest(request: SendOTPRequest, acceptLanguage: string | null = null) -> Promise<ApiResponse>` - Requests an OTP (One Time Password) for login.
|
|
23
|
+
* `otpRequestLogin(request: SendOTPRequest, acceptLanguage: string | null = null) -> Promise<ApiResponse>` - Requests an OTP for login and returns a login response.
|
|
24
|
+
* `passwordResetRequest(request: PasswordResetRequest) -> Promise<ApiResponse>` - Requests a password reset.
|
|
25
|
+
* `confirmOtp(request: ConfirmOTPRequest) -> Promise<ApiResponse>` - Confirms the OTP (One Time Password) for login or password reset.
|
|
26
|
+
* `userReset(shortname: string) -> Promise<ApiResponse>` - Resets the user password by sending an OTP to the user's email.
|
|
27
|
+
* `validatePassword(password: string) -> Promise<ApiResponse>` - Validates the password.
|
|
28
|
+
* `createUser(request: ActionRequestRecord) -> Promise<ActionResponse>` - Creates a new user.
|
|
29
|
+
* `updateUser(request: ActionRequestRecord) -> Promise<ActionResponse>` - Updates an existing user.
|
|
30
|
+
* `checkExisting(prop: string, value: string) -> Promise<ResponseEntry>` - Checks if a user exists.
|
|
31
|
+
* `getProfile() -> Promise<ProfileResponse>` - Gets the profile of the current user.
|
|
32
32
|
* `query(query: QueryRequest) -> Promise<ApiQueryResponse | null>` - Performs a query action.
|
|
33
33
|
* `csv(query: any) -> Promise<ApiQueryResponse>` - Query the entries as csv file.
|
|
34
34
|
* `space(action: ActionRequest) -> Promise<ActionResponse>` - Performs actions on spaces.
|
|
35
35
|
* `request(action: ActionRequest) -> Promise<ActionResponse>` - Performs a request action.
|
|
36
|
-
* `
|
|
37
|
-
* `
|
|
38
|
-
* `fetchDataAsset(
|
|
39
|
-
* `
|
|
40
|
-
* `
|
|
41
|
-
* `
|
|
42
|
-
* `
|
|
43
|
-
* `
|
|
44
|
-
* `
|
|
45
|
-
* `
|
|
46
|
-
* `
|
|
47
|
-
* `
|
|
48
|
-
|
|
49
|
-
|
|
36
|
+
* `retrieveEntry(request: RetrieveEntryRequest, scope: string = "managed") -> Promise<ResponseEntry | null>` - Performs a retrieve action.
|
|
37
|
+
* `uploadWithPayload(request: UploadWithPayloadRequest, scope: string = "managed") -> Promise<ApiResponse>` - Uploads a file with a payload.
|
|
38
|
+
* `fetchDataAsset(request: FetchDataAssetRequest) -> Promise<any>` - Fetches a data asset.
|
|
39
|
+
* `getSpaces() -> Promise<ApiResponse | null>` - Gets the spaces (user query).
|
|
40
|
+
* `getChildren(request: GetChildrenRequest) -> Promise<ApiResponse | null>` - Gets the children of a space (user query).
|
|
41
|
+
* `getAttachmentUrl(request: GetAttachmentURLRequest, scope: string = "managed") -> string` - Constructs the URL of an attachment.
|
|
42
|
+
* `getSpaceHealth(space_name: string) -> Promise<ApiQueryResponse & { attributes: { folders_report: Object } }>` - Gets the health check of a space.
|
|
43
|
+
* `getPayload(request: GetPayloadRequest, scope: string = "managed") -> Promise<any>` - Gets the payload of a resource.
|
|
44
|
+
* `progressTicket(request: ProgressTicketRequest) -> Promise<ApiQueryResponse & { attributes: { folders_report: Object } }>` - Performs a progress ticket action.
|
|
45
|
+
* `submit(request: SubmitRequest) -> Promise<any>` - Submits a record (log/feedback) to Dmart.
|
|
46
|
+
* `getManifest() -> Promise<any>` - Gets the manifest of the current instance.
|
|
47
|
+
* `getSettings() -> Promise<any>` - Gets the settings of the current instance.
|
|
48
|
+
|
|
49
|
+
# Usage
|
|
50
|
+
|
|
51
|
+
* Initialize the Dmart instance:
|
|
52
|
+
```js
|
|
53
|
+
export const dmartAxios = axios.create({
|
|
54
|
+
baseURL: backendURL,
|
|
55
|
+
withCredentials: true,
|
|
56
|
+
});
|
|
57
|
+
Dmart.setAxiosInstance(dmartAxios);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Manage user
|
|
61
|
+
|
|
62
|
+
* Create user
|
|
63
|
+
```ts
|
|
64
|
+
const createUserRequest: ActionRequest = {
|
|
65
|
+
space_name: 'users',
|
|
66
|
+
request_type: RequestType.create,
|
|
67
|
+
records: [
|
|
68
|
+
{
|
|
69
|
+
resource_type: ResourceType.user,
|
|
70
|
+
shortname: 'john_doe', // auto: for auto-generated shortname
|
|
71
|
+
attributes: {
|
|
72
|
+
password: 'my-password',
|
|
73
|
+
is_active: true,
|
|
74
|
+
// email, msisdn, displayname are optional
|
|
75
|
+
email: 'john_doe@example.com',
|
|
76
|
+
msisdn: '1234567890',
|
|
77
|
+
password: 'securePassword123',
|
|
78
|
+
displayname: {en: 'John Doe'},
|
|
79
|
+
// roles is optional
|
|
80
|
+
roles: ['store_manager'],
|
|
81
|
+
// is_msisdn_verified, is_email_verified are optional
|
|
82
|
+
is_msisdn_verified: true,
|
|
83
|
+
is_email_verified: true,
|
|
84
|
+
// is force_password_change is optional
|
|
85
|
+
is_force_password_change: false,
|
|
86
|
+
// payload is optional
|
|
87
|
+
payload: {
|
|
88
|
+
content_type: 'json',
|
|
89
|
+
body: {
|
|
90
|
+
additional_info: 'This is some additional information about the user.'
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const response = await Dmart.createUser(createUserRequest.records[0]);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
* Login with credentials
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
const response = await Dmart.login('john_doe', 'securePassword123');
|
|
105
|
+
|
|
106
|
+
loginBy({email: 'john_doe@example.com'}, 'securePassword123');
|
|
107
|
+
|
|
108
|
+
loginBy({msisdn: '1234567890'}, 'securePassword123');
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
* Get user profile
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
const profileResponse = await Dmart.getProfile();
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
* Update user
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
const updateUserRequest: ActionRequest = {
|
|
121
|
+
space_name: 'users',
|
|
122
|
+
request_type: RequestType.update,
|
|
123
|
+
records: [
|
|
124
|
+
{
|
|
125
|
+
resource_type: ResourceType.user,
|
|
126
|
+
shortname: 'john_doe',
|
|
127
|
+
attributes: {
|
|
128
|
+
payload: {
|
|
129
|
+
content_type: 'json',
|
|
130
|
+
body: {
|
|
131
|
+
'rotation': 'bi-weekly'
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const response = await Dmart.updateUser(updateUserRequest.records[0]);
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Managing entries
|
|
143
|
+
|
|
144
|
+
* Create entry
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
const createRequest: ActionRequest = {
|
|
148
|
+
space_name: 'test_space',
|
|
149
|
+
request_type: RequestType.create,
|
|
150
|
+
records: [
|
|
151
|
+
{
|
|
152
|
+
resource_type: ResourceType.content,
|
|
153
|
+
subpath: '/dummies',
|
|
154
|
+
shortname: 'dummy_001',
|
|
155
|
+
attributes: {
|
|
156
|
+
payload: {
|
|
157
|
+
content_type: 'json',
|
|
158
|
+
body: {
|
|
159
|
+
title: 'Test Dummy Entry',
|
|
160
|
+
description: 'This is a test dummy entry',
|
|
161
|
+
status: 'active'
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
]
|
|
167
|
+
};
|
|
168
|
+
const response = await Dmart.request(createRequest);
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
* Update entry
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
const updateRequest: ActionRequest = {
|
|
175
|
+
space_name: 'test_space',
|
|
176
|
+
request_type: RequestType.update,
|
|
177
|
+
records: [
|
|
178
|
+
{
|
|
179
|
+
resource_type: ResourceType.content,
|
|
180
|
+
subpath: '/dummies',
|
|
181
|
+
shortname: 'dummy_001',
|
|
182
|
+
attributes: {
|
|
183
|
+
payload: {
|
|
184
|
+
content_type: 'json',
|
|
185
|
+
body: {
|
|
186
|
+
status: 'unactive'
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
]
|
|
192
|
+
};
|
|
193
|
+
const response = await Dmart.request(createRequest);
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
* Delete entry
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
const deleteRequest: ActionRequest = {
|
|
200
|
+
space_name: 'test_space',
|
|
201
|
+
request_type: RequestType.delete,
|
|
202
|
+
records: [
|
|
203
|
+
{
|
|
204
|
+
resource_type: ResourceType.content,
|
|
205
|
+
subpath: '/dummies',
|
|
206
|
+
shortname: 'dummy_001',
|
|
207
|
+
attributes: {}
|
|
208
|
+
}
|
|
209
|
+
]
|
|
210
|
+
};
|
|
211
|
+
const response = await Dmart.request(createRequest);
|
|
212
|
+
```
|
package/dmart.service.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
ActionResponse,
|
|
6
6
|
ApiQueryResponse,
|
|
7
7
|
ApiResponse,
|
|
8
|
-
ConfirmOTPRequest,
|
|
8
|
+
ConfirmOTPRequest, DmartScope,
|
|
9
9
|
FetchDataAssetRequest,
|
|
10
10
|
GetAttachmentURLRequest,
|
|
11
11
|
GetChildrenRequest,
|
|
@@ -170,7 +170,7 @@ export class Dmart {
|
|
|
170
170
|
|
|
171
171
|
public static async query(
|
|
172
172
|
query: QueryRequest,
|
|
173
|
-
scope: string =
|
|
173
|
+
scope: string = DmartScope.managed
|
|
174
174
|
): Promise<ApiQueryResponse | null> {
|
|
175
175
|
try {
|
|
176
176
|
if (query.type != QueryType.spaces) {
|
|
@@ -255,7 +255,7 @@ export class Dmart {
|
|
|
255
255
|
|
|
256
256
|
public static async retrieveEntry(
|
|
257
257
|
request: RetrieveEntryRequest,
|
|
258
|
-
scope: string =
|
|
258
|
+
scope: string = DmartScope.managed
|
|
259
259
|
): Promise<ResponseEntry | null> {
|
|
260
260
|
try {
|
|
261
261
|
if (request.validate_schema === null) {
|
|
@@ -276,7 +276,7 @@ export class Dmart {
|
|
|
276
276
|
|
|
277
277
|
public static async uploadWithPayload(
|
|
278
278
|
request: UploadWithPayloadRequest,
|
|
279
|
-
scope: string =
|
|
279
|
+
scope: string = DmartScope.managed
|
|
280
280
|
) {
|
|
281
281
|
const request_record_body: any = {
|
|
282
282
|
resource_type: request.resource_type,
|
|
@@ -376,7 +376,7 @@ export class Dmart {
|
|
|
376
376
|
|
|
377
377
|
public static getAttachmentUrl(
|
|
378
378
|
request: GetAttachmentURLRequest,
|
|
379
|
-
scope: string =
|
|
379
|
+
scope: string = DmartScope.managed
|
|
380
380
|
) {
|
|
381
381
|
return `${Dmart.axiosDmartInstance.defaults.baseURL}/${scope}/payload/${request.resource_type}/${request.space_name}/${request.subpath.replace(
|
|
382
382
|
/\/+$/,
|
|
@@ -397,7 +397,7 @@ export class Dmart {
|
|
|
397
397
|
|
|
398
398
|
public static async getPayload(
|
|
399
399
|
request: GetPayloadRequest,
|
|
400
|
-
scope: string =
|
|
400
|
+
scope: string = DmartScope.managed
|
|
401
401
|
) {
|
|
402
402
|
try {
|
|
403
403
|
let url = `${scope}/payload/${request.resource_type}/${request.space_name}/${request.subpath}/${request.shortname}`;
|
|
@@ -463,7 +463,7 @@ export class Dmart {
|
|
|
463
463
|
}
|
|
464
464
|
}
|
|
465
465
|
|
|
466
|
-
public static async
|
|
466
|
+
public static async getManifest() {
|
|
467
467
|
try {
|
|
468
468
|
const {data} = await Dmart.axiosDmartInstance.get<any>(`info/manifest`, {
|
|
469
469
|
headers,
|
|
@@ -474,7 +474,7 @@ export class Dmart {
|
|
|
474
474
|
}
|
|
475
475
|
}
|
|
476
476
|
|
|
477
|
-
public static async
|
|
477
|
+
public static async getSettings() {
|
|
478
478
|
try {
|
|
479
479
|
const {data} = await Dmart.axiosDmartInstance.get<any>(`info/settings`, {
|
|
480
480
|
headers,
|
package/package.json
CHANGED
package/test.ts
CHANGED
|
@@ -45,26 +45,26 @@
|
|
|
45
45
|
// const u = await Dmart.request(request);
|
|
46
46
|
// console.log({u});
|
|
47
47
|
|
|
48
|
-
import {Dmart, dmartClient} from "./dmart.service";
|
|
49
|
-
import {ContentType, ResourceType} from "./dmart.model";
|
|
50
|
-
import * as fs from "node:fs";
|
|
51
|
-
|
|
52
|
-
dmartClient.defaults.baseURL = 'https://nova.imx.sh/dmart';
|
|
53
|
-
|
|
54
|
-
Dmart.login('dmart', 'NdFVYdcsoo1M5u08').then(r => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
});
|
|
48
|
+
// import {Dmart, dmartClient} from "./dmart.service";
|
|
49
|
+
// import {ContentType, ResourceType} from "./dmart.model";
|
|
50
|
+
// import * as fs from "node:fs";
|
|
51
|
+
//
|
|
52
|
+
// dmartClient.defaults.baseURL = 'https://nova.imx.sh/dmart';
|
|
53
|
+
//
|
|
54
|
+
// Dmart.login('dmart', 'NdFVYdcsoo1M5u08').then(r => {
|
|
55
|
+
// const myPDFBuffer = fs.readFileSync('/home/splimter/projects/zain/vvv/testpdf.pdf');
|
|
56
|
+
// const myPDF = new File([myPDFBuffer], "testpdf.pdf", { type: "application/pdf" });
|
|
57
|
+
//
|
|
58
|
+
//
|
|
59
|
+
// Dmart.upload_with_payload(
|
|
60
|
+
// "referrals", `candidates/30304cab`, "auto",
|
|
61
|
+
// ResourceType.media, myPDF, ContentType.pdf,
|
|
62
|
+
// null, 'public'
|
|
63
|
+
// ).then(r=> {
|
|
64
|
+
// console.log({r})
|
|
65
|
+
// }).catch(e=> {
|
|
66
|
+
// console.log({e})
|
|
67
|
+
// })
|
|
68
|
+
// });
|
|
69
69
|
|
|
70
70
|
|