@edraj/tsdmart 1.0.0 → 1.0.1
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/index.ts +711 -0
- package/package.json +1 -1
- package/dmart.ts +0 -712
package/index.ts
CHANGED
|
@@ -0,0 +1,711 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
|
|
3
|
+
let baseURL = "http://localhost:8282";
|
|
4
|
+
|
|
5
|
+
axios.defaults.withCredentials = true;
|
|
6
|
+
|
|
7
|
+
export enum Status {
|
|
8
|
+
success = "success",
|
|
9
|
+
failed = "failed",
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type Error = {
|
|
13
|
+
type: string;
|
|
14
|
+
code: number;
|
|
15
|
+
message: string;
|
|
16
|
+
info: any;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type ApiResponseRecord = {
|
|
20
|
+
resource_type: string;
|
|
21
|
+
shortname: string;
|
|
22
|
+
branch_name?: string;
|
|
23
|
+
subpath: string;
|
|
24
|
+
attributes: Record<string, any>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type ApiResponse = {
|
|
28
|
+
status: Status;
|
|
29
|
+
error?: Error;
|
|
30
|
+
records: Array<ApiResponseRecord>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type Translation = {
|
|
34
|
+
ar: string;
|
|
35
|
+
en: string;
|
|
36
|
+
kd: string;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
enum UserType {
|
|
40
|
+
web = "web",
|
|
41
|
+
mobile = "mobile",
|
|
42
|
+
bot = "bot",
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type LoginResponseRecord = ApiResponseRecord & {
|
|
46
|
+
attributes: {
|
|
47
|
+
access_token: string;
|
|
48
|
+
type: UserType;
|
|
49
|
+
displayname: Translation;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// type LoginResponse = ApiResponse & { records : Array<LoginResponseRecord> };
|
|
54
|
+
|
|
55
|
+
type Permission = {
|
|
56
|
+
allowed_actions: Array<ActionType>;
|
|
57
|
+
conditions: Array<string>;
|
|
58
|
+
restricted_fields: Array<any>;
|
|
59
|
+
allowed_fields_values: Map<string, any>;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
enum Language {
|
|
63
|
+
arabic = "arabic",
|
|
64
|
+
english = "engligh",
|
|
65
|
+
kurdish = "kurdish",
|
|
66
|
+
french = "french",
|
|
67
|
+
turkish = "turkish",
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
type ProfileResponseRecord = ApiResponseRecord & {
|
|
71
|
+
attributes: {
|
|
72
|
+
email: string;
|
|
73
|
+
displayname: Translation;
|
|
74
|
+
type: string;
|
|
75
|
+
language: Language;
|
|
76
|
+
is_email_verified: boolean;
|
|
77
|
+
is_msisdn_verified: boolean;
|
|
78
|
+
force_password_change: boolean;
|
|
79
|
+
permissions: Record<string, Permission>;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export enum ActionType {
|
|
84
|
+
query = "query",
|
|
85
|
+
view = "view",
|
|
86
|
+
update = "update",
|
|
87
|
+
create = "create",
|
|
88
|
+
delete = "delete",
|
|
89
|
+
attach = "attach",
|
|
90
|
+
move = "move",
|
|
91
|
+
progress_ticket = "progress_ticket",
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export type ProfileResponse = ApiResponse & {
|
|
95
|
+
records: Array<ProfileResponseRecord>;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
let headers: { [key: string]: string } = {
|
|
99
|
+
"Content-type": "application/json",
|
|
100
|
+
//"Authorization": ""
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export type AggregationReducer = {
|
|
104
|
+
name: string;
|
|
105
|
+
alias: string;
|
|
106
|
+
args: Array<string>;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export type AggregationType = {
|
|
110
|
+
load: Array<string>;
|
|
111
|
+
group_by: Array<string>;
|
|
112
|
+
reducers: Array<AggregationReducer> | Array<string>;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export enum QueryType {
|
|
116
|
+
aggregation = "aggregation",
|
|
117
|
+
search = "search",
|
|
118
|
+
subpath = "subpath",
|
|
119
|
+
events = "events",
|
|
120
|
+
history = "history",
|
|
121
|
+
tags = "tags",
|
|
122
|
+
spaces = "spaces",
|
|
123
|
+
counters = "counters",
|
|
124
|
+
reports = "reports",
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export enum SortyType {
|
|
128
|
+
ascending = "ascending",
|
|
129
|
+
descending = "descending",
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// enum NotificationPriority {
|
|
133
|
+
// high = "high",
|
|
134
|
+
// medium = "medium",
|
|
135
|
+
// low = "low"
|
|
136
|
+
// };
|
|
137
|
+
|
|
138
|
+
export type QueryRequest = {
|
|
139
|
+
type: QueryType;
|
|
140
|
+
space_name: string;
|
|
141
|
+
subpath: string;
|
|
142
|
+
filter_types?: Array<ResourceType>;
|
|
143
|
+
filter_schema_names?: Array<string>;
|
|
144
|
+
filter_shortnames?: Array<string>;
|
|
145
|
+
search: string;
|
|
146
|
+
from_date?: string;
|
|
147
|
+
to_date?: string;
|
|
148
|
+
sort_by?: string;
|
|
149
|
+
sort_type?: SortyType;
|
|
150
|
+
retrieve_json_payload?: boolean;
|
|
151
|
+
retrieve_attachments?: boolean;
|
|
152
|
+
validate_schema?: boolean;
|
|
153
|
+
jq_filter?: string;
|
|
154
|
+
exact_subpath?: boolean;
|
|
155
|
+
limit?: number;
|
|
156
|
+
offset?: number;
|
|
157
|
+
aggregation_data?: AggregationType;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export enum RequestType {
|
|
161
|
+
create = "create",
|
|
162
|
+
update = "update",
|
|
163
|
+
replace = "replace",
|
|
164
|
+
delete = "delete",
|
|
165
|
+
move = "move",
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export enum ResourceAttachmentType {
|
|
169
|
+
json = "json",
|
|
170
|
+
comment = "comment",
|
|
171
|
+
media = "media",
|
|
172
|
+
relationship = "relationship",
|
|
173
|
+
alteration = "alteration",
|
|
174
|
+
csv = "csv",
|
|
175
|
+
parquet = "parquet",
|
|
176
|
+
jsonl = "jsonl",
|
|
177
|
+
sqlite = "sqlite",
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export enum ResourceType {
|
|
181
|
+
user = "user",
|
|
182
|
+
group = "group",
|
|
183
|
+
folder = "folder",
|
|
184
|
+
schema = "schema",
|
|
185
|
+
content = "content",
|
|
186
|
+
acl = "acl",
|
|
187
|
+
comment = "comment",
|
|
188
|
+
media = "media",
|
|
189
|
+
locator = "locator",
|
|
190
|
+
relationship = "relationship",
|
|
191
|
+
alteration = "alteration",
|
|
192
|
+
history = "history",
|
|
193
|
+
space = "space",
|
|
194
|
+
branch = "branch",
|
|
195
|
+
permission = "permission",
|
|
196
|
+
role = "role",
|
|
197
|
+
ticket = "ticket",
|
|
198
|
+
json = "json",
|
|
199
|
+
post = "post",
|
|
200
|
+
plugin_wrapper = "plugin_wrapper",
|
|
201
|
+
notification = "notification",
|
|
202
|
+
jsonl = "jsonl",
|
|
203
|
+
csv = "csv",
|
|
204
|
+
sqlite = "sqlite",
|
|
205
|
+
parquet = "parquet",
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export enum ContentType {
|
|
209
|
+
text = "text",
|
|
210
|
+
html = "html",
|
|
211
|
+
markdown = "markdown",
|
|
212
|
+
json = "json",
|
|
213
|
+
image = "image",
|
|
214
|
+
python = "python",
|
|
215
|
+
pdf = "pdf",
|
|
216
|
+
audio = "audio",
|
|
217
|
+
video = "video",
|
|
218
|
+
jsonl = "jsonl",
|
|
219
|
+
csv = "csv",
|
|
220
|
+
sqlite = "sqlite",
|
|
221
|
+
parquet = "parquet",
|
|
222
|
+
}
|
|
223
|
+
export enum ContentTypeMedia {
|
|
224
|
+
text = "text",
|
|
225
|
+
html = "html",
|
|
226
|
+
markdown = "markdown",
|
|
227
|
+
image = "image",
|
|
228
|
+
python = "python",
|
|
229
|
+
pdf = "pdf",
|
|
230
|
+
audio = "audio",
|
|
231
|
+
video = "video",
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
type Payload = {
|
|
235
|
+
content_type: ContentType;
|
|
236
|
+
schema_shortname?: string;
|
|
237
|
+
checksum: string;
|
|
238
|
+
body: string | Record<string, any> | any;
|
|
239
|
+
last_validated: string;
|
|
240
|
+
validation_status: "valid" | "invalid";
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
type MetaExtended = {
|
|
244
|
+
email: string;
|
|
245
|
+
msisdn: string;
|
|
246
|
+
is_email_verified: boolean;
|
|
247
|
+
is_msisdn_verified: boolean;
|
|
248
|
+
force_password_change: boolean;
|
|
249
|
+
password: string;
|
|
250
|
+
workflow_shortname: string;
|
|
251
|
+
state: string;
|
|
252
|
+
is_open: boolean;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
export type ResponseEntry = MetaExtended & {
|
|
256
|
+
uuid: string;
|
|
257
|
+
shortname: string;
|
|
258
|
+
subpath: string;
|
|
259
|
+
is_active: boolean;
|
|
260
|
+
displayname: Translation;
|
|
261
|
+
description: Translation;
|
|
262
|
+
tags: Set<string>;
|
|
263
|
+
created_at: string;
|
|
264
|
+
updated_at: string;
|
|
265
|
+
owner_shortname: string;
|
|
266
|
+
payload?: Payload;
|
|
267
|
+
relationships?: any;
|
|
268
|
+
attachments?: Object;
|
|
269
|
+
workflow_shortname?: string;
|
|
270
|
+
state?: string;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
export type ResponseRecord = {
|
|
274
|
+
resource_type: ResourceType;
|
|
275
|
+
uuid: string;
|
|
276
|
+
shortname: string;
|
|
277
|
+
subpath: string;
|
|
278
|
+
attributes: {
|
|
279
|
+
is_active: boolean;
|
|
280
|
+
displayname: Translation;
|
|
281
|
+
description: Translation;
|
|
282
|
+
tags: Set<string>;
|
|
283
|
+
created_at: string;
|
|
284
|
+
updated_at: string;
|
|
285
|
+
owner_shortname: string;
|
|
286
|
+
payload?: Payload;
|
|
287
|
+
};
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
export type ActionResponse = ApiResponse & {
|
|
291
|
+
records: Array<
|
|
292
|
+
ResponseRecord & {
|
|
293
|
+
attachments: {
|
|
294
|
+
media: Array<ResponseRecord>;
|
|
295
|
+
json: Array<ResponseRecord>;
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
>;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
type ActionRequestRecord = {
|
|
302
|
+
resource_type: ResourceType;
|
|
303
|
+
uuid?: string;
|
|
304
|
+
shortname: string;
|
|
305
|
+
subpath: string;
|
|
306
|
+
attributes: Record<string, any>;
|
|
307
|
+
attachments?: Record<ResourceType, Array<any>>;
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
export type ActionRequest = {
|
|
311
|
+
space_name: string;
|
|
312
|
+
request_type: RequestType;
|
|
313
|
+
records: Array<ActionRequestRecord>;
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
type ApiQueryResponse = ApiResponse & {
|
|
318
|
+
attributes: { total: number; returned: number };
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
export class Dmart {
|
|
322
|
+
public async login(shortname: string, password: string) {
|
|
323
|
+
const { data } = await axios.post<
|
|
324
|
+
ApiResponse & { records: Array<LoginResponseRecord> }
|
|
325
|
+
>(baseURL + "/user/login", { shortname, password }, { headers });
|
|
326
|
+
//console.log(JSON.stringify(data, null, 2));
|
|
327
|
+
// FIXME settins Authorization is only needed when the code is running on the server
|
|
328
|
+
/*headers.Authorization = "";
|
|
329
|
+
if (data.status == Status.success && data.records.length > 0) {
|
|
330
|
+
headers.Authorization = "Bearer " + data.records[0].attributes.access_token;
|
|
331
|
+
}*/
|
|
332
|
+
return data;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
public async logout() {
|
|
336
|
+
const { data } = await axios.post<ApiResponse>(
|
|
337
|
+
baseURL + "/user/logout",
|
|
338
|
+
{},
|
|
339
|
+
{ headers }
|
|
340
|
+
);
|
|
341
|
+
return data;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
public async create_user(request: any) {
|
|
345
|
+
try {
|
|
346
|
+
const { data } = await axios.post<ActionResponse>(
|
|
347
|
+
baseURL + "/user/create",
|
|
348
|
+
request,
|
|
349
|
+
{ headers }
|
|
350
|
+
);
|
|
351
|
+
return data;
|
|
352
|
+
} catch (error: any) {
|
|
353
|
+
return error.response.data;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
public async update_user(request: any) {
|
|
358
|
+
try {
|
|
359
|
+
const { data } = await axios.post<ActionResponse>(
|
|
360
|
+
baseURL + "/user/profile",
|
|
361
|
+
request,
|
|
362
|
+
{ headers }
|
|
363
|
+
);
|
|
364
|
+
return data;
|
|
365
|
+
} catch (error: any) {
|
|
366
|
+
return error.response.data;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
public async check_existing(prop: string, value: string) {
|
|
371
|
+
try {
|
|
372
|
+
const { data } = await axios.get<ResponseEntry>(
|
|
373
|
+
baseURL +
|
|
374
|
+
`/user/check-existing?${prop}=${value}`,
|
|
375
|
+
{ headers }
|
|
376
|
+
);
|
|
377
|
+
return data;
|
|
378
|
+
} catch (error: any) {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
public async get_profile() {
|
|
384
|
+
try {
|
|
385
|
+
const { data } = await axios.get<ProfileResponse>(
|
|
386
|
+
baseURL + "/user/profile",
|
|
387
|
+
{
|
|
388
|
+
headers,
|
|
389
|
+
}
|
|
390
|
+
);
|
|
391
|
+
if (typeof localStorage !== "undefined" && data.status === "success") {
|
|
392
|
+
localStorage.setItem(
|
|
393
|
+
"permissions",
|
|
394
|
+
JSON.stringify((data?.records ?? [{}])[0]?.attributes.permissions)
|
|
395
|
+
);
|
|
396
|
+
localStorage.setItem(
|
|
397
|
+
"roles",
|
|
398
|
+
JSON.stringify((data?.records ?? [{}])[0]?.attributes?.["roles"])
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
return data;
|
|
402
|
+
} catch (error: any) {
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
public async query(query: QueryRequest): Promise<ApiQueryResponse|null> {
|
|
408
|
+
try {
|
|
409
|
+
if (query.type != QueryType.spaces) {
|
|
410
|
+
query.sort_type = query.sort_type || SortyType.ascending;
|
|
411
|
+
query.sort_by = query.sort_by || "created_at";
|
|
412
|
+
}
|
|
413
|
+
query.subpath = query.subpath.replace(/\/+/g, "/");
|
|
414
|
+
const { data } = await axios.post<ApiQueryResponse>(
|
|
415
|
+
baseURL + "/managed/query",
|
|
416
|
+
query,
|
|
417
|
+
{ headers , timeout: 3000 }
|
|
418
|
+
);
|
|
419
|
+
return data;
|
|
420
|
+
} catch (e) {
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
public async csv(query: any): Promise<ApiQueryResponse> {
|
|
426
|
+
try {
|
|
427
|
+
query.sort_type = query.sort_type || SortyType.ascending;
|
|
428
|
+
query.sort_by = "created_at";
|
|
429
|
+
query.subpath = query.subpath.replace(/\/+/g, "/");
|
|
430
|
+
const { data } = await axios.post<ApiQueryResponse>(
|
|
431
|
+
baseURL + "/managed/csv",
|
|
432
|
+
query,
|
|
433
|
+
{ headers }
|
|
434
|
+
);
|
|
435
|
+
return data;
|
|
436
|
+
} catch (error: any) {
|
|
437
|
+
return error.response.data;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
public async space(action: ActionRequest): Promise<ActionResponse> {
|
|
442
|
+
try {
|
|
443
|
+
const { data } = await axios.post<ActionResponse>(
|
|
444
|
+
baseURL + "/managed/space",
|
|
445
|
+
action,
|
|
446
|
+
{ headers }
|
|
447
|
+
);
|
|
448
|
+
return data;
|
|
449
|
+
} catch (error: any) {
|
|
450
|
+
return error.response.data;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
public async request(action: ActionRequest): Promise<ActionResponse> {
|
|
455
|
+
try {
|
|
456
|
+
const { data } = await axios.post<ActionResponse>(
|
|
457
|
+
baseURL + "/managed/request",
|
|
458
|
+
action,
|
|
459
|
+
{ headers }
|
|
460
|
+
);
|
|
461
|
+
return data;
|
|
462
|
+
} catch (error: any) {
|
|
463
|
+
return error.response.data;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
public async retrieve_entry(
|
|
468
|
+
resource_type: ResourceType,
|
|
469
|
+
space_name: string,
|
|
470
|
+
subpath: string,
|
|
471
|
+
shortname: string,
|
|
472
|
+
retrieve_json_payload: boolean = false,
|
|
473
|
+
retrieve_attachments: boolean = false,
|
|
474
|
+
validate_schema: boolean = true
|
|
475
|
+
): Promise<ResponseEntry|null> {
|
|
476
|
+
try {
|
|
477
|
+
if (!subpath || subpath == "/") subpath = "__root__";
|
|
478
|
+
const { data } = await axios.get<ResponseEntry>(
|
|
479
|
+
baseURL +
|
|
480
|
+
`/managed/entry/${resource_type}/${space_name}/${subpath}/${shortname}?retrieve_json_payload=${retrieve_json_payload}&retrieve_attachments=${retrieve_attachments}&validate_schema=${validate_schema}`.replace(
|
|
481
|
+
/\/+/g,
|
|
482
|
+
"/"
|
|
483
|
+
),
|
|
484
|
+
{ headers }
|
|
485
|
+
);
|
|
486
|
+
return data;
|
|
487
|
+
} catch (error: any) {
|
|
488
|
+
throw new Error(error.response.data.error.message)
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
public async upload_with_payload(
|
|
493
|
+
space_name: string,
|
|
494
|
+
subpath: string,
|
|
495
|
+
shortname: string,
|
|
496
|
+
resource_type: ResourceType,
|
|
497
|
+
payload_file: File,
|
|
498
|
+
content_type?: ContentType,
|
|
499
|
+
schema_shortname?: string
|
|
500
|
+
): Promise<ApiResponse> {
|
|
501
|
+
const request_record_body:any = {
|
|
502
|
+
resource_type,
|
|
503
|
+
subpath,
|
|
504
|
+
shortname,
|
|
505
|
+
attributes: { is_active: true, payload: {body:{}} },
|
|
506
|
+
};
|
|
507
|
+
if (content_type){
|
|
508
|
+
request_record_body.attributes.payload.content_type = content_type;
|
|
509
|
+
}
|
|
510
|
+
if (schema_shortname){
|
|
511
|
+
request_record_body.attributes.payload.schema_shortname = schema_shortname;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const request_record = new Blob(
|
|
515
|
+
[
|
|
516
|
+
JSON.stringify(request_record_body),
|
|
517
|
+
],
|
|
518
|
+
{ type: "application/json" }
|
|
519
|
+
);
|
|
520
|
+
|
|
521
|
+
const form_data = new FormData();
|
|
522
|
+
form_data.append("space_name", space_name);
|
|
523
|
+
form_data.append("request_record", request_record);
|
|
524
|
+
form_data.append("payload_file", payload_file);
|
|
525
|
+
|
|
526
|
+
const headers = { "Content-Type": "multipart/form-data" };
|
|
527
|
+
|
|
528
|
+
const { data } = await axios.post<ApiResponse>(
|
|
529
|
+
baseURL + "/managed/resource_with_payload",
|
|
530
|
+
form_data,
|
|
531
|
+
{ headers }
|
|
532
|
+
);
|
|
533
|
+
|
|
534
|
+
return data;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
public async fetchDataAsset(
|
|
539
|
+
resourceType: string, // Replace with actual type if needed
|
|
540
|
+
dataAssetType: string, // Replace with actual type if needed
|
|
541
|
+
spaceName: string,
|
|
542
|
+
subpath: string,
|
|
543
|
+
shortname: string,
|
|
544
|
+
query_string?: string,
|
|
545
|
+
filter_data_assets?: string[],
|
|
546
|
+
branch_name?: string
|
|
547
|
+
) {
|
|
548
|
+
try {
|
|
549
|
+
const endpoint = "/managed/data-asset";
|
|
550
|
+
const url = `${baseURL}${endpoint}`;
|
|
551
|
+
const { data } = await axios.post(
|
|
552
|
+
url,
|
|
553
|
+
{
|
|
554
|
+
space_name: spaceName,
|
|
555
|
+
resource_type: resourceType,
|
|
556
|
+
data_asset_type: dataAssetType,
|
|
557
|
+
subpath,
|
|
558
|
+
shortname,
|
|
559
|
+
query_string: query_string ?? "SELECT * FROM file",
|
|
560
|
+
filter_data_assets,
|
|
561
|
+
branch_name,
|
|
562
|
+
},
|
|
563
|
+
{ headers }
|
|
564
|
+
);
|
|
565
|
+
|
|
566
|
+
return data;
|
|
567
|
+
} catch (error: any) {
|
|
568
|
+
return error;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
public async get_spaces(): Promise<ApiResponse | null> {
|
|
573
|
+
return await this.query({
|
|
574
|
+
type: QueryType.spaces,
|
|
575
|
+
space_name: "management",
|
|
576
|
+
subpath: "/",
|
|
577
|
+
search: "",
|
|
578
|
+
limit: 100,
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
public async get_children(
|
|
583
|
+
space_name: string,
|
|
584
|
+
subpath: string,
|
|
585
|
+
limit: number = 20,
|
|
586
|
+
offset: number = 0,
|
|
587
|
+
restrict_types: Array<ResourceType> = []
|
|
588
|
+
): Promise<ApiResponse | null> {
|
|
589
|
+
return await this.query({
|
|
590
|
+
type: QueryType.search,
|
|
591
|
+
space_name: space_name,
|
|
592
|
+
subpath: subpath,
|
|
593
|
+
filter_types: restrict_types,
|
|
594
|
+
exact_subpath: true,
|
|
595
|
+
search: "",
|
|
596
|
+
limit: limit,
|
|
597
|
+
offset: offset,
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
public get_attachment_url(
|
|
602
|
+
resource_type: ResourceType,
|
|
603
|
+
space_name: string,
|
|
604
|
+
subpath: string,
|
|
605
|
+
parent_shortname: string,
|
|
606
|
+
shortname: string,
|
|
607
|
+
ext: string
|
|
608
|
+
) {
|
|
609
|
+
return (
|
|
610
|
+
baseURL +
|
|
611
|
+
`/managed/payload/${resource_type}/${space_name}/${subpath.replace(
|
|
612
|
+
/\/+$/,
|
|
613
|
+
""
|
|
614
|
+
)}/${parent_shortname}/${shortname}.${ext}`.replaceAll("..", ".")
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
public async get_space_health(space_name: string) {
|
|
619
|
+
const { data } = await axios.get<
|
|
620
|
+
ApiQueryResponse & { attributes: { folders_report: Object } }
|
|
621
|
+
>(baseURL + `/managed/health/${space_name}`, { headers });
|
|
622
|
+
return data;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
public async get_attachment_content(
|
|
626
|
+
resource_type: string,
|
|
627
|
+
space_name: string,
|
|
628
|
+
subpath: string,
|
|
629
|
+
shortname: string,
|
|
630
|
+
) {
|
|
631
|
+
const { data } = await axios.get<any>(
|
|
632
|
+
baseURL +
|
|
633
|
+
`/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}`,
|
|
634
|
+
{ headers }
|
|
635
|
+
);
|
|
636
|
+
return data;
|
|
637
|
+
}
|
|
638
|
+
public async get_payload(
|
|
639
|
+
resource_type: string,
|
|
640
|
+
space_name: string,
|
|
641
|
+
subpath: string,
|
|
642
|
+
shortname: string,
|
|
643
|
+
ext: string = ".json"
|
|
644
|
+
) {
|
|
645
|
+
const { data } = await axios.get<any>(
|
|
646
|
+
baseURL +
|
|
647
|
+
`/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
|
|
648
|
+
{ headers }
|
|
649
|
+
);
|
|
650
|
+
return data;
|
|
651
|
+
}
|
|
652
|
+
public async get_payload_content(
|
|
653
|
+
resource_type: string,
|
|
654
|
+
space_name: string,
|
|
655
|
+
subpath: string,
|
|
656
|
+
shortname: string,
|
|
657
|
+
ext: string = ".json"
|
|
658
|
+
) {
|
|
659
|
+
const { data } = await axios.get<any>(
|
|
660
|
+
baseURL +
|
|
661
|
+
`/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
|
|
662
|
+
{ headers }
|
|
663
|
+
);
|
|
664
|
+
return data;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
public async progress_ticket(
|
|
668
|
+
space_name: string,
|
|
669
|
+
subpath: string,
|
|
670
|
+
shortname: string,
|
|
671
|
+
action: string,
|
|
672
|
+
resolution?: string,
|
|
673
|
+
comment?: string
|
|
674
|
+
) {
|
|
675
|
+
try {
|
|
676
|
+
const payload: any = {}
|
|
677
|
+
if(resolution){
|
|
678
|
+
payload.resolution = resolution;
|
|
679
|
+
}
|
|
680
|
+
if(comment){
|
|
681
|
+
payload.comment = comment;
|
|
682
|
+
}
|
|
683
|
+
const { data } = await axios.put<
|
|
684
|
+
ApiQueryResponse & { attributes: { folders_report: Object } }
|
|
685
|
+
>(
|
|
686
|
+
baseURL +
|
|
687
|
+
`/managed/progress-ticket/${space_name}/${subpath}/${shortname}/${action}`,
|
|
688
|
+
payload,
|
|
689
|
+
{ headers }
|
|
690
|
+
);
|
|
691
|
+
return data;
|
|
692
|
+
} catch (error: any) {
|
|
693
|
+
return error.response.data;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
public async get_manifest() {
|
|
698
|
+
const { data } = await axios.get<any>(baseURL + `/info/manifest`, {
|
|
699
|
+
headers,
|
|
700
|
+
});
|
|
701
|
+
return data;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
public async get_settings() {
|
|
705
|
+
const { data } = await axios.get<any>(baseURL + `/info/settings`, {
|
|
706
|
+
headers,
|
|
707
|
+
});
|
|
708
|
+
return data;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
// 23 funcs
|
package/package.json
CHANGED
package/dmart.ts
DELETED
|
@@ -1,712 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
|
|
3
|
-
let baseURL = "http://localhost:8282";
|
|
4
|
-
|
|
5
|
-
axios.defaults.withCredentials = true;
|
|
6
|
-
|
|
7
|
-
export enum Status {
|
|
8
|
-
success = "success",
|
|
9
|
-
failed = "failed",
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
type Error = {
|
|
13
|
-
type: string;
|
|
14
|
-
code: number;
|
|
15
|
-
message: string;
|
|
16
|
-
info: any;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type ApiResponseRecord = {
|
|
20
|
-
resource_type: string;
|
|
21
|
-
shortname: string;
|
|
22
|
-
branch_name?: string;
|
|
23
|
-
subpath: string;
|
|
24
|
-
attributes: Record<string, any>;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export type ApiResponse = {
|
|
28
|
-
status: Status;
|
|
29
|
-
error?: Error;
|
|
30
|
-
records: Array<ApiResponseRecord>;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
type Translation = {
|
|
34
|
-
ar: string;
|
|
35
|
-
en: string;
|
|
36
|
-
kd: string;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
enum UserType {
|
|
40
|
-
web = "web",
|
|
41
|
-
mobile = "mobile",
|
|
42
|
-
bot = "bot",
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
type LoginResponseRecord = ApiResponseRecord & {
|
|
46
|
-
attributes: {
|
|
47
|
-
access_token: string;
|
|
48
|
-
type: UserType;
|
|
49
|
-
displayname: Translation;
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// type LoginResponse = ApiResponse & { records : Array<LoginResponseRecord> };
|
|
54
|
-
|
|
55
|
-
type Permission = {
|
|
56
|
-
allowed_actions: Array<ActionType>;
|
|
57
|
-
conditions: Array<string>;
|
|
58
|
-
restricted_fields: Array<any>;
|
|
59
|
-
allowed_fields_values: Map<string, any>;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
enum Language {
|
|
63
|
-
arabic = "arabic",
|
|
64
|
-
english = "engligh",
|
|
65
|
-
kurdish = "kurdish",
|
|
66
|
-
french = "french",
|
|
67
|
-
turkish = "turkish",
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
type ProfileResponseRecord = ApiResponseRecord & {
|
|
71
|
-
attributes: {
|
|
72
|
-
email: string;
|
|
73
|
-
displayname: Translation;
|
|
74
|
-
type: string;
|
|
75
|
-
language: Language;
|
|
76
|
-
is_email_verified: boolean;
|
|
77
|
-
is_msisdn_verified: boolean;
|
|
78
|
-
force_password_change: boolean;
|
|
79
|
-
permissions: Record<string, Permission>;
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export enum ActionType {
|
|
84
|
-
query = "query",
|
|
85
|
-
view = "view",
|
|
86
|
-
update = "update",
|
|
87
|
-
create = "create",
|
|
88
|
-
delete = "delete",
|
|
89
|
-
attach = "attach",
|
|
90
|
-
move = "move",
|
|
91
|
-
progress_ticket = "progress_ticket",
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export type ProfileResponse = ApiResponse & {
|
|
95
|
-
records: Array<ProfileResponseRecord>;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
let headers: { [key: string]: string } = {
|
|
99
|
-
"Content-type": "application/json",
|
|
100
|
-
//"Authorization": ""
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export type AggregationReducer = {
|
|
104
|
-
name: string;
|
|
105
|
-
alias: string;
|
|
106
|
-
args: Array<string>;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export type AggregationType = {
|
|
110
|
-
load: Array<string>;
|
|
111
|
-
group_by: Array<string>;
|
|
112
|
-
reducers: Array<AggregationReducer> | Array<string>;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export enum QueryType {
|
|
116
|
-
aggregation = "aggregation",
|
|
117
|
-
search = "search",
|
|
118
|
-
subpath = "subpath",
|
|
119
|
-
events = "events",
|
|
120
|
-
history = "history",
|
|
121
|
-
tags = "tags",
|
|
122
|
-
spaces = "spaces",
|
|
123
|
-
counters = "counters",
|
|
124
|
-
reports = "reports",
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export enum SortyType {
|
|
128
|
-
ascending = "ascending",
|
|
129
|
-
descending = "descending",
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// enum NotificationPriority {
|
|
133
|
-
// high = "high",
|
|
134
|
-
// medium = "medium",
|
|
135
|
-
// low = "low"
|
|
136
|
-
// };
|
|
137
|
-
|
|
138
|
-
export type QueryRequest = {
|
|
139
|
-
type: QueryType;
|
|
140
|
-
space_name: string;
|
|
141
|
-
subpath: string;
|
|
142
|
-
filter_types?: Array<ResourceType>;
|
|
143
|
-
filter_schema_names?: Array<string>;
|
|
144
|
-
filter_shortnames?: Array<string>;
|
|
145
|
-
search: string;
|
|
146
|
-
from_date?: string;
|
|
147
|
-
to_date?: string;
|
|
148
|
-
sort_by?: string;
|
|
149
|
-
sort_type?: SortyType;
|
|
150
|
-
retrieve_json_payload?: boolean;
|
|
151
|
-
retrieve_attachments?: boolean;
|
|
152
|
-
validate_schema?: boolean;
|
|
153
|
-
jq_filter?: string;
|
|
154
|
-
exact_subpath?: boolean;
|
|
155
|
-
limit?: number;
|
|
156
|
-
offset?: number;
|
|
157
|
-
aggregation_data?: AggregationType;
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
export enum RequestType {
|
|
161
|
-
create = "create",
|
|
162
|
-
update = "update",
|
|
163
|
-
replace = "replace",
|
|
164
|
-
delete = "delete",
|
|
165
|
-
move = "move",
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export enum ResourceAttachmentType {
|
|
169
|
-
json = "json",
|
|
170
|
-
comment = "comment",
|
|
171
|
-
media = "media",
|
|
172
|
-
relationship = "relationship",
|
|
173
|
-
alteration = "alteration",
|
|
174
|
-
csv = "csv",
|
|
175
|
-
parquet = "parquet",
|
|
176
|
-
jsonl = "jsonl",
|
|
177
|
-
sqlite = "sqlite",
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export enum ResourceType {
|
|
181
|
-
user = "user",
|
|
182
|
-
group = "group",
|
|
183
|
-
folder = "folder",
|
|
184
|
-
schema = "schema",
|
|
185
|
-
content = "content",
|
|
186
|
-
acl = "acl",
|
|
187
|
-
comment = "comment",
|
|
188
|
-
media = "media",
|
|
189
|
-
locator = "locator",
|
|
190
|
-
relationship = "relationship",
|
|
191
|
-
alteration = "alteration",
|
|
192
|
-
history = "history",
|
|
193
|
-
space = "space",
|
|
194
|
-
branch = "branch",
|
|
195
|
-
permission = "permission",
|
|
196
|
-
role = "role",
|
|
197
|
-
ticket = "ticket",
|
|
198
|
-
json = "json",
|
|
199
|
-
post = "post",
|
|
200
|
-
plugin_wrapper = "plugin_wrapper",
|
|
201
|
-
notification = "notification",
|
|
202
|
-
jsonl = "jsonl",
|
|
203
|
-
csv = "csv",
|
|
204
|
-
sqlite = "sqlite",
|
|
205
|
-
parquet = "parquet",
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
export enum ContentType {
|
|
209
|
-
text = "text",
|
|
210
|
-
html = "html",
|
|
211
|
-
markdown = "markdown",
|
|
212
|
-
json = "json",
|
|
213
|
-
image = "image",
|
|
214
|
-
python = "python",
|
|
215
|
-
pdf = "pdf",
|
|
216
|
-
audio = "audio",
|
|
217
|
-
video = "video",
|
|
218
|
-
jsonl = "jsonl",
|
|
219
|
-
csv = "csv",
|
|
220
|
-
sqlite = "sqlite",
|
|
221
|
-
parquet = "parquet",
|
|
222
|
-
}
|
|
223
|
-
export enum ContentTypeMedia {
|
|
224
|
-
text = "text",
|
|
225
|
-
html = "html",
|
|
226
|
-
markdown = "markdown",
|
|
227
|
-
image = "image",
|
|
228
|
-
python = "python",
|
|
229
|
-
pdf = "pdf",
|
|
230
|
-
audio = "audio",
|
|
231
|
-
video = "video",
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
type Payload = {
|
|
235
|
-
content_type: ContentType;
|
|
236
|
-
schema_shortname?: string;
|
|
237
|
-
checksum: string;
|
|
238
|
-
body: string | Record<string, any> | any;
|
|
239
|
-
last_validated: string;
|
|
240
|
-
validation_status: "valid" | "invalid";
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
type MetaExtended = {
|
|
244
|
-
email: string;
|
|
245
|
-
msisdn: string;
|
|
246
|
-
is_email_verified: boolean;
|
|
247
|
-
is_msisdn_verified: boolean;
|
|
248
|
-
force_password_change: boolean;
|
|
249
|
-
password: string;
|
|
250
|
-
workflow_shortname: string;
|
|
251
|
-
state: string;
|
|
252
|
-
is_open: boolean;
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
export type ResponseEntry = MetaExtended & {
|
|
256
|
-
uuid: string;
|
|
257
|
-
shortname: string;
|
|
258
|
-
subpath: string;
|
|
259
|
-
is_active: boolean;
|
|
260
|
-
displayname: Translation;
|
|
261
|
-
description: Translation;
|
|
262
|
-
tags: Set<string>;
|
|
263
|
-
created_at: string;
|
|
264
|
-
updated_at: string;
|
|
265
|
-
owner_shortname: string;
|
|
266
|
-
payload?: Payload;
|
|
267
|
-
relationships?: any;
|
|
268
|
-
attachments?: Object;
|
|
269
|
-
workflow_shortname?: string;
|
|
270
|
-
state?: string;
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
export type ResponseRecord = {
|
|
274
|
-
resource_type: ResourceType;
|
|
275
|
-
uuid: string;
|
|
276
|
-
shortname: string;
|
|
277
|
-
subpath: string;
|
|
278
|
-
attributes: {
|
|
279
|
-
is_active: boolean;
|
|
280
|
-
displayname: Translation;
|
|
281
|
-
description: Translation;
|
|
282
|
-
tags: Set<string>;
|
|
283
|
-
created_at: string;
|
|
284
|
-
updated_at: string;
|
|
285
|
-
owner_shortname: string;
|
|
286
|
-
payload?: Payload;
|
|
287
|
-
};
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
export type ActionResponse = ApiResponse & {
|
|
291
|
-
records: Array<
|
|
292
|
-
ResponseRecord & {
|
|
293
|
-
attachments: {
|
|
294
|
-
media: Array<ResponseRecord>;
|
|
295
|
-
json: Array<ResponseRecord>;
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
>;
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
type ActionRequestRecord = {
|
|
302
|
-
resource_type: ResourceType;
|
|
303
|
-
uuid?: string;
|
|
304
|
-
shortname: string;
|
|
305
|
-
subpath: string;
|
|
306
|
-
attributes: Record<string, any>;
|
|
307
|
-
attachments?: Record<ResourceType, Array<any>>;
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
export type ActionRequest = {
|
|
311
|
-
space_name: string;
|
|
312
|
-
request_type: RequestType;
|
|
313
|
-
records: Array<ActionRequestRecord>;
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
type ApiQueryResponse = ApiResponse & {
|
|
318
|
-
attributes: { total: number; returned: number };
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
export class Dmart {
|
|
322
|
-
|
|
323
|
-
public async login(shortname: string, password: string) {
|
|
324
|
-
const { data } = await axios.post<
|
|
325
|
-
ApiResponse & { records: Array<LoginResponseRecord> }
|
|
326
|
-
>(baseURL + "/user/login", { shortname, password }, { headers });
|
|
327
|
-
//console.log(JSON.stringify(data, null, 2));
|
|
328
|
-
// FIXME settins Authorization is only needed when the code is running on the server
|
|
329
|
-
/*headers.Authorization = "";
|
|
330
|
-
if (data.status == Status.success && data.records.length > 0) {
|
|
331
|
-
headers.Authorization = "Bearer " + data.records[0].attributes.access_token;
|
|
332
|
-
}*/
|
|
333
|
-
return data;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
public async logout() {
|
|
337
|
-
const { data } = await axios.post<ApiResponse>(
|
|
338
|
-
baseURL + "/user/logout",
|
|
339
|
-
{},
|
|
340
|
-
{ headers }
|
|
341
|
-
);
|
|
342
|
-
return data;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
public async create_user(request: any) {
|
|
346
|
-
try {
|
|
347
|
-
const { data } = await axios.post<ActionResponse>(
|
|
348
|
-
baseURL + "/user/create",
|
|
349
|
-
request,
|
|
350
|
-
{ headers }
|
|
351
|
-
);
|
|
352
|
-
return data;
|
|
353
|
-
} catch (error: any) {
|
|
354
|
-
return error.response.data;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
public async update_user(request: any) {
|
|
359
|
-
try {
|
|
360
|
-
const { data } = await axios.post<ActionResponse>(
|
|
361
|
-
baseURL + "/user/profile",
|
|
362
|
-
request,
|
|
363
|
-
{ headers }
|
|
364
|
-
);
|
|
365
|
-
return data;
|
|
366
|
-
} catch (error: any) {
|
|
367
|
-
return error.response.data;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
public async check_existing(prop: string, value: string) {
|
|
372
|
-
try {
|
|
373
|
-
const { data } = await axios.get<ResponseEntry>(
|
|
374
|
-
baseURL +
|
|
375
|
-
`/user/check-existing?${prop}=${value}`,
|
|
376
|
-
{ headers }
|
|
377
|
-
);
|
|
378
|
-
return data;
|
|
379
|
-
} catch (error: any) {
|
|
380
|
-
return null;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
public async get_profile() {
|
|
385
|
-
try {
|
|
386
|
-
const { data } = await axios.get<ProfileResponse>(
|
|
387
|
-
baseURL + "/user/profile",
|
|
388
|
-
{
|
|
389
|
-
headers,
|
|
390
|
-
}
|
|
391
|
-
);
|
|
392
|
-
if (typeof localStorage !== "undefined" && data.status === "success") {
|
|
393
|
-
localStorage.setItem(
|
|
394
|
-
"permissions",
|
|
395
|
-
JSON.stringify((data?.records ?? [{}])[0]?.attributes.permissions)
|
|
396
|
-
);
|
|
397
|
-
localStorage.setItem(
|
|
398
|
-
"roles",
|
|
399
|
-
JSON.stringify((data?.records ?? [{}])[0]?.attributes?.["roles"])
|
|
400
|
-
);
|
|
401
|
-
}
|
|
402
|
-
return data;
|
|
403
|
-
} catch (error: any) {
|
|
404
|
-
return null;
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
public async query(query: QueryRequest): Promise<ApiQueryResponse|null> {
|
|
409
|
-
try {
|
|
410
|
-
if (query.type != QueryType.spaces) {
|
|
411
|
-
query.sort_type = query.sort_type || SortyType.ascending;
|
|
412
|
-
query.sort_by = query.sort_by || "created_at";
|
|
413
|
-
}
|
|
414
|
-
query.subpath = query.subpath.replace(/\/+/g, "/");
|
|
415
|
-
const { data } = await axios.post<ApiQueryResponse>(
|
|
416
|
-
baseURL + "/managed/query",
|
|
417
|
-
query,
|
|
418
|
-
{ headers , timeout: 3000 }
|
|
419
|
-
);
|
|
420
|
-
return data;
|
|
421
|
-
} catch (e) {
|
|
422
|
-
return null;
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
public async csv(query: any): Promise<ApiQueryResponse> {
|
|
427
|
-
try {
|
|
428
|
-
query.sort_type = query.sort_type || SortyType.ascending;
|
|
429
|
-
query.sort_by = "created_at";
|
|
430
|
-
query.subpath = query.subpath.replace(/\/+/g, "/");
|
|
431
|
-
const { data } = await axios.post<ApiQueryResponse>(
|
|
432
|
-
baseURL + "/managed/csv",
|
|
433
|
-
query,
|
|
434
|
-
{ headers }
|
|
435
|
-
);
|
|
436
|
-
return data;
|
|
437
|
-
} catch (error: any) {
|
|
438
|
-
return error.response.data;
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
public async space(action: ActionRequest): Promise<ActionResponse> {
|
|
443
|
-
try {
|
|
444
|
-
const { data } = await axios.post<ActionResponse>(
|
|
445
|
-
baseURL + "/managed/space",
|
|
446
|
-
action,
|
|
447
|
-
{ headers }
|
|
448
|
-
);
|
|
449
|
-
return data;
|
|
450
|
-
} catch (error: any) {
|
|
451
|
-
return error.response.data;
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
public async request(action: ActionRequest): Promise<ActionResponse> {
|
|
456
|
-
try {
|
|
457
|
-
const { data } = await axios.post<ActionResponse>(
|
|
458
|
-
baseURL + "/managed/request",
|
|
459
|
-
action,
|
|
460
|
-
{ headers }
|
|
461
|
-
);
|
|
462
|
-
return data;
|
|
463
|
-
} catch (error: any) {
|
|
464
|
-
return error.response.data;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
public async retrieve_entry(
|
|
469
|
-
resource_type: ResourceType,
|
|
470
|
-
space_name: string,
|
|
471
|
-
subpath: string,
|
|
472
|
-
shortname: string,
|
|
473
|
-
retrieve_json_payload: boolean = false,
|
|
474
|
-
retrieve_attachments: boolean = false,
|
|
475
|
-
validate_schema: boolean = true
|
|
476
|
-
): Promise<ResponseEntry|null> {
|
|
477
|
-
try {
|
|
478
|
-
if (!subpath || subpath == "/") subpath = "__root__";
|
|
479
|
-
const { data } = await axios.get<ResponseEntry>(
|
|
480
|
-
baseURL +
|
|
481
|
-
`/managed/entry/${resource_type}/${space_name}/${subpath}/${shortname}?retrieve_json_payload=${retrieve_json_payload}&retrieve_attachments=${retrieve_attachments}&validate_schema=${validate_schema}`.replace(
|
|
482
|
-
/\/+/g,
|
|
483
|
-
"/"
|
|
484
|
-
),
|
|
485
|
-
{ headers }
|
|
486
|
-
);
|
|
487
|
-
return data;
|
|
488
|
-
} catch (error: any) {
|
|
489
|
-
throw new Error(error.response.data.error.message)
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
public async upload_with_payload(
|
|
494
|
-
space_name: string,
|
|
495
|
-
subpath: string,
|
|
496
|
-
shortname: string,
|
|
497
|
-
resource_type: ResourceType,
|
|
498
|
-
payload_file: File,
|
|
499
|
-
content_type?: ContentType,
|
|
500
|
-
schema_shortname?: string
|
|
501
|
-
): Promise<ApiResponse> {
|
|
502
|
-
const request_record_body:any = {
|
|
503
|
-
resource_type,
|
|
504
|
-
subpath,
|
|
505
|
-
shortname,
|
|
506
|
-
attributes: { is_active: true, payload: {body:{}} },
|
|
507
|
-
};
|
|
508
|
-
if (content_type){
|
|
509
|
-
request_record_body.attributes.payload.content_type = content_type;
|
|
510
|
-
}
|
|
511
|
-
if (schema_shortname){
|
|
512
|
-
request_record_body.attributes.payload.schema_shortname = schema_shortname;
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
const request_record = new Blob(
|
|
516
|
-
[
|
|
517
|
-
JSON.stringify(request_record_body),
|
|
518
|
-
],
|
|
519
|
-
{ type: "application/json" }
|
|
520
|
-
);
|
|
521
|
-
|
|
522
|
-
const form_data = new FormData();
|
|
523
|
-
form_data.append("space_name", space_name);
|
|
524
|
-
form_data.append("request_record", request_record);
|
|
525
|
-
form_data.append("payload_file", payload_file);
|
|
526
|
-
|
|
527
|
-
const headers = { "Content-Type": "multipart/form-data" };
|
|
528
|
-
|
|
529
|
-
const { data } = await axios.post<ApiResponse>(
|
|
530
|
-
baseURL + "/managed/resource_with_payload",
|
|
531
|
-
form_data,
|
|
532
|
-
{ headers }
|
|
533
|
-
);
|
|
534
|
-
|
|
535
|
-
return data;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
public async fetchDataAsset(
|
|
540
|
-
resourceType: string, // Replace with actual type if needed
|
|
541
|
-
dataAssetType: string, // Replace with actual type if needed
|
|
542
|
-
spaceName: string,
|
|
543
|
-
subpath: string,
|
|
544
|
-
shortname: string,
|
|
545
|
-
query_string?: string,
|
|
546
|
-
filter_data_assets?: string[],
|
|
547
|
-
branch_name?: string
|
|
548
|
-
) {
|
|
549
|
-
try {
|
|
550
|
-
const endpoint = "/managed/data-asset";
|
|
551
|
-
const url = `${baseURL}${endpoint}`;
|
|
552
|
-
const { data } = await axios.post(
|
|
553
|
-
url,
|
|
554
|
-
{
|
|
555
|
-
space_name: spaceName,
|
|
556
|
-
resource_type: resourceType,
|
|
557
|
-
data_asset_type: dataAssetType,
|
|
558
|
-
subpath,
|
|
559
|
-
shortname,
|
|
560
|
-
query_string: query_string ?? "SELECT * FROM file",
|
|
561
|
-
filter_data_assets,
|
|
562
|
-
branch_name,
|
|
563
|
-
},
|
|
564
|
-
{ headers }
|
|
565
|
-
);
|
|
566
|
-
|
|
567
|
-
return data;
|
|
568
|
-
} catch (error: any) {
|
|
569
|
-
return error;
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
public async get_spaces(): Promise<ApiResponse | null> {
|
|
574
|
-
return await this.query({
|
|
575
|
-
type: QueryType.spaces,
|
|
576
|
-
space_name: "management",
|
|
577
|
-
subpath: "/",
|
|
578
|
-
search: "",
|
|
579
|
-
limit: 100,
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
public async get_children(
|
|
584
|
-
space_name: string,
|
|
585
|
-
subpath: string,
|
|
586
|
-
limit: number = 20,
|
|
587
|
-
offset: number = 0,
|
|
588
|
-
restrict_types: Array<ResourceType> = []
|
|
589
|
-
): Promise<ApiResponse | null> {
|
|
590
|
-
return await this.query({
|
|
591
|
-
type: QueryType.search,
|
|
592
|
-
space_name: space_name,
|
|
593
|
-
subpath: subpath,
|
|
594
|
-
filter_types: restrict_types,
|
|
595
|
-
exact_subpath: true,
|
|
596
|
-
search: "",
|
|
597
|
-
limit: limit,
|
|
598
|
-
offset: offset,
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
public get_attachment_url(
|
|
603
|
-
resource_type: ResourceType,
|
|
604
|
-
space_name: string,
|
|
605
|
-
subpath: string,
|
|
606
|
-
parent_shortname: string,
|
|
607
|
-
shortname: string,
|
|
608
|
-
ext: string
|
|
609
|
-
) {
|
|
610
|
-
return (
|
|
611
|
-
baseURL +
|
|
612
|
-
`/managed/payload/${resource_type}/${space_name}/${subpath.replace(
|
|
613
|
-
/\/+$/,
|
|
614
|
-
""
|
|
615
|
-
)}/${parent_shortname}/${shortname}.${ext}`.replaceAll("..", ".")
|
|
616
|
-
);
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
public async get_space_health(space_name: string) {
|
|
620
|
-
const { data } = await axios.get<
|
|
621
|
-
ApiQueryResponse & { attributes: { folders_report: Object } }
|
|
622
|
-
>(baseURL + `/managed/health/${space_name}`, { headers });
|
|
623
|
-
return data;
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
public async get_attachment_content(
|
|
627
|
-
resource_type: string,
|
|
628
|
-
space_name: string,
|
|
629
|
-
subpath: string,
|
|
630
|
-
shortname: string,
|
|
631
|
-
) {
|
|
632
|
-
const { data } = await axios.get<any>(
|
|
633
|
-
baseURL +
|
|
634
|
-
`/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}`,
|
|
635
|
-
{ headers }
|
|
636
|
-
);
|
|
637
|
-
return data;
|
|
638
|
-
}
|
|
639
|
-
public async get_payload(
|
|
640
|
-
resource_type: string,
|
|
641
|
-
space_name: string,
|
|
642
|
-
subpath: string,
|
|
643
|
-
shortname: string,
|
|
644
|
-
ext: string = ".json"
|
|
645
|
-
) {
|
|
646
|
-
const { data } = await axios.get<any>(
|
|
647
|
-
baseURL +
|
|
648
|
-
`/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
|
|
649
|
-
{ headers }
|
|
650
|
-
);
|
|
651
|
-
return data;
|
|
652
|
-
}
|
|
653
|
-
public async get_payload_content(
|
|
654
|
-
resource_type: string,
|
|
655
|
-
space_name: string,
|
|
656
|
-
subpath: string,
|
|
657
|
-
shortname: string,
|
|
658
|
-
ext: string = ".json"
|
|
659
|
-
) {
|
|
660
|
-
const { data } = await axios.get<any>(
|
|
661
|
-
baseURL +
|
|
662
|
-
`/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
|
|
663
|
-
{ headers }
|
|
664
|
-
);
|
|
665
|
-
return data;
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
public async progress_ticket(
|
|
669
|
-
space_name: string,
|
|
670
|
-
subpath: string,
|
|
671
|
-
shortname: string,
|
|
672
|
-
action: string,
|
|
673
|
-
resolution?: string,
|
|
674
|
-
comment?: string
|
|
675
|
-
) {
|
|
676
|
-
try {
|
|
677
|
-
const payload: any = {}
|
|
678
|
-
if(resolution){
|
|
679
|
-
payload.resolution = resolution;
|
|
680
|
-
}
|
|
681
|
-
if(comment){
|
|
682
|
-
payload.comment = comment;
|
|
683
|
-
}
|
|
684
|
-
const { data } = await axios.put<
|
|
685
|
-
ApiQueryResponse & { attributes: { folders_report: Object } }
|
|
686
|
-
>(
|
|
687
|
-
baseURL +
|
|
688
|
-
`/managed/progress-ticket/${space_name}/${subpath}/${shortname}/${action}`,
|
|
689
|
-
payload,
|
|
690
|
-
{ headers }
|
|
691
|
-
);
|
|
692
|
-
return data;
|
|
693
|
-
} catch (error: any) {
|
|
694
|
-
return error.response.data;
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
public async get_manifest() {
|
|
699
|
-
const { data } = await axios.get<any>(baseURL + `/info/manifest`, {
|
|
700
|
-
headers,
|
|
701
|
-
});
|
|
702
|
-
return data;
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
public async get_settings() {
|
|
706
|
-
const { data } = await axios.get<any>(baseURL + `/info/settings`, {
|
|
707
|
-
headers,
|
|
708
|
-
});
|
|
709
|
-
return data;
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
// 23 funcs
|