@edraj/tsdmart 4.0.2 → 4.0.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/dmart.service.ts +212 -1
- package/package.json +1 -1
package/dmart.service.ts
CHANGED
|
@@ -29,10 +29,19 @@ import {
|
|
|
29
29
|
export class Dmart {
|
|
30
30
|
static axiosDmartInstance: AxiosInstance;
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Sets the Axios instance to be used for all HTTP requests
|
|
34
|
+
* @param axiosInstance - The Axios instance to use for API calls
|
|
35
|
+
*/
|
|
32
36
|
static setAxiosInstance(axiosInstance: AxiosInstance) {
|
|
33
37
|
Dmart.axiosDmartInstance = axiosInstance;
|
|
34
38
|
}
|
|
35
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Gets the current Axios instance
|
|
42
|
+
* @returns The configured Axios instance
|
|
43
|
+
* @throws Error if no Axios instance has been set
|
|
44
|
+
*/
|
|
36
45
|
public static getAxiosInstance(): AxiosInstance {
|
|
37
46
|
if (!Dmart.axiosDmartInstance) {
|
|
38
47
|
throw new Error("Axios instance is not set. Please set it using setAxiosInstance method.");
|
|
@@ -40,30 +49,60 @@ export class Dmart {
|
|
|
40
49
|
return Dmart.axiosDmartInstance;
|
|
41
50
|
}
|
|
42
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Gets the current headers object used for API requests
|
|
54
|
+
* @returns The headers object containing request headers
|
|
55
|
+
*/
|
|
43
56
|
public static getHeaders() {
|
|
44
57
|
return headers;
|
|
45
58
|
}
|
|
46
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Updates the headers object with new headers
|
|
62
|
+
* @param newHeaders - Object containing headers to merge with existing headers
|
|
63
|
+
*/
|
|
47
64
|
public static setHeaders(newHeaders: any) {
|
|
48
65
|
Object.assign(headers, newHeaders);
|
|
49
66
|
}
|
|
50
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Gets the base URL from the Axios instance
|
|
70
|
+
* @returns The base URL string
|
|
71
|
+
*/
|
|
51
72
|
public static getBaseURL() {
|
|
52
73
|
return Dmart.axiosDmartInstance.defaults.baseURL;
|
|
53
74
|
}
|
|
54
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Sets the base URL for the Axios instance
|
|
78
|
+
* @param url - The base URL to set
|
|
79
|
+
*/
|
|
55
80
|
public static set setBaseURL(url: string) {
|
|
56
81
|
Dmart.axiosDmartInstance.defaults.baseURL = url;
|
|
57
82
|
}
|
|
58
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Gets the current authentication token
|
|
86
|
+
* @returns The token string without the "Bearer " prefix, or null if not set
|
|
87
|
+
*/
|
|
59
88
|
public static getToken() {
|
|
60
89
|
return headers["Authorization"] ? headers["Authorization"].replace("Bearer ", "") : null;
|
|
61
90
|
}
|
|
62
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Sets the authentication token in the headers
|
|
94
|
+
* @param token - The JWT token to use for authentication
|
|
95
|
+
*/
|
|
63
96
|
public static setToken(token: string) {
|
|
64
97
|
headers["Authorization"] = `Bearer ${token}`;
|
|
65
98
|
}
|
|
66
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Authenticates a user with shortname and password
|
|
102
|
+
* @param shortname - The user's shortname (username)
|
|
103
|
+
* @param password - The user's password
|
|
104
|
+
* @returns Promise resolving to LoginResponse containing authentication data and access token
|
|
105
|
+
*/
|
|
67
106
|
public static async login(shortname: string, password: string) {
|
|
68
107
|
const response = await Dmart.axiosDmartInstance.post<LoginResponse>(
|
|
69
108
|
`user/login`,
|
|
@@ -78,6 +117,13 @@ export class Dmart {
|
|
|
78
117
|
return data;
|
|
79
118
|
}
|
|
80
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Authenticates a user with custom credentials and password
|
|
122
|
+
* @param credentials - Object containing login credentials (e.g., email, phone, etc.)
|
|
123
|
+
* @param password - The user's password
|
|
124
|
+
* @returns Promise resolving to LoginResponse containing authentication data and access token
|
|
125
|
+
* @throws Error if login request fails
|
|
126
|
+
*/
|
|
81
127
|
public static async loginBy(credentials: any, password: string) {
|
|
82
128
|
try {
|
|
83
129
|
const response = await Dmart.axiosDmartInstance.post<LoginResponse>(
|
|
@@ -96,6 +142,11 @@ export class Dmart {
|
|
|
96
142
|
}
|
|
97
143
|
}
|
|
98
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Logs out the current user session
|
|
147
|
+
* @returns Promise resolving to ApiResponse indicating logout status
|
|
148
|
+
* @throws Error if logout request fails
|
|
149
|
+
*/
|
|
99
150
|
public static async logout() {
|
|
100
151
|
try {
|
|
101
152
|
const {data} = await Dmart.axiosDmartInstance.post<ApiResponse>(
|
|
@@ -109,6 +160,12 @@ export class Dmart {
|
|
|
109
160
|
}
|
|
110
161
|
}
|
|
111
162
|
|
|
163
|
+
/**
|
|
164
|
+
* Creates a new user account
|
|
165
|
+
* @param request - ActionRequestRecord containing user creation data
|
|
166
|
+
* @returns Promise resolving to ActionResponse with creation result
|
|
167
|
+
* @throws Error if user creation fails
|
|
168
|
+
*/
|
|
112
169
|
public static async createUser(request: ActionRequestRecord) {
|
|
113
170
|
try {
|
|
114
171
|
const {data} = await Dmart.axiosDmartInstance.post<ActionResponse>(
|
|
@@ -122,6 +179,12 @@ export class Dmart {
|
|
|
122
179
|
}
|
|
123
180
|
}
|
|
124
181
|
|
|
182
|
+
/**
|
|
183
|
+
* Updates an existing user's profile information
|
|
184
|
+
* @param request - ActionRequestRecord containing user update data
|
|
185
|
+
* @returns Promise resolving to ActionResponse with update result
|
|
186
|
+
* @throws Error if user update fails
|
|
187
|
+
*/
|
|
125
188
|
public static async updateUser(request: ActionRequestRecord) {
|
|
126
189
|
try {
|
|
127
190
|
const {data} = await Dmart.axiosDmartInstance.post<ActionResponse>(
|
|
@@ -135,6 +198,13 @@ export class Dmart {
|
|
|
135
198
|
}
|
|
136
199
|
}
|
|
137
200
|
|
|
201
|
+
/**
|
|
202
|
+
* Checks if a user property value already exists in the system
|
|
203
|
+
* @param prop - The property name to check (e.g., 'email', 'shortname')
|
|
204
|
+
* @param value - The value to check for existence
|
|
205
|
+
* @returns Promise resolving to ResponseEntry indicating if the value exists
|
|
206
|
+
* @throws Error if check request fails
|
|
207
|
+
*/
|
|
138
208
|
public static async checkExisting(prop: string, value: string) {
|
|
139
209
|
try {
|
|
140
210
|
const {data} = await Dmart.axiosDmartInstance.get<ResponseEntry>(
|
|
@@ -147,6 +217,11 @@ export class Dmart {
|
|
|
147
217
|
}
|
|
148
218
|
}
|
|
149
219
|
|
|
220
|
+
/**
|
|
221
|
+
* Retrieves the current user's profile information
|
|
222
|
+
* @returns Promise resolving to ProfileResponse containing user profile data, permissions, and roles
|
|
223
|
+
* @throws Error if profile retrieval fails
|
|
224
|
+
*/
|
|
150
225
|
public static async getProfile() {
|
|
151
226
|
try {
|
|
152
227
|
const {data} = await Dmart.axiosDmartInstance.get<ProfileResponse>(`user/profile`, {
|
|
@@ -168,6 +243,13 @@ export class Dmart {
|
|
|
168
243
|
}
|
|
169
244
|
}
|
|
170
245
|
|
|
246
|
+
/**
|
|
247
|
+
* Executes a query against the Dmart API to retrieve data
|
|
248
|
+
* @param query - QueryRequest object containing query parameters, filters, and sorting options
|
|
249
|
+
* @param scope - The scope for the query (default: DmartScope.managed)
|
|
250
|
+
* @returns Promise resolving to ApiQueryResponse with query results or null
|
|
251
|
+
* @throws Error if query execution fails
|
|
252
|
+
*/
|
|
171
253
|
public static async query(
|
|
172
254
|
query: QueryRequest,
|
|
173
255
|
scope: string = DmartScope.managed
|
|
@@ -189,6 +271,12 @@ export class Dmart {
|
|
|
189
271
|
}
|
|
190
272
|
}
|
|
191
273
|
|
|
274
|
+
/**
|
|
275
|
+
* Exports query results as CSV format
|
|
276
|
+
* @param query - Query object with parameters for CSV export
|
|
277
|
+
* @returns Promise resolving to ApiQueryResponse containing CSV data
|
|
278
|
+
* @throws Error if CSV generation fails
|
|
279
|
+
*/
|
|
192
280
|
public static async csv(query: any): Promise<ApiQueryResponse> {
|
|
193
281
|
try {
|
|
194
282
|
query.sort_type = query.sort_type || SortyType.ascending;
|
|
@@ -205,6 +293,11 @@ export class Dmart {
|
|
|
205
293
|
}
|
|
206
294
|
}
|
|
207
295
|
|
|
296
|
+
/**
|
|
297
|
+
* Creates resources from an uploaded CSV file
|
|
298
|
+
* @param request - ResourcesFromCSVRequest containing file data and resource configuration
|
|
299
|
+
* @returns Promise resolving to ApiResponse with creation results, or error object if failed
|
|
300
|
+
*/
|
|
208
301
|
public static async resourcesFromCsv(
|
|
209
302
|
request: ResourcesFromCSVRequest
|
|
210
303
|
) {
|
|
@@ -232,7 +325,12 @@ export class Dmart {
|
|
|
232
325
|
}
|
|
233
326
|
}
|
|
234
327
|
|
|
235
|
-
|
|
328
|
+
/**
|
|
329
|
+
* Performs space-level operations (create, update, delete spaces)
|
|
330
|
+
* @param action - ActionRequest containing the operation details for space management
|
|
331
|
+
* @returns Promise resolving to ActionResponse with operation result
|
|
332
|
+
* @throws Error if space operation fails
|
|
333
|
+
*/
|
|
236
334
|
public static async space(action: ActionRequest): Promise<ActionResponse> {
|
|
237
335
|
try {
|
|
238
336
|
const {data} = await Dmart.axiosDmartInstance.post<ActionResponse>(
|
|
@@ -246,6 +344,11 @@ export class Dmart {
|
|
|
246
344
|
}
|
|
247
345
|
}
|
|
248
346
|
|
|
347
|
+
/**
|
|
348
|
+
* Executes a general request action against the Dmart API
|
|
349
|
+
* @param action - ActionRequest containing the request details and parameters
|
|
350
|
+
* @returns Promise resolving to ActionResponse with request result
|
|
351
|
+
*/
|
|
249
352
|
public static async request(action: ActionRequest): Promise<ActionResponse> {
|
|
250
353
|
const res = await Dmart.axiosDmartInstance.post<ActionResponse>(`managed/request`, action, {
|
|
251
354
|
headers,
|
|
@@ -253,6 +356,13 @@ export class Dmart {
|
|
|
253
356
|
return res?.data;
|
|
254
357
|
}
|
|
255
358
|
|
|
359
|
+
/**
|
|
360
|
+
* Retrieves a specific entry from the Dmart system
|
|
361
|
+
* @param request - RetrieveEntryRequest containing entry identification and retrieval options
|
|
362
|
+
* @param scope - The scope for the retrieval (default: DmartScope.managed)
|
|
363
|
+
* @returns Promise resolving to ResponseEntry with entry data or null if not found
|
|
364
|
+
* @throws Error if entry retrieval fails
|
|
365
|
+
*/
|
|
256
366
|
public static async retrieveEntry(
|
|
257
367
|
request: RetrieveEntryRequest,
|
|
258
368
|
scope: string = DmartScope.managed
|
|
@@ -274,6 +384,13 @@ export class Dmart {
|
|
|
274
384
|
}
|
|
275
385
|
|
|
276
386
|
|
|
387
|
+
/**
|
|
388
|
+
* Uploads a resource with an attached payload file
|
|
389
|
+
* @param request - UploadWithPayloadRequest containing resource data and payload file
|
|
390
|
+
* @param scope - The scope for the upload operation (default: DmartScope.managed)
|
|
391
|
+
* @returns Promise resolving to ApiResponse with upload result
|
|
392
|
+
* @throws Error if upload fails
|
|
393
|
+
*/
|
|
277
394
|
public static async uploadWithPayload(
|
|
278
395
|
request: UploadWithPayloadRequest,
|
|
279
396
|
scope: string = DmartScope.managed
|
|
@@ -317,6 +434,12 @@ export class Dmart {
|
|
|
317
434
|
}
|
|
318
435
|
}
|
|
319
436
|
|
|
437
|
+
/**
|
|
438
|
+
* Fetches data assets from the Dmart system with optional SQL query filtering
|
|
439
|
+
* @param request - FetchDataAssetRequest containing asset identification and query parameters
|
|
440
|
+
* @returns Promise resolving to data asset response
|
|
441
|
+
* @throws Error if data asset fetch fails
|
|
442
|
+
*/
|
|
320
443
|
public static async fetchDataAsset(
|
|
321
444
|
request: FetchDataAssetRequest,
|
|
322
445
|
) {
|
|
@@ -340,6 +463,10 @@ export class Dmart {
|
|
|
340
463
|
}
|
|
341
464
|
}
|
|
342
465
|
|
|
466
|
+
/**
|
|
467
|
+
* Retrieves a list of all available spaces in the system
|
|
468
|
+
* @returns Promise resolving to ApiResponse containing spaces data or null
|
|
469
|
+
*/
|
|
343
470
|
public static async getSpaces(): Promise<ApiResponse | null> {
|
|
344
471
|
return await this.query({
|
|
345
472
|
type: QueryType.spaces,
|
|
@@ -350,6 +477,11 @@ export class Dmart {
|
|
|
350
477
|
});
|
|
351
478
|
}
|
|
352
479
|
|
|
480
|
+
/**
|
|
481
|
+
* Gets child resources within a specified space and subpath
|
|
482
|
+
* @param request - GetChildrenRequest containing search parameters and filters
|
|
483
|
+
* @returns Promise resolving to ApiResponse with child resources or null
|
|
484
|
+
*/
|
|
353
485
|
public static async getChildren(
|
|
354
486
|
request: GetChildrenRequest
|
|
355
487
|
): Promise<ApiResponse | null> {
|
|
@@ -374,6 +506,12 @@ export class Dmart {
|
|
|
374
506
|
});
|
|
375
507
|
}
|
|
376
508
|
|
|
509
|
+
/**
|
|
510
|
+
* Generates a URL for accessing attachment resources
|
|
511
|
+
* @param request - GetAttachmentURLRequest containing attachment identification parameters
|
|
512
|
+
* @param scope - The scope for the attachment URL (default: DmartScope.managed)
|
|
513
|
+
* @returns String URL for accessing the attachment
|
|
514
|
+
*/
|
|
377
515
|
public static getAttachmentUrl(
|
|
378
516
|
request: GetAttachmentURLRequest,
|
|
379
517
|
scope: string = DmartScope.managed
|
|
@@ -384,6 +522,12 @@ export class Dmart {
|
|
|
384
522
|
)}/${request.parent_shortname}/${request.shortname}${request.ext === null ? "" : `.${request.ext}`}`;
|
|
385
523
|
}
|
|
386
524
|
|
|
525
|
+
/**
|
|
526
|
+
* Retrieves health information and statistics for a specific space
|
|
527
|
+
* @param space_name - The name of the space to check health for
|
|
528
|
+
* @returns Promise resolving to ApiQueryResponse with health data and folders report
|
|
529
|
+
* @throws Error if health check fails
|
|
530
|
+
*/
|
|
387
531
|
public static async getSpaceHealth(space_name: string) {
|
|
388
532
|
try {
|
|
389
533
|
const {data} = await Dmart.axiosDmartInstance.get<
|
|
@@ -395,6 +539,13 @@ export class Dmart {
|
|
|
395
539
|
}
|
|
396
540
|
}
|
|
397
541
|
|
|
542
|
+
/**
|
|
543
|
+
* Retrieves payload data for a specific resource
|
|
544
|
+
* @param request - GetPayloadRequest containing payload identification parameters
|
|
545
|
+
* @param scope - The scope for the payload retrieval (default: DmartScope.managed)
|
|
546
|
+
* @returns Promise resolving to payload data
|
|
547
|
+
* @throws Error if payload retrieval fails
|
|
548
|
+
*/
|
|
398
549
|
public static async getPayload(
|
|
399
550
|
request: GetPayloadRequest,
|
|
400
551
|
scope: string = DmartScope.managed
|
|
@@ -416,6 +567,12 @@ export class Dmart {
|
|
|
416
567
|
}
|
|
417
568
|
}
|
|
418
569
|
|
|
570
|
+
/**
|
|
571
|
+
* Updates the progress of a ticket with resolution and comments
|
|
572
|
+
* @param request - ProgressTicketRequest containing ticket identification and update data
|
|
573
|
+
* @returns Promise resolving to ApiQueryResponse with progress update result
|
|
574
|
+
* @throws Error if ticket progress update fails
|
|
575
|
+
*/
|
|
419
576
|
public static async progressTicket(
|
|
420
577
|
request: ProgressTicketRequest
|
|
421
578
|
) {
|
|
@@ -440,6 +597,12 @@ export class Dmart {
|
|
|
440
597
|
}
|
|
441
598
|
}
|
|
442
599
|
|
|
600
|
+
/**
|
|
601
|
+
* Submits data to a public endpoint with optional workflow processing
|
|
602
|
+
* @param request - SubmitRequest containing submission data and routing information
|
|
603
|
+
* @returns Promise resolving to submission response data
|
|
604
|
+
* @throws Error if submission fails
|
|
605
|
+
*/
|
|
443
606
|
public static async submit(
|
|
444
607
|
request: SubmitRequest
|
|
445
608
|
) {
|
|
@@ -463,6 +626,11 @@ export class Dmart {
|
|
|
463
626
|
}
|
|
464
627
|
}
|
|
465
628
|
|
|
629
|
+
/**
|
|
630
|
+
* Retrieves the system manifest containing configuration and metadata
|
|
631
|
+
* @returns Promise resolving to manifest data
|
|
632
|
+
* @throws Error if manifest retrieval fails
|
|
633
|
+
*/
|
|
466
634
|
public static async getManifest() {
|
|
467
635
|
try {
|
|
468
636
|
const {data} = await Dmart.axiosDmartInstance.get<any>(`info/manifest`, {
|
|
@@ -474,6 +642,11 @@ export class Dmart {
|
|
|
474
642
|
}
|
|
475
643
|
}
|
|
476
644
|
|
|
645
|
+
/**
|
|
646
|
+
* Retrieves the system settings and configuration
|
|
647
|
+
* @returns Promise resolving to settings data
|
|
648
|
+
* @throws Error if settings retrieval fails
|
|
649
|
+
*/
|
|
477
650
|
public static async getSettings() {
|
|
478
651
|
try {
|
|
479
652
|
const {data} = await Dmart.axiosDmartInstance.get<any>(`info/settings`, {
|
|
@@ -485,6 +658,13 @@ export class Dmart {
|
|
|
485
658
|
}
|
|
486
659
|
}
|
|
487
660
|
|
|
661
|
+
/**
|
|
662
|
+
* Sends an OTP (One-Time Password) request to a user
|
|
663
|
+
* @param request - SendOTPRequest containing recipient information
|
|
664
|
+
* @param acceptLanguage - Optional language preference for the OTP message (default: null)
|
|
665
|
+
* @returns Promise resolving to ApiResponse with OTP request result
|
|
666
|
+
* @throws Error if OTP request fails
|
|
667
|
+
*/
|
|
488
668
|
public static async otpRequest(
|
|
489
669
|
request: SendOTPRequest,
|
|
490
670
|
acceptLanguage: string | null = null
|
|
@@ -506,6 +686,13 @@ export class Dmart {
|
|
|
506
686
|
}
|
|
507
687
|
}
|
|
508
688
|
|
|
689
|
+
/**
|
|
690
|
+
* Sends an OTP (One-Time Password) request for login purposes
|
|
691
|
+
* @param request - SendOTPRequest containing recipient information for login OTP
|
|
692
|
+
* @param acceptLanguage - Optional language preference for the OTP message (default: null)
|
|
693
|
+
* @returns Promise resolving to ApiResponse with OTP login request result
|
|
694
|
+
* @throws Error if OTP login request fails
|
|
695
|
+
*/
|
|
509
696
|
public static async otpRequestLogin(
|
|
510
697
|
request: SendOTPRequest,
|
|
511
698
|
acceptLanguage: string | null = null
|
|
@@ -527,6 +714,12 @@ export class Dmart {
|
|
|
527
714
|
}
|
|
528
715
|
}
|
|
529
716
|
|
|
717
|
+
/**
|
|
718
|
+
* Initiates a password reset request for a user
|
|
719
|
+
* @param request - PasswordResetRequest containing user identification for password reset
|
|
720
|
+
* @returns Promise resolving to ApiResponse with password reset request result
|
|
721
|
+
* @throws Error if password reset request fails
|
|
722
|
+
*/
|
|
530
723
|
public static async passwordResetRequest(request: PasswordResetRequest) {
|
|
531
724
|
try {
|
|
532
725
|
const {data} = await Dmart.axiosDmartInstance.post<ApiResponse>(
|
|
@@ -540,6 +733,12 @@ export class Dmart {
|
|
|
540
733
|
}
|
|
541
734
|
}
|
|
542
735
|
|
|
736
|
+
/**
|
|
737
|
+
* Confirms an OTP (One-Time Password) code provided by the user
|
|
738
|
+
* @param request - ConfirmOTPRequest containing the OTP code and verification details
|
|
739
|
+
* @returns Promise resolving to ApiResponse with OTP confirmation result
|
|
740
|
+
* @throws Error if OTP confirmation fails
|
|
741
|
+
*/
|
|
543
742
|
public static async confirmOtp(request: ConfirmOTPRequest) {
|
|
544
743
|
try {
|
|
545
744
|
const {data} = await Dmart.axiosDmartInstance.post<ApiResponse>(
|
|
@@ -553,6 +752,12 @@ export class Dmart {
|
|
|
553
752
|
}
|
|
554
753
|
}
|
|
555
754
|
|
|
755
|
+
/**
|
|
756
|
+
* Resets a user's account or session state
|
|
757
|
+
* @param shortname - The shortname (username) of the user to reset
|
|
758
|
+
* @returns Promise resolving to ApiResponse with user reset result
|
|
759
|
+
* @throws Error if user reset fails
|
|
760
|
+
*/
|
|
556
761
|
public static async userReset(shortname: string) {
|
|
557
762
|
try {
|
|
558
763
|
const {data} = await Dmart.axiosDmartInstance.post<ApiResponse>(
|
|
@@ -566,6 +771,12 @@ export class Dmart {
|
|
|
566
771
|
}
|
|
567
772
|
}
|
|
568
773
|
|
|
774
|
+
/**
|
|
775
|
+
* Validates a password against system password policies and requirements
|
|
776
|
+
* @param password - The password string to validate
|
|
777
|
+
* @returns Promise resolving to ApiResponse with validation result
|
|
778
|
+
* @throws Error if password validation fails
|
|
779
|
+
*/
|
|
569
780
|
public static async validatePassword(password: string) {
|
|
570
781
|
try {
|
|
571
782
|
const {data} = await Dmart.axiosDmartInstance.post<ApiResponse>(
|