@edraj/tsdmart 5.3.0 → 5.3.3
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 +15 -0
- package/dist/dmart.model.d.ts +388 -0
- package/dist/dmart.model.d.ts.map +1 -0
- package/dist/dmart.model.js +140 -0
- package/dist/dmart.model.js.map +1 -0
- package/dist/dmart.service.d.ts +248 -0
- package/dist/dmart.service.d.ts.map +1 -0
- package/{dmart.service.ts → dist/dmart.service.js} +91 -298
- package/dist/dmart.service.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/{index.ts → dist/index.js} +1 -1
- package/dist/index.js.map +1 -0
- package/package.json +32 -4
- package/a +0 -2
- package/dmart.model.ts +0 -442
- package/test.ts +0 -70
- package/tsconfig.json +0 -45
|
@@ -1,295 +1,193 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
DmartScope,
|
|
4
|
-
headers,
|
|
5
|
-
QueryType,
|
|
6
|
-
SortType,
|
|
7
|
-
Status,
|
|
8
|
-
} from "./dmart.model";
|
|
9
|
-
import type {
|
|
10
|
-
ActionRequest,
|
|
11
|
-
ActionRequestRecord,
|
|
12
|
-
ActionResponse,
|
|
13
|
-
ApiQueryResponse,
|
|
14
|
-
ApiResponse,
|
|
15
|
-
ConfirmOTPRequest,
|
|
16
|
-
FetchDataAssetRequest,
|
|
17
|
-
GetAttachmentURLRequest,
|
|
18
|
-
GetChildrenRequest,
|
|
19
|
-
GetPayloadRequest,
|
|
20
|
-
LoginResponse,
|
|
21
|
-
PasswordResetRequest,
|
|
22
|
-
ProfileResponse,
|
|
23
|
-
ProgressTicketRequest,
|
|
24
|
-
QueryRequest,
|
|
25
|
-
ResourcesFromCSVRequest,
|
|
26
|
-
ResponseEntry,
|
|
27
|
-
RetrieveEntryRequest,
|
|
28
|
-
SendOTPRequest,
|
|
29
|
-
SubmitRequest,
|
|
30
|
-
UploadWithPayloadRequest,
|
|
31
|
-
} from "./dmart.model";
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
import { DmartScope, headers, QueryType, SortType, Status, } from "./dmart.model";
|
|
34
2
|
export class Dmart {
|
|
35
|
-
static axiosDmartInstance
|
|
36
|
-
|
|
3
|
+
static axiosDmartInstance;
|
|
37
4
|
/**
|
|
38
5
|
* Sets the Axios instance to be used for all HTTP requests
|
|
39
6
|
* @param axiosInstance - The Axios instance to use for API calls
|
|
40
7
|
*/
|
|
41
|
-
static setAxiosInstance(axiosInstance
|
|
8
|
+
static setAxiosInstance(axiosInstance) {
|
|
42
9
|
Dmart.axiosDmartInstance = axiosInstance;
|
|
43
10
|
}
|
|
44
|
-
|
|
45
11
|
/**
|
|
46
12
|
* Gets the current Axios instance
|
|
47
13
|
* @returns The configured Axios instance
|
|
48
14
|
* @throws Error if no Axios instance has been set
|
|
49
15
|
*/
|
|
50
|
-
|
|
16
|
+
static getAxiosInstance() {
|
|
51
17
|
if (!Dmart.axiosDmartInstance) {
|
|
52
18
|
throw new Error("Axios instance is not set. Please set it using setAxiosInstance method.");
|
|
53
19
|
}
|
|
54
20
|
return Dmart.axiosDmartInstance;
|
|
55
21
|
}
|
|
56
|
-
|
|
57
22
|
/**
|
|
58
23
|
* Gets the current headers object used for API requests
|
|
59
24
|
* @returns The headers object containing request headers
|
|
60
25
|
*/
|
|
61
|
-
|
|
26
|
+
static getHeaders() {
|
|
62
27
|
return headers;
|
|
63
28
|
}
|
|
64
|
-
|
|
65
29
|
/**
|
|
66
30
|
* Updates the headers object with new headers
|
|
67
31
|
* @param newHeaders - Object containing headers to merge with existing headers
|
|
68
32
|
*/
|
|
69
|
-
|
|
33
|
+
static setHeaders(newHeaders) {
|
|
70
34
|
Object.assign(headers, newHeaders);
|
|
71
35
|
}
|
|
72
|
-
|
|
73
36
|
/**
|
|
74
37
|
* Gets the base URL from the Axios instance
|
|
75
38
|
* @returns The base URL string
|
|
76
39
|
* @throws Error if no Axios instance has been set
|
|
77
40
|
*/
|
|
78
|
-
|
|
41
|
+
static getBaseURL() {
|
|
79
42
|
return Dmart.getAxiosInstance().defaults.baseURL;
|
|
80
43
|
}
|
|
81
|
-
|
|
82
44
|
/**
|
|
83
45
|
* Sets the base URL for the Axios instance
|
|
84
46
|
* @param url - The base URL to set
|
|
85
47
|
*/
|
|
86
|
-
|
|
48
|
+
static setBaseURL(url) {
|
|
87
49
|
Dmart.getAxiosInstance().defaults.baseURL = url;
|
|
88
50
|
}
|
|
89
|
-
|
|
90
51
|
/**
|
|
91
52
|
* Gets the current authentication token
|
|
92
53
|
* @returns The token string without the "Bearer " prefix, or null if not set
|
|
93
54
|
*/
|
|
94
|
-
|
|
55
|
+
static getToken() {
|
|
95
56
|
return headers["Authorization"] ? headers["Authorization"].replace("Bearer ", "") : null;
|
|
96
57
|
}
|
|
97
|
-
|
|
98
58
|
/**
|
|
99
59
|
* Sets the authentication token in the headers
|
|
100
60
|
* @param token - The JWT token to use for authentication
|
|
101
61
|
*/
|
|
102
|
-
|
|
62
|
+
static setToken(token) {
|
|
103
63
|
headers["Authorization"] = `Bearer ${token}`;
|
|
104
64
|
}
|
|
105
|
-
|
|
106
65
|
/**
|
|
107
66
|
* Authenticates a user with shortname and password
|
|
108
67
|
* @param shortname - The user's shortname (username)
|
|
109
68
|
* @param password - The user's password
|
|
110
69
|
* @returns Promise resolving to LoginResponse containing authentication data and access token
|
|
111
70
|
*/
|
|
112
|
-
|
|
113
|
-
const response = await Dmart.axiosDmartInstance.post
|
|
114
|
-
|
|
115
|
-
{shortname, password},
|
|
116
|
-
{headers}
|
|
117
|
-
);
|
|
118
|
-
const data: LoginResponse = response.data;
|
|
71
|
+
static async login(shortname, password) {
|
|
72
|
+
const response = await Dmart.axiosDmartInstance.post('user/login', { shortname, password }, { headers });
|
|
73
|
+
const data = response.data;
|
|
119
74
|
if (data.status === Status.success && data.records.length > 0) {
|
|
120
75
|
headers["Authorization"] = "Bearer " + data.records[0]?.attributes.access_token;
|
|
121
76
|
}
|
|
122
77
|
return data;
|
|
123
78
|
}
|
|
124
|
-
|
|
125
79
|
/**
|
|
126
80
|
* Authenticates a user with custom credentials and password
|
|
127
81
|
* @param credentials - Object containing login credentials (e.g., email, phone, etc.)
|
|
128
82
|
* @param password - The user's password
|
|
129
83
|
* @returns Promise resolving to LoginResponse containing authentication data and access token
|
|
130
84
|
*/
|
|
131
|
-
|
|
132
|
-
const response = await Dmart.axiosDmartInstance.post
|
|
133
|
-
|
|
134
|
-
{...credentials, password},
|
|
135
|
-
{headers}
|
|
136
|
-
);
|
|
137
|
-
const data: LoginResponse = response.data;
|
|
85
|
+
static async loginBy(credentials, password) {
|
|
86
|
+
const response = await Dmart.axiosDmartInstance.post('user/login', { ...credentials, password }, { headers });
|
|
87
|
+
const data = response.data;
|
|
138
88
|
if (data.status === Status.success && data.records.length > 0) {
|
|
139
89
|
headers["Authorization"] =
|
|
140
90
|
"Bearer " + data.records[0]?.attributes.access_token;
|
|
141
91
|
}
|
|
142
92
|
return data;
|
|
143
93
|
}
|
|
144
|
-
|
|
145
94
|
/**
|
|
146
95
|
* Logs out the current user session
|
|
147
96
|
* @returns Promise resolving to ApiResponse indicating logout status
|
|
148
97
|
*/
|
|
149
|
-
|
|
150
|
-
const {data} = await Dmart.axiosDmartInstance.post
|
|
151
|
-
'user/logout',
|
|
152
|
-
{},
|
|
153
|
-
{headers}
|
|
154
|
-
);
|
|
98
|
+
static async logout() {
|
|
99
|
+
const { data } = await Dmart.axiosDmartInstance.post('user/logout', {}, { headers });
|
|
155
100
|
return data;
|
|
156
101
|
}
|
|
157
|
-
|
|
158
102
|
/**
|
|
159
103
|
* Creates a new user account
|
|
160
104
|
* @param request - ActionRequestRecord containing user creation data
|
|
161
105
|
* @returns Promise resolving to ActionResponse with creation result
|
|
162
106
|
*/
|
|
163
|
-
|
|
164
|
-
const {data} = await Dmart.axiosDmartInstance.post
|
|
165
|
-
'user/create',
|
|
166
|
-
request,
|
|
167
|
-
{headers}
|
|
168
|
-
);
|
|
107
|
+
static async createUser(request) {
|
|
108
|
+
const { data } = await Dmart.axiosDmartInstance.post('user/create', request, { headers });
|
|
169
109
|
return data;
|
|
170
110
|
}
|
|
171
|
-
|
|
172
111
|
/**
|
|
173
112
|
* Updates an existing user's profile information
|
|
174
113
|
* @param request - ActionRequestRecord containing user update data
|
|
175
114
|
* @returns Promise resolving to ActionResponse with update result
|
|
176
115
|
*/
|
|
177
|
-
|
|
178
|
-
const {data} = await Dmart.axiosDmartInstance.post
|
|
179
|
-
'user/profile',
|
|
180
|
-
request,
|
|
181
|
-
{headers}
|
|
182
|
-
);
|
|
116
|
+
static async updateUser(request) {
|
|
117
|
+
const { data } = await Dmart.axiosDmartInstance.post('user/profile', request, { headers });
|
|
183
118
|
return data;
|
|
184
119
|
}
|
|
185
|
-
|
|
186
120
|
/**
|
|
187
121
|
* Checks if a user property value already exists in the system
|
|
188
122
|
* @param prop - The property name to check (e.g., 'email', 'shortname')
|
|
189
123
|
* @param value - The value to check for existence
|
|
190
124
|
* @returns Promise resolving to ResponseEntry indicating if the value exists
|
|
191
125
|
*/
|
|
192
|
-
|
|
193
|
-
const {data} = await Dmart.axiosDmartInstance.get
|
|
194
|
-
`user/check-existing?${prop}=${value}`,
|
|
195
|
-
{headers}
|
|
196
|
-
);
|
|
126
|
+
static async checkExisting(prop, value) {
|
|
127
|
+
const { data } = await Dmart.axiosDmartInstance.get(`user/check-existing?${prop}=${value}`, { headers });
|
|
197
128
|
return data;
|
|
198
129
|
}
|
|
199
|
-
|
|
200
130
|
/**
|
|
201
131
|
* Retrieves the current user's profile information
|
|
202
132
|
* @returns Promise resolving to ProfileResponse containing user profile data, permissions, and roles
|
|
203
133
|
*/
|
|
204
|
-
|
|
205
|
-
const {data} = await Dmart.axiosDmartInstance.get
|
|
134
|
+
static async getProfile() {
|
|
135
|
+
const { data } = await Dmart.axiosDmartInstance.get('user/profile', {
|
|
206
136
|
headers,
|
|
207
137
|
});
|
|
208
138
|
if (typeof localStorage !== "undefined" && data.status === "success") {
|
|
209
|
-
localStorage.setItem(
|
|
210
|
-
|
|
211
|
-
JSON.stringify((data?.records ?? [{}])[0]?.attributes.permissions)
|
|
212
|
-
);
|
|
213
|
-
localStorage.setItem(
|
|
214
|
-
"roles",
|
|
215
|
-
JSON.stringify((data?.records ?? [{}])[0]?.attributes?.["roles"])
|
|
216
|
-
);
|
|
139
|
+
localStorage.setItem("permissions", JSON.stringify((data?.records ?? [{}])[0]?.attributes.permissions));
|
|
140
|
+
localStorage.setItem("roles", JSON.stringify((data?.records ?? [{}])[0]?.attributes?.["roles"]));
|
|
217
141
|
}
|
|
218
142
|
return data;
|
|
219
143
|
}
|
|
220
|
-
|
|
221
144
|
/**
|
|
222
145
|
* Executes a query against the Dmart API to retrieve data
|
|
223
146
|
* @param query - QueryRequest object containing query parameters, filters, and sorting options
|
|
224
147
|
* @param scope - The scope for the query (default: DmartScope.managed)
|
|
225
148
|
* @returns Promise resolving to ApiQueryResponse with query results or null
|
|
226
149
|
*/
|
|
227
|
-
|
|
228
|
-
query: QueryRequest,
|
|
229
|
-
scope: DmartScope = DmartScope.managed
|
|
230
|
-
): Promise<ApiQueryResponse | null> {
|
|
150
|
+
static async query(query, scope = DmartScope.managed) {
|
|
231
151
|
if (query.type !== QueryType.spaces) {
|
|
232
152
|
query.sort_type = query.sort_type || SortType.ascending;
|
|
233
153
|
query.sort_by = query.sort_by || "created_at";
|
|
234
154
|
}
|
|
235
155
|
query.subpath = query.subpath.replace(/\/+/g, "/");
|
|
236
|
-
const {data} = await Dmart.axiosDmartInstance.post
|
|
237
|
-
`${scope}/query`,
|
|
238
|
-
query,
|
|
239
|
-
{headers}
|
|
240
|
-
);
|
|
156
|
+
const { data } = await Dmart.axiosDmartInstance.post(`${scope}/query`, query, { headers });
|
|
241
157
|
return data;
|
|
242
158
|
}
|
|
243
|
-
|
|
244
159
|
/**
|
|
245
160
|
* Exports query results as CSV format
|
|
246
161
|
* @param query - Query object with parameters for CSV export
|
|
247
162
|
* @returns Promise resolving to ApiQueryResponse containing CSV data
|
|
248
163
|
*/
|
|
249
|
-
|
|
164
|
+
static async csv(query) {
|
|
250
165
|
query.sort_type = query.sort_type || SortType.ascending;
|
|
251
166
|
query.sort_by = "created_at";
|
|
252
167
|
query.subpath = query.subpath.replace(/\/+/g, "/");
|
|
253
|
-
const {data} = await Dmart.axiosDmartInstance.post
|
|
254
|
-
'managed/csv',
|
|
255
|
-
query,
|
|
256
|
-
{headers}
|
|
257
|
-
);
|
|
168
|
+
const { data } = await Dmart.axiosDmartInstance.post('managed/csv', query, { headers });
|
|
258
169
|
return data;
|
|
259
170
|
}
|
|
260
|
-
|
|
261
171
|
/**
|
|
262
172
|
* Creates resources from an uploaded CSV file
|
|
263
173
|
* @param request - ResourcesFromCSVRequest containing file data and resource configuration
|
|
264
174
|
* @returns Promise resolving to ApiResponse with creation results
|
|
265
175
|
*/
|
|
266
|
-
|
|
267
|
-
request: ResourcesFromCSVRequest
|
|
268
|
-
) {
|
|
176
|
+
static async resourcesFromCsv(request) {
|
|
269
177
|
let csvUrl = `/managed/resources_from_csv/${request.resourceType}/${request.space_name}/${request.subpath}`;
|
|
270
|
-
const params
|
|
178
|
+
const params = {};
|
|
271
179
|
if (request.schema) {
|
|
272
180
|
csvUrl += `/${request.schema}`;
|
|
273
181
|
}
|
|
274
|
-
|
|
275
182
|
const formdata = new FormData();
|
|
276
183
|
formdata.append("resources_file", request.payload);
|
|
277
|
-
|
|
278
184
|
if (request.isUpdate) {
|
|
279
185
|
params['is_update'] = request.isUpdate;
|
|
280
186
|
}
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
const {data} = await Dmart.axiosDmartInstance.post<ApiResponse>(
|
|
285
|
-
csvUrl,
|
|
286
|
-
formdata,
|
|
287
|
-
{headers: multipartHeaders, params}
|
|
288
|
-
);
|
|
289
|
-
|
|
187
|
+
const multipartHeaders = { ...headers, "Content-Type": "multipart/form-data" };
|
|
188
|
+
const { data } = await Dmart.axiosDmartInstance.post(csvUrl, formdata, { headers: multipartHeaders, params });
|
|
290
189
|
return data;
|
|
291
190
|
}
|
|
292
|
-
|
|
293
191
|
// /** LEGACY, DEPRECATED CODE, DO NOT USE
|
|
294
192
|
// * Performs space-level operations (create, update, delete spaces)
|
|
295
193
|
// * @param action - ActionRequest containing the operation details for space management
|
|
@@ -303,116 +201,87 @@ export class Dmart {
|
|
|
303
201
|
// );
|
|
304
202
|
// return data;
|
|
305
203
|
// }
|
|
306
|
-
|
|
307
204
|
/**
|
|
308
205
|
* Executes a general request action against the Dmart API
|
|
309
206
|
* @param action - ActionRequest containing the request details and parameters
|
|
310
207
|
* @returns Promise resolving to ActionResponse with request result
|
|
311
208
|
*/
|
|
312
|
-
|
|
313
|
-
const res = await Dmart.axiosDmartInstance.post
|
|
209
|
+
static async request(action) {
|
|
210
|
+
const res = await Dmart.axiosDmartInstance.post('managed/request', action, {
|
|
314
211
|
headers,
|
|
315
212
|
});
|
|
316
213
|
return res?.data;
|
|
317
214
|
}
|
|
318
|
-
|
|
319
215
|
/**
|
|
320
216
|
* Retrieves a specific entry from the Dmart system
|
|
321
217
|
* @param request - RetrieveEntryRequest containing entry identification and retrieval options
|
|
322
218
|
* @param scope - The scope for the retrieval (default: DmartScope.managed)
|
|
323
219
|
* @returns Promise resolving to ResponseEntry with entry data or null if not found
|
|
324
220
|
*/
|
|
325
|
-
|
|
326
|
-
request: RetrieveEntryRequest,
|
|
327
|
-
scope: DmartScope = DmartScope.managed
|
|
328
|
-
): Promise<ResponseEntry | null> {
|
|
221
|
+
static async retrieveEntry(request, scope = DmartScope.managed) {
|
|
329
222
|
if (request.validate_schema === null) {
|
|
330
223
|
request.validate_schema = true;
|
|
331
224
|
}
|
|
332
|
-
if (!request.subpath || request.subpath === "/")
|
|
225
|
+
if (!request.subpath || request.subpath === "/")
|
|
226
|
+
request.subpath = "__root__";
|
|
333
227
|
const url = `${scope}/entry/${request.resource_type}/${request.space_name}/${request.subpath}/${request.shortname}?retrieve_json_payload=${request.retrieve_json_payload}&retrieve_attachments=${request.retrieve_attachments}&validate_schema=${request.validate_schema}`;
|
|
334
|
-
const {data} = await Dmart.axiosDmartInstance.get
|
|
335
|
-
`${url.replace(/\/+/g, "/")}`,
|
|
336
|
-
{headers}
|
|
337
|
-
);
|
|
228
|
+
const { data } = await Dmart.axiosDmartInstance.get(`${url.replace(/\/+/g, "/")}`, { headers });
|
|
338
229
|
return data;
|
|
339
230
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
231
|
/**
|
|
343
232
|
* Uploads a resource with an attached payload file
|
|
344
233
|
* @param request - UploadWithPayloadRequest containing resource data and payload file
|
|
345
234
|
* @param scope - The scope for the upload operation (default: DmartScope.managed)
|
|
346
235
|
* @returns Promise resolving to ApiResponse with upload result
|
|
347
236
|
*/
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
scope: DmartScope = DmartScope.managed
|
|
351
|
-
) {
|
|
352
|
-
const request_record_body: Record<string, any> = {
|
|
237
|
+
static async uploadWithPayload(request, scope = DmartScope.managed) {
|
|
238
|
+
const request_record_body = {
|
|
353
239
|
resource_type: request.resource_type,
|
|
354
240
|
subpath: request.subpath,
|
|
355
241
|
shortname: request.shortname,
|
|
356
242
|
attributes: request.attributes ?? {},
|
|
357
243
|
};
|
|
358
|
-
|
|
359
244
|
if (!request.attributes || Object.keys(request.attributes).length === 0) {
|
|
360
|
-
request_record_body['attributes'] = {is_active: true, payload: {body: {}}};
|
|
361
|
-
}
|
|
245
|
+
request_record_body['attributes'] = { is_active: true, payload: { body: {}, content_type: 'json' } };
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
362
248
|
if (!Object.keys(request.attributes).includes('is_active')) {
|
|
363
249
|
request_record_body['attributes'].is_active = true;
|
|
364
250
|
}
|
|
365
251
|
}
|
|
366
|
-
|
|
367
252
|
const request_record = new Blob([JSON.stringify(request_record_body)], {
|
|
368
253
|
type: "application/json",
|
|
369
254
|
});
|
|
370
|
-
|
|
371
255
|
const form_data = new FormData();
|
|
372
256
|
form_data.append("space_name", request.space_name);
|
|
373
257
|
form_data.append("request_record", request_record);
|
|
374
258
|
form_data.append("payload_file", request.payload_file);
|
|
375
|
-
|
|
376
|
-
const
|
|
377
|
-
|
|
378
|
-
const {data} = await Dmart.axiosDmartInstance.post<ApiResponse>(
|
|
379
|
-
`${scope}/resource_with_payload`,
|
|
380
|
-
form_data,
|
|
381
|
-
{headers: _headers}
|
|
382
|
-
);
|
|
383
|
-
|
|
259
|
+
const _headers = { ...headers, "Content-Type": "multipart/form-data" };
|
|
260
|
+
const { data } = await Dmart.axiosDmartInstance.post(`${scope}/resource_with_payload`, form_data, { headers: _headers });
|
|
384
261
|
return data;
|
|
385
262
|
}
|
|
386
|
-
|
|
387
263
|
/**
|
|
388
264
|
* Fetches data assets from the Dmart system with optional SQL query filtering
|
|
389
265
|
* @param request - FetchDataAssetRequest containing asset identification and query parameters
|
|
390
266
|
* @returns Promise resolving to data asset response
|
|
391
267
|
*/
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
shortname: request.shortname,
|
|
403
|
-
query_string: request.query_string ?? "SELECT * FROM file",
|
|
404
|
-
filter_data_assets: request.filter_data_assets,
|
|
405
|
-
},
|
|
406
|
-
{headers}
|
|
407
|
-
);
|
|
268
|
+
static async fetchDataAsset(request) {
|
|
269
|
+
const { data } = await Dmart.axiosDmartInstance.post('managed/data-asset', {
|
|
270
|
+
space_name: request.spaceName,
|
|
271
|
+
resource_type: request.resourceType,
|
|
272
|
+
data_asset_type: request.dataAssetType,
|
|
273
|
+
subpath: request.subpath,
|
|
274
|
+
shortname: request.shortname,
|
|
275
|
+
query_string: request.query_string ?? "SELECT * FROM file",
|
|
276
|
+
filter_data_assets: request.filter_data_assets,
|
|
277
|
+
}, { headers });
|
|
408
278
|
return data;
|
|
409
279
|
}
|
|
410
|
-
|
|
411
280
|
/**
|
|
412
281
|
* Retrieves a list of all available spaces in the system
|
|
413
282
|
* @returns Promise resolving to ApiResponse containing spaces data or null
|
|
414
283
|
*/
|
|
415
|
-
|
|
284
|
+
static async getSpaces() {
|
|
416
285
|
return await this.query({
|
|
417
286
|
type: QueryType.spaces,
|
|
418
287
|
space_name: "management",
|
|
@@ -421,15 +290,12 @@ export class Dmart {
|
|
|
421
290
|
limit: 100,
|
|
422
291
|
});
|
|
423
292
|
}
|
|
424
|
-
|
|
425
293
|
/**
|
|
426
294
|
* Gets child resources within a specified space and subpath
|
|
427
295
|
* @param request - GetChildrenRequest containing search parameters and filters
|
|
428
296
|
* @returns Promise resolving to ApiResponse with child resources or null
|
|
429
297
|
*/
|
|
430
|
-
|
|
431
|
-
request: GetChildrenRequest
|
|
432
|
-
): Promise<ApiResponse | null> {
|
|
298
|
+
static async getChildren(request) {
|
|
433
299
|
if (request.limit === null) {
|
|
434
300
|
request.limit = 20;
|
|
435
301
|
}
|
|
@@ -450,92 +316,62 @@ export class Dmart {
|
|
|
450
316
|
offset: request.offset,
|
|
451
317
|
});
|
|
452
318
|
}
|
|
453
|
-
|
|
454
319
|
/**
|
|
455
320
|
* Generates a URL for accessing attachment resources
|
|
456
321
|
* @param request - GetAttachmentURLRequest containing attachment identification parameters
|
|
457
322
|
* @param scope - The scope for the attachment URL (default: DmartScope.managed)
|
|
458
323
|
* @returns String URL for accessing the attachment
|
|
459
324
|
*/
|
|
460
|
-
|
|
461
|
-
request
|
|
462
|
-
scope: DmartScope = DmartScope.managed
|
|
463
|
-
) {
|
|
464
|
-
const subpath = request.subpath.replace(
|
|
465
|
-
/\/+$/,
|
|
466
|
-
""
|
|
467
|
-
);
|
|
325
|
+
static getAttachmentUrl(request, scope = DmartScope.managed) {
|
|
326
|
+
const subpath = request.subpath.replace(/\/+$/, "");
|
|
468
327
|
return `${Dmart.getAxiosInstance().defaults.baseURL}` + `/${scope}/payload/${request.resource_type}/${request.space_name}/${subpath}/${request.parent_shortname}/${request.shortname}${request.ext === null ? "" : `.${request.ext}`}`.replaceAll('//', '/');
|
|
469
328
|
}
|
|
470
|
-
|
|
471
329
|
/**
|
|
472
330
|
* Retrieves health information and statistics for a specific space
|
|
473
331
|
* @param space_name - The name of the space to check health for
|
|
474
332
|
* @returns Promise resolving to ApiQueryResponse with health data and folders report
|
|
475
333
|
*/
|
|
476
|
-
|
|
477
|
-
const {data} = await Dmart.axiosDmartInstance.get
|
|
478
|
-
ApiQueryResponse & { attributes: { folders_report: Record<string, unknown> } }
|
|
479
|
-
>(`managed/health/${space_name}`, {headers});
|
|
334
|
+
static async getSpaceHealth(space_name) {
|
|
335
|
+
const { data } = await Dmart.axiosDmartInstance.get(`managed/health/${space_name}`, { headers });
|
|
480
336
|
return data;
|
|
481
337
|
}
|
|
482
|
-
|
|
483
338
|
/**
|
|
484
339
|
* Retrieves payload data for a specific resource
|
|
485
340
|
* @param request - GetPayloadRequest containing payload identification parameters
|
|
486
341
|
* @param scope - The scope for the payload retrieval (default: DmartScope.managed)
|
|
487
342
|
* @returns Promise resolving to payload data
|
|
488
343
|
*/
|
|
489
|
-
|
|
490
|
-
request: GetPayloadRequest,
|
|
491
|
-
scope: DmartScope = DmartScope.managed
|
|
492
|
-
) {
|
|
344
|
+
static async getPayload(request, scope = DmartScope.managed) {
|
|
493
345
|
let url = `${scope}/payload/${request.resource_type}/${request.space_name}/${request.subpath}/${request.shortname}`;
|
|
494
|
-
|
|
495
346
|
if (request.schemaShortname) {
|
|
496
347
|
url += `.${request.schemaShortname}`;
|
|
497
348
|
}
|
|
498
349
|
url += `.${request.ext}`;
|
|
499
|
-
const {data} = await Dmart.axiosDmartInstance.get
|
|
500
|
-
url,
|
|
501
|
-
{headers}
|
|
502
|
-
);
|
|
350
|
+
const { data } = await Dmart.axiosDmartInstance.get(url, { headers });
|
|
503
351
|
return data;
|
|
504
352
|
}
|
|
505
|
-
|
|
506
353
|
/**
|
|
507
354
|
* Updates the progress of a ticket with resolution and comments
|
|
508
355
|
* @param request - ProgressTicketRequest containing ticket identification and update data
|
|
509
356
|
* @returns Promise resolving to ApiQueryResponse with progress update result
|
|
510
357
|
*/
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
) {
|
|
514
|
-
const payload: Record<string, string> = {};
|
|
358
|
+
static async progressTicket(request) {
|
|
359
|
+
const payload = {};
|
|
515
360
|
if (request.resolution) {
|
|
516
361
|
payload['resolution'] = request.resolution;
|
|
517
362
|
}
|
|
518
363
|
if (request.comment) {
|
|
519
364
|
payload['comment'] = request.comment;
|
|
520
365
|
}
|
|
521
|
-
const {data} = await Dmart.axiosDmartInstance.put
|
|
522
|
-
ApiQueryResponse & { attributes: { folders_report: Record<string, unknown> } }
|
|
523
|
-
>(
|
|
524
|
-
`managed/progress-ticket/${request.space_name}/${request.subpath}/${request.shortname}/${request.action}`,
|
|
525
|
-
payload,
|
|
526
|
-
{headers}
|
|
527
|
-
);
|
|
366
|
+
const { data } = await Dmart.axiosDmartInstance.put(`managed/progress-ticket/${request.space_name}/${request.subpath}/${request.shortname}/${request.action}`, payload, { headers });
|
|
528
367
|
return data;
|
|
529
368
|
}
|
|
530
|
-
|
|
531
369
|
/**
|
|
532
370
|
* Submits data to a public endpoint with optional workflow processing
|
|
533
371
|
* @param request - SubmitRequest containing submission data and routing information
|
|
534
372
|
* @returns Promise resolving to submission response data
|
|
535
373
|
*/
|
|
536
|
-
|
|
537
|
-
request: SubmitRequest
|
|
538
|
-
) {
|
|
374
|
+
static async submit(request) {
|
|
539
375
|
let url = `public/submit/${request.spaceName}`;
|
|
540
376
|
if (request.resourceType) {
|
|
541
377
|
url += `/${request.resourceType}`;
|
|
@@ -544,135 +380,92 @@ export class Dmart {
|
|
|
544
380
|
url += `/${request.workflowShortname}`;
|
|
545
381
|
}
|
|
546
382
|
url += `/${request.schemaShortname}/${request.subpath}`;
|
|
547
|
-
const {data} = await Dmart.axiosDmartInstance.post(
|
|
548
|
-
url,
|
|
549
|
-
request.record,
|
|
550
|
-
{headers}
|
|
551
|
-
);
|
|
383
|
+
const { data } = await Dmart.axiosDmartInstance.post(url, request.record, { headers });
|
|
552
384
|
return data;
|
|
553
385
|
}
|
|
554
|
-
|
|
555
386
|
/**
|
|
556
387
|
* Retrieves the system manifest containing configuration and metadata
|
|
557
388
|
* @returns Promise resolving to manifest data
|
|
558
389
|
*/
|
|
559
|
-
|
|
560
|
-
const {data} = await Dmart.axiosDmartInstance.get
|
|
390
|
+
static async getManifest() {
|
|
391
|
+
const { data } = await Dmart.axiosDmartInstance.get('info/manifest', {
|
|
561
392
|
headers,
|
|
562
393
|
});
|
|
563
394
|
return data;
|
|
564
395
|
}
|
|
565
|
-
|
|
566
396
|
/**
|
|
567
397
|
* Retrieves the system settings and configuration
|
|
568
398
|
* @returns Promise resolving to settings data
|
|
569
399
|
*/
|
|
570
|
-
|
|
571
|
-
const {data} = await Dmart.axiosDmartInstance.get
|
|
400
|
+
static async getSettings() {
|
|
401
|
+
const { data } = await Dmart.axiosDmartInstance.get('info/settings', {
|
|
572
402
|
headers,
|
|
573
403
|
});
|
|
574
404
|
return data;
|
|
575
405
|
}
|
|
576
|
-
|
|
577
406
|
/**
|
|
578
407
|
* Sends an OTP (One-Time Password) request to a user
|
|
579
408
|
* @param request - SendOTPRequest containing recipient information
|
|
580
409
|
* @param acceptLanguage - Optional language preference for the OTP message (default: null)
|
|
581
410
|
* @returns Promise resolving to ApiResponse with OTP request result
|
|
582
411
|
*/
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
acceptLanguage: string | null = null
|
|
586
|
-
) {
|
|
587
|
-
const requestHeaders = {...headers};
|
|
412
|
+
static async otpRequest(request, acceptLanguage = null) {
|
|
413
|
+
const requestHeaders = { ...headers };
|
|
588
414
|
if (acceptLanguage) {
|
|
589
415
|
requestHeaders['Accept-Language'] = acceptLanguage;
|
|
590
416
|
}
|
|
591
|
-
|
|
592
|
-
const {data} = await Dmart.axiosDmartInstance.post<ApiResponse>(
|
|
593
|
-
'user/otp-request',
|
|
594
|
-
request,
|
|
595
|
-
{headers: requestHeaders}
|
|
596
|
-
);
|
|
417
|
+
const { data } = await Dmart.axiosDmartInstance.post('user/otp-request', request, { headers: requestHeaders });
|
|
597
418
|
return data;
|
|
598
419
|
}
|
|
599
|
-
|
|
600
420
|
/**
|
|
601
421
|
* Sends an OTP (One-Time Password) request for login purposes
|
|
602
422
|
* @param request - SendOTPRequest containing recipient information for login OTP
|
|
603
423
|
* @param acceptLanguage - Optional language preference for the OTP message (default: null)
|
|
604
424
|
* @returns Promise resolving to ApiResponse with OTP login request result
|
|
605
425
|
*/
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
acceptLanguage: string | null = null
|
|
609
|
-
) {
|
|
610
|
-
const requestHeaders = {...headers};
|
|
426
|
+
static async otpRequestLogin(request, acceptLanguage = null) {
|
|
427
|
+
const requestHeaders = { ...headers };
|
|
611
428
|
if (acceptLanguage) {
|
|
612
429
|
requestHeaders['Accept-Language'] = acceptLanguage;
|
|
613
430
|
}
|
|
614
|
-
|
|
615
|
-
const {data} = await Dmart.axiosDmartInstance.post<ApiResponse>(
|
|
616
|
-
'user/otp-request-login',
|
|
617
|
-
request,
|
|
618
|
-
{headers: requestHeaders}
|
|
619
|
-
);
|
|
431
|
+
const { data } = await Dmart.axiosDmartInstance.post('user/otp-request-login', request, { headers: requestHeaders });
|
|
620
432
|
return data;
|
|
621
433
|
}
|
|
622
|
-
|
|
623
434
|
/**
|
|
624
435
|
* Initiates a password reset request for a user
|
|
625
436
|
* @param request - PasswordResetRequest containing user identification for password reset
|
|
626
437
|
* @returns Promise resolving to ApiResponse with password reset request result
|
|
627
438
|
*/
|
|
628
|
-
|
|
629
|
-
const {data} = await Dmart.axiosDmartInstance.post
|
|
630
|
-
'user/password-reset-request',
|
|
631
|
-
request,
|
|
632
|
-
{headers}
|
|
633
|
-
);
|
|
439
|
+
static async passwordResetRequest(request) {
|
|
440
|
+
const { data } = await Dmart.axiosDmartInstance.post('user/password-reset-request', request, { headers });
|
|
634
441
|
return data;
|
|
635
442
|
}
|
|
636
|
-
|
|
637
443
|
/**
|
|
638
444
|
* Confirms an OTP (One-Time Password) code provided by the user
|
|
639
445
|
* @param request - ConfirmOTPRequest containing the OTP code and verification details
|
|
640
446
|
* @returns Promise resolving to ApiResponse with OTP confirmation result
|
|
641
447
|
*/
|
|
642
|
-
|
|
643
|
-
const {data} = await Dmart.axiosDmartInstance.post
|
|
644
|
-
'user/otp-confirm',
|
|
645
|
-
request,
|
|
646
|
-
{headers}
|
|
647
|
-
);
|
|
448
|
+
static async confirmOtp(request) {
|
|
449
|
+
const { data } = await Dmart.axiosDmartInstance.post('user/otp-confirm', request, { headers });
|
|
648
450
|
return data;
|
|
649
451
|
}
|
|
650
|
-
|
|
651
452
|
/**
|
|
652
453
|
* Resets a user's account or session state
|
|
653
454
|
* @param shortname - The shortname (username) of the user to reset
|
|
654
455
|
* @returns Promise resolving to ApiResponse with user reset result
|
|
655
456
|
*/
|
|
656
|
-
|
|
657
|
-
const {data} = await Dmart.axiosDmartInstance.post
|
|
658
|
-
'user/reset',
|
|
659
|
-
{shortname},
|
|
660
|
-
{headers}
|
|
661
|
-
);
|
|
457
|
+
static async userReset(shortname) {
|
|
458
|
+
const { data } = await Dmart.axiosDmartInstance.post('user/reset', { shortname }, { headers });
|
|
662
459
|
return data;
|
|
663
460
|
}
|
|
664
|
-
|
|
665
461
|
/**
|
|
666
462
|
* Validates a password against system password policies and requirements
|
|
667
463
|
* @param password - The password string to validate
|
|
668
464
|
* @returns Promise resolving to ApiResponse with validation result
|
|
669
465
|
*/
|
|
670
|
-
|
|
671
|
-
const {data} = await Dmart.axiosDmartInstance.post
|
|
672
|
-
'user/validate_password',
|
|
673
|
-
{password},
|
|
674
|
-
{headers}
|
|
675
|
-
);
|
|
466
|
+
static async validatePassword(password) {
|
|
467
|
+
const { data } = await Dmart.axiosDmartInstance.post('user/validate_password', { password }, { headers });
|
|
676
468
|
return data;
|
|
677
469
|
}
|
|
678
470
|
}
|
|
471
|
+
//# sourceMappingURL=dmart.service.js.map
|