@edraj/tsdmart 2.8.0 → 4.0.0

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 CHANGED
@@ -1,22 +1,28 @@
1
1
  import {AxiosInstance} from "axios";
2
2
  import {
3
- ActionRequest, ActionRequestRecord,
4
- ActionResponse,
5
- ApiQueryResponse,
6
- ApiResponse,
7
- ConfirmOTPRequest,
8
- ContentType,
9
- headers,
10
- LoginResponse,
11
- PasswordResetRequest,
12
- ProfileResponse,
13
- QueryRequest,
14
- QueryType,
15
- ResourceType,
16
- ResponseEntry,
17
- SendOTPRequest,
18
- SortyType,
19
- Status,
3
+ ActionRequest,
4
+ ActionRequestRecord,
5
+ ActionResponse,
6
+ ApiQueryResponse,
7
+ ApiResponse,
8
+ ConfirmOTPRequest,
9
+ FetchDataAssetRequest,
10
+ GetAttachmentURLRequest,
11
+ GetChildrenRequest,
12
+ GetPayloadRequest,
13
+ headers,
14
+ LoginResponse,
15
+ PasswordResetRequest,
16
+ ProfileResponse, ProgressTicketRequest,
17
+ QueryRequest,
18
+ QueryType,
19
+ ResourcesFromCSVRequest,
20
+ ResponseEntry,
21
+ RetrieveEntryRequest,
22
+ SendOTPRequest,
23
+ SortyType,
24
+ Status, SubmitRequest,
25
+ UploadWithPayloadRequest,
20
26
  } from "./dmart.model";
21
27
 
22
28
 
@@ -58,553 +64,518 @@ export class Dmart {
58
64
  headers["Authorization"] = `Bearer ${token}`;
59
65
  }
60
66
 
61
- public static async login(shortname: string, password: string) {
62
- const response = await Dmart.axiosDmartInstance.post<LoginResponse>(
63
- `user/login`,
64
- { shortname, password },
65
- { headers }
66
- );
67
- const data: LoginResponse = response.data;
68
- if (data.status == Status.success && data.records.length > 0) {
69
- headers["Authorization"] =
70
- "Bearer " + data.records[0]?.attributes.access_token;
71
- }
72
- return data;
73
- }
74
-
75
- public static async loginBy(credentials: any, password: string) {
76
- try {
77
- const response = await Dmart.axiosDmartInstance.post<LoginResponse>(
78
- `user/login`,
79
- { ...credentials, password },
80
- { headers }
81
- );
82
- const data: LoginResponse = response.data;
83
- if (data.status == Status.success && data.records.length > 0) {
84
- headers["Authorization"] =
85
- "Bearer " + data.records[0]?.attributes.access_token;
86
- }
87
- return data;
88
- } catch (error: any) {
89
- throw error;
90
- }
91
- }
92
-
93
- public static async logout() {
94
- try {
95
- const { data } = await Dmart.axiosDmartInstance.post<ApiResponse>(
96
- `user/logout`,
97
- {},
98
- { headers }
99
- );
100
- return data;
101
- } catch (error: any) {
102
- throw error;
103
- }
104
- }
105
-
106
- public static async create_user(request: ActionRequestRecord) {
107
- try {
108
- const { data } = await Dmart.axiosDmartInstance.post<ActionResponse>(
109
- `user/create`,
110
- request,
111
- { headers }
112
- );
113
- return data;
114
- } catch (error: any) {
115
- throw error;
116
- }
117
- }
118
-
119
- public static async update_user(request: ActionRequestRecord) {
120
- try {
121
- const { data } = await Dmart.axiosDmartInstance.post<ActionResponse>(
122
- `user/profile`,
123
- request,
124
- { headers }
125
- );
126
- return data;
127
- } catch (error: any) {
128
- throw error;
129
- }
130
- }
131
-
132
- public static async check_existing(prop: string, value: string) {
133
- try {
134
- const { data } = await Dmart.axiosDmartInstance.get<ResponseEntry>(
135
- `user/check-existing?${prop}=${value}`,
136
- { headers }
137
- );
138
- return data;
139
- } catch (error: any) {
140
- throw error;
141
- }
142
- }
143
-
144
- public static async get_profile() {
145
- try {
146
- const { data } = await Dmart.axiosDmartInstance.get<ProfileResponse>(`user/profile`, {
147
- headers,
148
- });
149
- if (typeof localStorage !== "undefined" && data.status === "success") {
150
- localStorage.setItem(
151
- "permissions",
152
- JSON.stringify((data?.records ?? [{}])[0]?.attributes.permissions)
67
+ public static async login(shortname: string, password: string) {
68
+ const response = await Dmart.axiosDmartInstance.post<LoginResponse>(
69
+ `user/login`,
70
+ {shortname, password},
71
+ {headers}
153
72
  );
154
- localStorage.setItem(
155
- "roles",
156
- JSON.stringify((data?.records ?? [{}])[0]?.attributes?.["roles"])
157
- );
158
- }
159
- return data;
160
- } catch (error: any) {
161
- throw error;
162
- }
163
- }
164
-
165
- public static async query(
166
- query: QueryRequest,
167
- scope: string = "managed"
168
- ): Promise<ApiQueryResponse | null> {
169
- try {
170
- if (query.type != QueryType.spaces) {
171
- query.sort_type = query.sort_type || SortyType.ascending;
172
- query.sort_by = query.sort_by || "created_at";
173
- }
174
- query.subpath = query.subpath.replace(/\/+/g, "/");
175
- const { data } = await Dmart.axiosDmartInstance.post<ApiQueryResponse>(
176
- `${scope}/query`,
177
- query,
178
- { headers }
179
- );
180
- return data;
181
- } catch (error: any) {
182
- throw error;
183
- }
184
- }
185
-
186
- public static async csv(query: any): Promise<ApiQueryResponse> {
187
- try {
188
- query.sort_type = query.sort_type || SortyType.ascending;
189
- query.sort_by = "created_at";
190
- query.subpath = query.subpath.replace(/\/+/g, "/");
191
- const { data } = await Dmart.axiosDmartInstance.post<ApiQueryResponse>(
192
- `managed/csv`,
193
- query,
194
- { headers }
195
- );
196
- return data;
197
- } catch (error: any) {
198
- throw error;
199
- }
200
- }
201
-
202
- public static async resources_from_csv(
203
- space_name: string,
204
- subpath: string,
205
- resourceType: ResourceType,
206
- schema: string,
207
- payload: File,
208
- ){
209
- try {
210
- let csvUrl = `/managed/resources_from_csv/${resourceType}/${space_name}/${subpath}`;
211
-
212
- if(schema){
213
- csvUrl += `/${schema}`;
214
- }
215
-
216
- let formdata = new FormData();
217
- formdata.append("resources_file", payload);
218
-
219
- const headers = {"Content-Type": "multipart/form-data"};
220
-
221
- const {data} = await Dmart.axiosDmartInstance.post<ApiResponse>(
222
- csvUrl,
223
- formdata,
224
- {headers}
225
- );
226
-
227
- return data;
228
- } catch (error) {
229
- return error;
230
- }
231
- }
232
-
233
-
234
- public static async space(action: ActionRequest): Promise<ActionResponse> {
235
- try {
236
- const { data } = await Dmart.axiosDmartInstance.post<ActionResponse>(
237
- `managed/space`,
238
- action,
239
- { headers }
240
- );
241
- return data;
242
- } catch (error: any) {
243
- throw error;
244
- }
245
- }
246
-
247
- public static async request(action: ActionRequest): Promise<ActionResponse> {
248
- const res = await Dmart.axiosDmartInstance.post<ActionResponse>(`managed/request`, action, {
249
- headers,
250
- });
251
- return res?.data;
252
- }
253
-
254
- public static async retrieve_entry(
255
- resource_type: ResourceType,
256
- space_name: string,
257
- subpath: string,
258
- shortname: string,
259
- retrieve_json_payload: boolean = false,
260
- retrieve_attachments: boolean = false,
261
- validate_schema: boolean = true,
262
- scope: string = "managed"
263
- ): Promise<ResponseEntry | null> {
264
- try {
265
- if (!subpath || subpath == "/") subpath = "__root__";
266
- const url = `${scope}/entry/${resource_type}/${space_name}/${subpath}/${shortname}?retrieve_json_payload=${retrieve_json_payload}&retrieve_attachments=${retrieve_attachments}&validate_schema=${validate_schema}`;
267
- const { data } = await Dmart.axiosDmartInstance.get<ResponseEntry>(
268
- `${url.replace(/\/+/g, "/")}`,
269
- { headers }
270
- );
271
- return data;
272
- } catch (error: any) {
273
- throw error;
274
- }
275
- }
276
-
277
-
278
-
279
- public static async upload_with_payload(
280
- space_name: string,
281
- subpath: string,
282
- shortname: string,
283
- resource_type: ResourceType,
284
- payload_file: File,
285
- content_type?: ContentType,
286
- schema_shortname?: string,
287
- scope: string = "managed"
288
- ): Promise<ApiResponse> {
289
- const request_record_body: any = {
290
- resource_type,
291
- subpath,
292
- shortname,
293
- attributes: { is_active: true, payload: { body: {} } },
294
- };
295
- if (content_type) {
296
- request_record_body.attributes.payload.content_type = content_type;
297
- }
298
- if (schema_shortname) {
299
- request_record_body.attributes.payload.schema_shortname =
300
- schema_shortname;
301
- }
302
-
303
- const request_record = new Blob([JSON.stringify(request_record_body)], {
304
- type: "application/json",
305
- });
306
-
307
- const form_data = new FormData();
308
- form_data.append("space_name", space_name);
309
- form_data.append("request_record", request_record);
310
- form_data.append("payload_file", payload_file);
311
-
312
- const headers = { "Content-Type": "multipart/form-data" };
313
-
314
- try {
315
- const { data } = await Dmart.axiosDmartInstance.post<ApiResponse>(
316
- `${scope}/resource_with_payload`,
317
- form_data,
318
- { headers }
319
- );
320
-
321
- return data;
322
- } catch (error: any) {
323
- throw error;
324
- }
325
- }
326
-
327
- public static async fetchDataAsset(
328
- resourceType: string,
329
- dataAssetType: string,
330
- spaceName: string,
331
- subpath: string,
332
- shortname: string,
333
- query_string?: string,
334
- filter_data_assets?: string[]
335
- ) {
336
- try {
337
- const { data } = await Dmart.axiosDmartInstance.post(
338
- 'managed/data-asset',
339
- {
340
- space_name: spaceName,
341
- resource_type: resourceType,
342
- data_asset_type: dataAssetType,
343
- subpath,
344
- shortname,
345
- query_string: query_string ?? "SELECT * FROM file",
346
- filter_data_assets,
347
- },
348
- { headers }
349
- );
350
- return data;
351
- } catch (error: any) {
352
- throw error;
353
- }
354
- }
355
-
356
- public static async get_spaces(): Promise<ApiResponse | null> {
357
- return await this.query({
358
- type: QueryType.spaces,
359
- space_name: "management",
360
- subpath: "/",
361
- search: "",
362
- limit: 100,
363
- });
364
- }
365
-
366
- public static async get_children(
367
- space_name: string,
368
- subpath: string,
369
- limit: number = 20,
370
- offset: number = 0,
371
- restrict_types: Array<ResourceType> = []
372
- ): Promise<ApiResponse | null> {
373
- return await this.query({
374
- type: QueryType.search,
375
- space_name: space_name,
376
- subpath: subpath,
377
- filter_types: restrict_types,
378
- exact_subpath: true,
379
- search: "",
380
- limit: limit,
381
- offset: offset,
382
- });
383
- }
384
-
385
- public static get_attachment_url(
386
- resource_type: ResourceType,
387
- space_name: string,
388
- subpath: string,
389
- parent_shortname: string,
390
- shortname: string,
391
- ext: string | null = null,
392
- scope: string = "managed"
393
- ) {
394
- return `${Dmart.axiosDmartInstance.defaults.baseURL}/${scope}/payload/${resource_type}/${space_name}/${subpath.replace(
395
- /\/+$/,
396
- ""
397
- )}/${parent_shortname}/${shortname}${ext === null ? "" : `.${ext}`}`;
398
- }
399
-
400
- public static async get_space_health(space_name: string) {
401
- try {
402
- const { data } = await Dmart.axiosDmartInstance.get<
403
- ApiQueryResponse & { attributes: { folders_report: Object } }
404
- >(`managed/health/${space_name}`, { headers });
405
- return data;
406
- } catch (error: any) {
407
- throw error;
408
- }
409
- }
410
-
411
- // TODO: update to enums
412
- public static async get_payload(
413
- resource_type: string,
414
- space_name: string,
415
- subpath: string,
416
- shortname: string,
417
- schemaShortname: string|null = null,
418
- ext: string = "json",
419
- scope: string = "managed"
420
- ) {
421
- try {
422
- let url = `${scope}/payload/${resource_type}/${space_name}/${subpath}/${shortname}`;
423
-
424
- if(schemaShortname){
425
- url += `.${schemaShortname}`
426
- }
427
- url += `.${ext}`
428
- const { data } = await Dmart.axiosDmartInstance.get<any>(
429
- url,
430
- { headers }
431
- );
432
- return data;
433
- } catch (error: any) {
434
- throw error;
435
- }
436
- }
437
-
438
- public static async progress_ticket(
439
- space_name: string,
440
- subpath: string,
441
- shortname: string,
442
- action: string,
443
- resolution?: string,
444
- comment?: string
445
- ) {
446
- try {
447
- const payload: any = {};
448
- if (resolution) {
449
- payload.resolution = resolution;
450
- }
451
- if (comment) {
452
- payload.comment = comment;
453
- }
454
- const { data } = await Dmart.axiosDmartInstance.put<
455
- ApiQueryResponse & { attributes: { folders_report: Object } }
456
- >(
457
- `managed/progress-ticket/${space_name}/${subpath}/${shortname}/${action}`,
458
- payload,
459
- { headers }
460
- );
461
- return data;
462
- } catch (error: any) {
463
- throw error;
464
- }
465
- }
466
-
467
- public static async submit(
468
- spaceName: string,
469
- schemaShortname: string,
470
- subpath: string,
471
- record: any,
472
- resourceType?: string,
473
- workflowShortname?: string,
474
- ) {
475
- try {
476
- var url = `public/submit/${spaceName}`;
477
- if (resourceType) {
478
- url += `/${resourceType}`;
73
+ const data: LoginResponse = response.data;
74
+ if (data.status == Status.success && data.records.length > 0) {
75
+ headers["Authorization"] =
76
+ "Bearer " + data.records[0]?.attributes.access_token;
77
+ }
78
+ return data;
79
+ }
80
+
81
+ public static async loginBy(credentials: any, password: string) {
82
+ try {
83
+ const response = await Dmart.axiosDmartInstance.post<LoginResponse>(
84
+ `user/login`,
85
+ {...credentials, password},
86
+ {headers}
87
+ );
88
+ const data: LoginResponse = response.data;
89
+ if (data.status == Status.success && data.records.length > 0) {
90
+ headers["Authorization"] =
91
+ "Bearer " + data.records[0]?.attributes.access_token;
92
+ }
93
+ return data;
94
+ } catch (error: any) {
95
+ throw error;
96
+ }
97
+ }
98
+
99
+ public static async logout() {
100
+ try {
101
+ const {data} = await Dmart.axiosDmartInstance.post<ApiResponse>(
102
+ `user/logout`,
103
+ {},
104
+ {headers}
105
+ );
106
+ return data;
107
+ } catch (error: any) {
108
+ throw error;
109
+ }
110
+ }
111
+
112
+ public static async createUser(request: ActionRequestRecord) {
113
+ try {
114
+ const {data} = await Dmart.axiosDmartInstance.post<ActionResponse>(
115
+ `user/create`,
116
+ request,
117
+ {headers}
118
+ );
119
+ return data;
120
+ } catch (error: any) {
121
+ throw error;
122
+ }
123
+ }
124
+
125
+ public static async updateUser(request: ActionRequestRecord) {
126
+ try {
127
+ const {data} = await Dmart.axiosDmartInstance.post<ActionResponse>(
128
+ `user/profile`,
129
+ request,
130
+ {headers}
131
+ );
132
+ return data;
133
+ } catch (error: any) {
134
+ throw error;
135
+ }
136
+ }
137
+
138
+ public static async checkExisting(prop: string, value: string) {
139
+ try {
140
+ const {data} = await Dmart.axiosDmartInstance.get<ResponseEntry>(
141
+ `user/check-existing?${prop}=${value}`,
142
+ {headers}
143
+ );
144
+ return data;
145
+ } catch (error: any) {
146
+ throw error;
147
+ }
148
+ }
149
+
150
+ public static async getProfile() {
151
+ try {
152
+ const {data} = await Dmart.axiosDmartInstance.get<ProfileResponse>(`user/profile`, {
153
+ headers,
154
+ });
155
+ if (typeof localStorage !== "undefined" && data.status === "success") {
156
+ localStorage.setItem(
157
+ "permissions",
158
+ JSON.stringify((data?.records ?? [{}])[0]?.attributes.permissions)
159
+ );
160
+ localStorage.setItem(
161
+ "roles",
162
+ JSON.stringify((data?.records ?? [{}])[0]?.attributes?.["roles"])
163
+ );
164
+ }
165
+ return data;
166
+ } catch (error: any) {
167
+ throw error;
168
+ }
169
+ }
170
+
171
+ public static async query(
172
+ query: QueryRequest,
173
+ scope: string = "managed"
174
+ ): Promise<ApiQueryResponse | null> {
175
+ try {
176
+ if (query.type != QueryType.spaces) {
177
+ query.sort_type = query.sort_type || SortyType.ascending;
178
+ query.sort_by = query.sort_by || "created_at";
179
+ }
180
+ query.subpath = query.subpath.replace(/\/+/g, "/");
181
+ const {data} = await Dmart.axiosDmartInstance.post<ApiQueryResponse>(
182
+ `${scope}/query`,
183
+ query,
184
+ {headers}
185
+ );
186
+ return data;
187
+ } catch (error: any) {
188
+ throw error;
189
+ }
190
+ }
191
+
192
+ public static async csv(query: any): Promise<ApiQueryResponse> {
193
+ try {
194
+ query.sort_type = query.sort_type || SortyType.ascending;
195
+ query.sort_by = "created_at";
196
+ query.subpath = query.subpath.replace(/\/+/g, "/");
197
+ const {data} = await Dmart.axiosDmartInstance.post<ApiQueryResponse>(
198
+ `managed/csv`,
199
+ query,
200
+ {headers}
201
+ );
202
+ return data;
203
+ } catch (error: any) {
204
+ throw error;
205
+ }
206
+ }
207
+
208
+ public static async resourcesFromCsv(
209
+ request: ResourcesFromCSVRequest
210
+ ) {
211
+ try {
212
+ let csvUrl = `/managed/resources_from_csv/${request.resourceType}/${request.space_name}/${request.subpath}`;
213
+
214
+ if (request.schema) {
215
+ csvUrl += `/${request.schema}`;
216
+ }
217
+
218
+ let formdata = new FormData();
219
+ formdata.append("resources_file", request.payload);
220
+
221
+ const headers = {"Content-Type": "multipart/form-data"};
222
+
223
+ const {data} = await Dmart.axiosDmartInstance.post<ApiResponse>(
224
+ csvUrl,
225
+ formdata,
226
+ {headers}
227
+ );
228
+
229
+ return data;
230
+ } catch (error) {
231
+ return error;
232
+ }
233
+ }
234
+
235
+
236
+ public static async space(action: ActionRequest): Promise<ActionResponse> {
237
+ try {
238
+ const {data} = await Dmart.axiosDmartInstance.post<ActionResponse>(
239
+ `managed/space`,
240
+ action,
241
+ {headers}
242
+ );
243
+ return data;
244
+ } catch (error: any) {
245
+ throw error;
246
+ }
247
+ }
248
+
249
+ public static async request(action: ActionRequest): Promise<ActionResponse> {
250
+ const res = await Dmart.axiosDmartInstance.post<ActionResponse>(`managed/request`, action, {
251
+ headers,
252
+ });
253
+ return res?.data;
254
+ }
255
+
256
+ public static async retrieveEntry(
257
+ request: RetrieveEntryRequest,
258
+ scope: string = "managed"
259
+ ): Promise<ResponseEntry | null> {
260
+ try {
261
+ if (request.validate_schema === null) {
262
+ request.validate_schema = true;
263
+ }
264
+ if (!request.subpath || request.subpath == "/") request.subpath = "__root__";
265
+ 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}`;
266
+ const {data} = await Dmart.axiosDmartInstance.get<ResponseEntry>(
267
+ `${url.replace(/\/+/g, "/")}`,
268
+ {headers}
269
+ );
270
+ return data;
271
+ } catch (error: any) {
272
+ throw error;
273
+ }
274
+ }
275
+
276
+
277
+ public static async uploadWithPayload(
278
+ request: UploadWithPayloadRequest,
279
+ scope: string = "managed"
280
+ ) {
281
+ const request_record_body: any = {
282
+ resource_type: request.resource_type,
283
+ subpath: request.subpath,
284
+ shortname: request.shortname,
285
+ attributes: request.attributes,
286
+ };
287
+
288
+ if (request.attributes !== null && Object.keys(request.attributes!).length === 0) {
289
+ request_record_body.attributes = {is_active: true, payload: {body: {}}};
290
+ } else {
291
+ if (!Object.keys(request.attributes!).includes('is_active')) {
292
+ request_record_body.attributes.is_active = true;
293
+ }
294
+ }
295
+
296
+ const request_record = new Blob([JSON.stringify(request_record_body)], {
297
+ type: "application/json",
298
+ });
299
+
300
+ const form_data = new FormData();
301
+ form_data.append("space_name", request.space_name);
302
+ form_data.append("request_record", request_record);
303
+ form_data.append("payload_file", request.payload_file);
304
+
305
+ const headers = {"Content-Type": "multipart/form-data"};
306
+
307
+ try {
308
+ const {data} = await Dmart.axiosDmartInstance.post<ApiResponse>(
309
+ `${scope}/resource_with_payload`,
310
+ form_data,
311
+ {headers}
312
+ );
313
+
314
+ return data;
315
+ } catch (error: any) {
316
+ throw error;
317
+ }
318
+ }
319
+
320
+ public static async fetchDataAsset(
321
+ request: FetchDataAssetRequest,
322
+ ) {
323
+ try {
324
+ const {data} = await Dmart.axiosDmartInstance.post(
325
+ 'managed/data-asset',
326
+ {
327
+ space_name: request.spaceName,
328
+ resource_type: request.resourceType,
329
+ data_asset_type: request.dataAssetType,
330
+ subpath: request.subpath,
331
+ shortname: request.shortname,
332
+ query_string: request.query_string ?? "SELECT * FROM file",
333
+ filter_data_assets: request.filter_data_assets,
334
+ },
335
+ {headers}
336
+ );
337
+ return data;
338
+ } catch (error: any) {
339
+ throw error;
340
+ }
341
+ }
342
+
343
+ public static async getSpaces(): Promise<ApiResponse | null> {
344
+ return await this.query({
345
+ type: QueryType.spaces,
346
+ space_name: "management",
347
+ subpath: "/",
348
+ search: "",
349
+ limit: 100,
350
+ });
351
+ }
352
+
353
+ public static async getChildren(
354
+ request: GetChildrenRequest
355
+ ): Promise<ApiResponse | null> {
356
+ if(request.limit === null){
357
+ request.limit = 20
358
+ }
359
+ if(request.offset === null){
360
+ request.offset = 0
361
+ }
362
+ if(request.restrict_types === null){
363
+ request.restrict_types = []
364
+ }
365
+ return await this.query({
366
+ type: QueryType.search,
367
+ space_name: request.space_name,
368
+ subpath: request.subpath,
369
+ filter_types: request.restrict_types,
370
+ exact_subpath: true,
371
+ search: request.search,
372
+ limit: request.limit,
373
+ offset: request.offset,
374
+ });
375
+ }
376
+
377
+ public static getAttachmentUrl(
378
+ request: GetAttachmentURLRequest,
379
+ scope: string = "managed"
380
+ ) {
381
+ return `${Dmart.axiosDmartInstance.defaults.baseURL}/${scope}/payload/${request.resource_type}/${request.space_name}/${request.subpath.replace(
382
+ /\/+$/,
383
+ ""
384
+ )}/${request.parent_shortname}/${request.shortname}${request.ext === null ? "" : `.${request.ext}`}`;
385
+ }
386
+
387
+ public static async getSpaceHealth(space_name: string) {
388
+ try {
389
+ const {data} = await Dmart.axiosDmartInstance.get<
390
+ ApiQueryResponse & { attributes: { folders_report: Object } }
391
+ >(`managed/health/${space_name}`, {headers});
392
+ return data;
393
+ } catch (error: any) {
394
+ throw error;
395
+ }
396
+ }
397
+
398
+ public static async getPayload(
399
+ request: GetPayloadRequest,
400
+ scope: string = "managed"
401
+ ) {
402
+ try {
403
+ let url = `${scope}/payload/${request.resource_type}/${request.space_name}/${request.subpath}/${request.shortname}`;
404
+
405
+ if (request.schemaShortname) {
406
+ url += `.${request.schemaShortname}`
407
+ }
408
+ url += `.${request.ext}`
409
+ const {data} = await Dmart.axiosDmartInstance.get<any>(
410
+ url,
411
+ {headers}
412
+ );
413
+ return data;
414
+ } catch (error: any) {
415
+ throw error;
416
+ }
417
+ }
418
+
419
+ public static async progressTicket(
420
+ request: ProgressTicketRequest
421
+ ) {
422
+ try {
423
+ const payload: any = {};
424
+ if (request.resolution) {
425
+ payload.resolution = request.resolution;
426
+ }
427
+ if (request.comment) {
428
+ payload.comment = request.comment;
429
+ }
430
+ const {data} = await Dmart.axiosDmartInstance.put<
431
+ ApiQueryResponse & { attributes: { folders_report: Object } }
432
+ >(
433
+ `managed/progress-ticket/${request.space_name}/${request.subpath}/${request.shortname}/${request.action}`,
434
+ payload,
435
+ {headers}
436
+ );
437
+ return data;
438
+ } catch (error: any) {
439
+ throw error;
440
+ }
441
+ }
442
+
443
+ public static async submit(
444
+ request: SubmitRequest
445
+ ) {
446
+ try {
447
+ var url = `public/submit/${request.spaceName}`;
448
+ if (request.resourceType) {
449
+ url += `/${request.resourceType}`;
450
+ }
451
+ if (request.workflowShortname) {
452
+ url += `/${request.workflowShortname}`;
453
+ }
454
+ url += `/${request.schemaShortname}/${request.subpath}`;
455
+ const {data} = await Dmart.axiosDmartInstance.post(
456
+ url,
457
+ request.record,
458
+ {headers}
459
+ );
460
+ return data;
461
+ } catch (error: any) {
462
+ throw error;
463
+ }
464
+ }
465
+
466
+ public static async get_manifest() {
467
+ try {
468
+ const {data} = await Dmart.axiosDmartInstance.get<any>(`info/manifest`, {
469
+ headers,
470
+ });
471
+ return data;
472
+ } catch (error: any) {
473
+ throw error;
474
+ }
475
+ }
476
+
477
+ public static async get_settings() {
478
+ try {
479
+ const {data} = await Dmart.axiosDmartInstance.get<any>(`info/settings`, {
480
+ headers,
481
+ });
482
+ return data;
483
+ } catch (error: any) {
484
+ throw error;
485
+ }
486
+ }
487
+
488
+ public static async otpRequest(
489
+ request: SendOTPRequest,
490
+ acceptLanguage: string | null = null
491
+ ) {
492
+ try {
493
+ const requestHeaders = {...headers};
494
+ if (acceptLanguage) {
495
+ requestHeaders['Accept-Language'] = acceptLanguage;
496
+ }
497
+
498
+ const {data} = await Dmart.axiosDmartInstance.post<ApiResponse>(
499
+ `user/otp-request`,
500
+ request,
501
+ {headers: requestHeaders}
502
+ );
503
+ return data;
504
+ } catch (error: any) {
505
+ throw error;
479
506
  }
480
- if (workflowShortname) {
481
- url += `/${workflowShortname}`;
507
+ }
508
+
509
+ public static async otpRequestLogin(
510
+ request: SendOTPRequest,
511
+ acceptLanguage: string | null = null
512
+ ) {
513
+ try {
514
+ const requestHeaders = {...headers};
515
+ if (acceptLanguage) {
516
+ requestHeaders['Accept-Language'] = acceptLanguage;
517
+ }
518
+
519
+ const {data} = await Dmart.axiosDmartInstance.post<ApiResponse>(
520
+ `user/otp-request-login`,
521
+ request,
522
+ {headers: requestHeaders}
523
+ );
524
+ return data;
525
+ } catch (error: any) {
526
+ throw error;
482
527
  }
483
- url += `/${schemaShortname}/${subpath}`;
484
- const { data } = await Dmart.axiosDmartInstance.post(
485
- url,
486
- record,
487
- { headers }
488
- );
489
- return data;
490
- } catch (error: any) {
491
- throw error;
492
- }
493
- }
494
-
495
- public static async get_manifest() {
496
- try {
497
- const { data } = await Dmart.axiosDmartInstance.get<any>(`info/manifest`, {
498
- headers,
499
- });
500
- return data;
501
- } catch (error: any) {
502
- throw error;
503
- }
504
- }
505
-
506
- public static async get_settings() {
507
- try {
508
- const { data } = await Dmart.axiosDmartInstance.get<any>(`info/settings`, {
509
- headers,
510
- });
511
- return data;
512
- } catch (error: any) {
513
- throw error;
514
- }
515
- }
516
-
517
- public static async otp_request(
518
- request: SendOTPRequest,
519
- acceptLanguage: string | null = null
520
- ) {
521
- try {
522
- const requestHeaders = { ...headers };
523
- if (acceptLanguage) {
524
- requestHeaders['Accept-Language'] = acceptLanguage;
525
- }
526
-
527
- const { data } = await Dmart.axiosDmartInstance.post<ApiResponse>(
528
- `user/otp-request`,
529
- request,
530
- { headers: requestHeaders }
531
- );
532
- return data;
533
- } catch (error: any) {
534
- throw error;
535
- }
536
- }
537
-
538
- public static async otp_request_login(
539
- request: SendOTPRequest,
540
- acceptLanguage: string | null = null
541
- ) {
542
- try {
543
- const requestHeaders = { ...headers };
544
- if (acceptLanguage) {
545
- requestHeaders['Accept-Language'] = acceptLanguage;
546
- }
547
-
548
- const { data } = await Dmart.axiosDmartInstance.post<ApiResponse>(
549
- `user/otp-request-login`,
550
- request,
551
- { headers: requestHeaders }
552
- );
553
- return data;
554
- } catch (error: any) {
555
- throw error;
556
- }
557
- }
558
-
559
- public static async password_reset_request(request: PasswordResetRequest) {
560
- try {
561
- const { data } = await Dmart.axiosDmartInstance.post<ApiResponse>(
562
- `user/password-reset-request`,
563
- request,
564
- { headers }
565
- );
566
- return data;
567
- } catch (error: any) {
568
- throw error;
569
- }
570
- }
571
-
572
- public static async confirm_otp(request: ConfirmOTPRequest) {
573
- try {
574
- const { data } = await Dmart.axiosDmartInstance.post<ApiResponse>(
575
- `user/otp-confirm`,
576
- request,
577
- { headers }
578
- );
579
- return data;
580
- } catch (error: any) {
581
- throw error;
582
- }
583
- }
584
-
585
- public static async user_reset(shortname: string) {
586
- try {
587
- const { data } = await Dmart.axiosDmartInstance.post<ApiResponse>(
588
- `user/reset`,
589
- { shortname },
590
- { headers }
591
- );
592
- return data;
593
- } catch (error: any) {
594
- throw error;
595
- }
596
- }
597
-
598
- public static async validate_password(password: string) {
599
- try {
600
- const { data } = await Dmart.axiosDmartInstance.post<ApiResponse>(
601
- `user/validate_password`,
602
- { password },
603
- { headers }
604
- );
605
- return data;
606
- } catch (error: any) {
607
- throw error;
608
- }
609
- }
528
+ }
529
+
530
+ public static async passwordResetRequest(request: PasswordResetRequest) {
531
+ try {
532
+ const {data} = await Dmart.axiosDmartInstance.post<ApiResponse>(
533
+ `user/password-reset-request`,
534
+ request,
535
+ {headers}
536
+ );
537
+ return data;
538
+ } catch (error: any) {
539
+ throw error;
540
+ }
541
+ }
542
+
543
+ public static async confirmOtp(request: ConfirmOTPRequest) {
544
+ try {
545
+ const {data} = await Dmart.axiosDmartInstance.post<ApiResponse>(
546
+ `user/otp-confirm`,
547
+ request,
548
+ {headers}
549
+ );
550
+ return data;
551
+ } catch (error: any) {
552
+ throw error;
553
+ }
554
+ }
555
+
556
+ public static async userReset(shortname: string) {
557
+ try {
558
+ const {data} = await Dmart.axiosDmartInstance.post<ApiResponse>(
559
+ `user/reset`,
560
+ {shortname},
561
+ {headers}
562
+ );
563
+ return data;
564
+ } catch (error: any) {
565
+ throw error;
566
+ }
567
+ }
568
+
569
+ public static async validatePassword(password: string) {
570
+ try {
571
+ const {data} = await Dmart.axiosDmartInstance.post<ApiResponse>(
572
+ `user/validate_password`,
573
+ {password},
574
+ {headers}
575
+ );
576
+ return data;
577
+ } catch (error: any) {
578
+ throw error;
579
+ }
580
+ }
610
581
  }