@edraj/tsdmart 1.0.2 → 1.0.4
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/.idea/tsdmart.iml +1 -0
- package/index.ts +45 -46
- package/package.json +1 -1
- package/b/axios.js +0 -9
- package/b/axios.ts +0 -36
- package/b/http.ts +0 -76
package/.idea/tsdmart.iml
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
7
7
|
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
8
8
|
<excludeFolder url="file://$MODULE_DIR$/b" />
|
|
9
|
+
<excludeFolder url="file://$MODULE_DIR$/.idea/copilot/chatSessions" />
|
|
9
10
|
</content>
|
|
10
11
|
<orderEntry type="inheritedJdk" />
|
|
11
12
|
<orderEntry type="sourceFolder" forTests="false" />
|
package/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
let baseURL = "http://localhost:8282";
|
|
4
4
|
|
|
5
5
|
axios.defaults.withCredentials = true;
|
|
6
6
|
|
|
@@ -318,12 +318,11 @@ type ApiQueryResponse = ApiResponse & {
|
|
|
318
318
|
attributes: { total: number; returned: number };
|
|
319
319
|
};
|
|
320
320
|
|
|
321
|
-
export class Dmart {
|
|
322
|
-
|
|
323
|
-
public async login(shortname: string, password: string) {
|
|
321
|
+
export default class Dmart {
|
|
322
|
+
public static async login(shortname: string, password: string) {
|
|
324
323
|
const { data } = await axios.post<
|
|
325
324
|
ApiResponse & { records: Array<LoginResponseRecord> }
|
|
326
|
-
>(
|
|
325
|
+
>(baseURL + "/user/login", { shortname, password }, { headers });
|
|
327
326
|
//console.log(JSON.stringify(data, null, 2));
|
|
328
327
|
// FIXME settins Authorization is only needed when the code is running on the server
|
|
329
328
|
/*headers.Authorization = "";
|
|
@@ -333,19 +332,19 @@ export class Dmart {
|
|
|
333
332
|
return data;
|
|
334
333
|
}
|
|
335
334
|
|
|
336
|
-
public async logout() {
|
|
335
|
+
public static async logout() {
|
|
337
336
|
const { data } = await axios.post<ApiResponse>(
|
|
338
|
-
|
|
337
|
+
baseURL + "/user/logout",
|
|
339
338
|
{},
|
|
340
339
|
{ headers }
|
|
341
340
|
);
|
|
342
341
|
return data;
|
|
343
342
|
}
|
|
344
343
|
|
|
345
|
-
public async create_user(request: any) {
|
|
344
|
+
public static async create_user(request: any) {
|
|
346
345
|
try {
|
|
347
346
|
const { data } = await axios.post<ActionResponse>(
|
|
348
|
-
|
|
347
|
+
baseURL + "/user/create",
|
|
349
348
|
request,
|
|
350
349
|
{ headers }
|
|
351
350
|
);
|
|
@@ -355,10 +354,10 @@ export class Dmart {
|
|
|
355
354
|
}
|
|
356
355
|
}
|
|
357
356
|
|
|
358
|
-
public async update_user(request: any) {
|
|
357
|
+
public static async update_user(request: any) {
|
|
359
358
|
try {
|
|
360
359
|
const { data } = await axios.post<ActionResponse>(
|
|
361
|
-
|
|
360
|
+
baseURL + "/user/profile",
|
|
362
361
|
request,
|
|
363
362
|
{ headers }
|
|
364
363
|
);
|
|
@@ -368,10 +367,10 @@ export class Dmart {
|
|
|
368
367
|
}
|
|
369
368
|
}
|
|
370
369
|
|
|
371
|
-
public async check_existing(prop: string, value: string) {
|
|
370
|
+
public static async check_existing(prop: string, value: string) {
|
|
372
371
|
try {
|
|
373
372
|
const { data } = await axios.get<ResponseEntry>(
|
|
374
|
-
|
|
373
|
+
baseURL +
|
|
375
374
|
`/user/check-existing?${prop}=${value}`,
|
|
376
375
|
{ headers }
|
|
377
376
|
);
|
|
@@ -381,10 +380,10 @@ export class Dmart {
|
|
|
381
380
|
}
|
|
382
381
|
}
|
|
383
382
|
|
|
384
|
-
public async get_profile() {
|
|
383
|
+
public static async get_profile() {
|
|
385
384
|
try {
|
|
386
385
|
const { data } = await axios.get<ProfileResponse>(
|
|
387
|
-
|
|
386
|
+
baseURL + "/user/profile",
|
|
388
387
|
{
|
|
389
388
|
headers,
|
|
390
389
|
}
|
|
@@ -405,7 +404,7 @@ export class Dmart {
|
|
|
405
404
|
}
|
|
406
405
|
}
|
|
407
406
|
|
|
408
|
-
public async query(query: QueryRequest): Promise<ApiQueryResponse|null> {
|
|
407
|
+
public static async query(query: QueryRequest): Promise<ApiQueryResponse|null> {
|
|
409
408
|
try {
|
|
410
409
|
if (query.type != QueryType.spaces) {
|
|
411
410
|
query.sort_type = query.sort_type || SortyType.ascending;
|
|
@@ -413,7 +412,7 @@ export class Dmart {
|
|
|
413
412
|
}
|
|
414
413
|
query.subpath = query.subpath.replace(/\/+/g, "/");
|
|
415
414
|
const { data } = await axios.post<ApiQueryResponse>(
|
|
416
|
-
|
|
415
|
+
baseURL + "/managed/query",
|
|
417
416
|
query,
|
|
418
417
|
{ headers , timeout: 3000 }
|
|
419
418
|
);
|
|
@@ -423,13 +422,13 @@ export class Dmart {
|
|
|
423
422
|
}
|
|
424
423
|
}
|
|
425
424
|
|
|
426
|
-
public async csv(query: any): Promise<ApiQueryResponse> {
|
|
425
|
+
public static async csv(query: any): Promise<ApiQueryResponse> {
|
|
427
426
|
try {
|
|
428
427
|
query.sort_type = query.sort_type || SortyType.ascending;
|
|
429
428
|
query.sort_by = "created_at";
|
|
430
429
|
query.subpath = query.subpath.replace(/\/+/g, "/");
|
|
431
430
|
const { data } = await axios.post<ApiQueryResponse>(
|
|
432
|
-
|
|
431
|
+
baseURL + "/managed/csv",
|
|
433
432
|
query,
|
|
434
433
|
{ headers }
|
|
435
434
|
);
|
|
@@ -439,10 +438,10 @@ export class Dmart {
|
|
|
439
438
|
}
|
|
440
439
|
}
|
|
441
440
|
|
|
442
|
-
public async space(action: ActionRequest): Promise<ActionResponse> {
|
|
441
|
+
public static async space(action: ActionRequest): Promise<ActionResponse> {
|
|
443
442
|
try {
|
|
444
443
|
const { data } = await axios.post<ActionResponse>(
|
|
445
|
-
|
|
444
|
+
baseURL + "/managed/space",
|
|
446
445
|
action,
|
|
447
446
|
{ headers }
|
|
448
447
|
);
|
|
@@ -452,10 +451,10 @@ export class Dmart {
|
|
|
452
451
|
}
|
|
453
452
|
}
|
|
454
453
|
|
|
455
|
-
public async request(action: ActionRequest): Promise<ActionResponse> {
|
|
454
|
+
public static async request(action: ActionRequest): Promise<ActionResponse> {
|
|
456
455
|
try {
|
|
457
456
|
const { data } = await axios.post<ActionResponse>(
|
|
458
|
-
|
|
457
|
+
baseURL + "/managed/request",
|
|
459
458
|
action,
|
|
460
459
|
{ headers }
|
|
461
460
|
);
|
|
@@ -465,7 +464,7 @@ export class Dmart {
|
|
|
465
464
|
}
|
|
466
465
|
}
|
|
467
466
|
|
|
468
|
-
public async retrieve_entry(
|
|
467
|
+
public static async retrieve_entry(
|
|
469
468
|
resource_type: ResourceType,
|
|
470
469
|
space_name: string,
|
|
471
470
|
subpath: string,
|
|
@@ -477,7 +476,7 @@ export class Dmart {
|
|
|
477
476
|
try {
|
|
478
477
|
if (!subpath || subpath == "/") subpath = "__root__";
|
|
479
478
|
const { data } = await axios.get<ResponseEntry>(
|
|
480
|
-
|
|
479
|
+
baseURL +
|
|
481
480
|
`/managed/entry/${resource_type}/${space_name}/${subpath}/${shortname}?retrieve_json_payload=${retrieve_json_payload}&retrieve_attachments=${retrieve_attachments}&validate_schema=${validate_schema}`.replace(
|
|
482
481
|
/\/+/g,
|
|
483
482
|
"/"
|
|
@@ -490,7 +489,7 @@ export class Dmart {
|
|
|
490
489
|
}
|
|
491
490
|
}
|
|
492
491
|
|
|
493
|
-
public async upload_with_payload(
|
|
492
|
+
public static async upload_with_payload(
|
|
494
493
|
space_name: string,
|
|
495
494
|
subpath: string,
|
|
496
495
|
shortname: string,
|
|
@@ -527,7 +526,7 @@ export class Dmart {
|
|
|
527
526
|
const headers = { "Content-Type": "multipart/form-data" };
|
|
528
527
|
|
|
529
528
|
const { data } = await axios.post<ApiResponse>(
|
|
530
|
-
|
|
529
|
+
baseURL + "/managed/resource_with_payload",
|
|
531
530
|
form_data,
|
|
532
531
|
{ headers }
|
|
533
532
|
);
|
|
@@ -536,7 +535,7 @@ export class Dmart {
|
|
|
536
535
|
}
|
|
537
536
|
|
|
538
537
|
|
|
539
|
-
public async fetchDataAsset(
|
|
538
|
+
public static async fetchDataAsset(
|
|
540
539
|
resourceType: string, // Replace with actual type if needed
|
|
541
540
|
dataAssetType: string, // Replace with actual type if needed
|
|
542
541
|
spaceName: string,
|
|
@@ -548,7 +547,7 @@ export class Dmart {
|
|
|
548
547
|
) {
|
|
549
548
|
try {
|
|
550
549
|
const endpoint = "/managed/data-asset";
|
|
551
|
-
const url = `${
|
|
550
|
+
const url = `${baseURL}${endpoint}`;
|
|
552
551
|
const { data } = await axios.post(
|
|
553
552
|
url,
|
|
554
553
|
{
|
|
@@ -570,7 +569,7 @@ export class Dmart {
|
|
|
570
569
|
}
|
|
571
570
|
}
|
|
572
571
|
|
|
573
|
-
public async get_spaces(): Promise<ApiResponse | null> {
|
|
572
|
+
public static async get_spaces(): Promise<ApiResponse | null> {
|
|
574
573
|
return await this.query({
|
|
575
574
|
type: QueryType.spaces,
|
|
576
575
|
space_name: "management",
|
|
@@ -580,7 +579,7 @@ export class Dmart {
|
|
|
580
579
|
});
|
|
581
580
|
}
|
|
582
581
|
|
|
583
|
-
public async get_children(
|
|
582
|
+
public static async get_children(
|
|
584
583
|
space_name: string,
|
|
585
584
|
subpath: string,
|
|
586
585
|
limit: number = 20,
|
|
@@ -608,7 +607,7 @@ export class Dmart {
|
|
|
608
607
|
ext: string
|
|
609
608
|
) {
|
|
610
609
|
return (
|
|
611
|
-
|
|
610
|
+
baseURL +
|
|
612
611
|
`/managed/payload/${resource_type}/${space_name}/${subpath.replace(
|
|
613
612
|
/\/+$/,
|
|
614
613
|
""
|
|
@@ -616,27 +615,27 @@ export class Dmart {
|
|
|
616
615
|
);
|
|
617
616
|
}
|
|
618
617
|
|
|
619
|
-
public async get_space_health(space_name: string) {
|
|
618
|
+
public static async get_space_health(space_name: string) {
|
|
620
619
|
const { data } = await axios.get<
|
|
621
620
|
ApiQueryResponse & { attributes: { folders_report: Object } }
|
|
622
|
-
>(
|
|
621
|
+
>(baseURL + `/managed/health/${space_name}`, { headers });
|
|
623
622
|
return data;
|
|
624
623
|
}
|
|
625
624
|
|
|
626
|
-
public async get_attachment_content(
|
|
625
|
+
public static async get_attachment_content(
|
|
627
626
|
resource_type: string,
|
|
628
627
|
space_name: string,
|
|
629
628
|
subpath: string,
|
|
630
629
|
shortname: string,
|
|
631
630
|
) {
|
|
632
631
|
const { data } = await axios.get<any>(
|
|
633
|
-
|
|
632
|
+
baseURL +
|
|
634
633
|
`/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}`,
|
|
635
634
|
{ headers }
|
|
636
635
|
);
|
|
637
636
|
return data;
|
|
638
637
|
}
|
|
639
|
-
public async get_payload(
|
|
638
|
+
public static async get_payload(
|
|
640
639
|
resource_type: string,
|
|
641
640
|
space_name: string,
|
|
642
641
|
subpath: string,
|
|
@@ -644,13 +643,13 @@ export class Dmart {
|
|
|
644
643
|
ext: string = ".json"
|
|
645
644
|
) {
|
|
646
645
|
const { data } = await axios.get<any>(
|
|
647
|
-
|
|
646
|
+
baseURL +
|
|
648
647
|
`/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
|
|
649
648
|
{ headers }
|
|
650
649
|
);
|
|
651
650
|
return data;
|
|
652
651
|
}
|
|
653
|
-
public async get_payload_content(
|
|
652
|
+
public static async get_payload_content(
|
|
654
653
|
resource_type: string,
|
|
655
654
|
space_name: string,
|
|
656
655
|
subpath: string,
|
|
@@ -658,14 +657,14 @@ export class Dmart {
|
|
|
658
657
|
ext: string = ".json"
|
|
659
658
|
) {
|
|
660
659
|
const { data } = await axios.get<any>(
|
|
661
|
-
|
|
660
|
+
baseURL +
|
|
662
661
|
`/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
|
|
663
662
|
{ headers }
|
|
664
663
|
);
|
|
665
664
|
return data;
|
|
666
665
|
}
|
|
667
666
|
|
|
668
|
-
public async progress_ticket(
|
|
667
|
+
public static async progress_ticket(
|
|
669
668
|
space_name: string,
|
|
670
669
|
subpath: string,
|
|
671
670
|
shortname: string,
|
|
@@ -684,7 +683,7 @@ export class Dmart {
|
|
|
684
683
|
const { data } = await axios.put<
|
|
685
684
|
ApiQueryResponse & { attributes: { folders_report: Object } }
|
|
686
685
|
>(
|
|
687
|
-
|
|
686
|
+
baseURL +
|
|
688
687
|
`/managed/progress-ticket/${space_name}/${subpath}/${shortname}/${action}`,
|
|
689
688
|
payload,
|
|
690
689
|
{ headers }
|
|
@@ -695,15 +694,15 @@ export class Dmart {
|
|
|
695
694
|
}
|
|
696
695
|
}
|
|
697
696
|
|
|
698
|
-
public async get_manifest() {
|
|
699
|
-
const { data } = await axios.get<any>(
|
|
697
|
+
public static async get_manifest() {
|
|
698
|
+
const { data } = await axios.get<any>(baseURL + `/info/manifest`, {
|
|
700
699
|
headers,
|
|
701
700
|
});
|
|
702
701
|
return data;
|
|
703
702
|
}
|
|
704
703
|
|
|
705
|
-
public async get_settings() {
|
|
706
|
-
const { data } = await axios.get<any>(
|
|
704
|
+
public static async get_settings() {
|
|
705
|
+
const { data } = await axios.get<any>(baseURL + `/info/settings`, {
|
|
707
706
|
headers,
|
|
708
707
|
});
|
|
709
708
|
return data;
|
package/package.json
CHANGED
package/b/axios.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
// import axios from 'axios';
|
|
3
|
-
var postData = {
|
|
4
|
-
password: 'Password1234',
|
|
5
|
-
shortname: 'dmart'
|
|
6
|
-
};
|
|
7
|
-
var url = 'https://dmart.cc/dmart/user/login'; // Example endpoint
|
|
8
|
-
var response = await axios.post(url, postData);
|
|
9
|
-
console.log(response.data);
|
package/b/axios.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import axios from 'axios';
|
|
3
|
-
|
|
4
|
-
let response = await axios.post('https://dmart.cc/dmart/user/login', {
|
|
5
|
-
password: 'Password1234',
|
|
6
|
-
shortname: 'dmart'
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
let config = {
|
|
10
|
-
method: 'post',
|
|
11
|
-
maxBodyLength: Infinity,
|
|
12
|
-
url: 'https://dmart.cc/dmart/managed/query',
|
|
13
|
-
headers: {
|
|
14
|
-
'Content-Type': 'application/json',
|
|
15
|
-
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7InVzZXJuYW1lIjoiamltbXkifSwiZXhwaXJlcyI6MTcxMzI2ODQ3Ni43NDEzMjR9.pEmHFJFv1x43WGIhKNfSL5PVr2zI06yeOQv7QGojtQk'
|
|
16
|
-
},
|
|
17
|
-
data: JSON.stringify({
|
|
18
|
-
"type": "subpath",
|
|
19
|
-
"space_name": "management",
|
|
20
|
-
"subpath": "users",
|
|
21
|
-
"sort_by": "created_at",
|
|
22
|
-
"sort_type": "ascending",
|
|
23
|
-
"retrieve_json_payload": true
|
|
24
|
-
})
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
// for (let i = 0; i < 100; i++) {
|
|
29
|
-
// await axios.request(config);
|
|
30
|
-
// }
|
|
31
|
-
|
|
32
|
-
const requests = [];
|
|
33
|
-
for (let i = 0; i < 1000; i++) {
|
|
34
|
-
requests.push(axios.request(config));
|
|
35
|
-
}
|
|
36
|
-
await Promise.all(requests);
|
package/b/http.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import https from 'https';
|
|
2
|
-
|
|
3
|
-
// Function to make a POST request
|
|
4
|
-
function makePostRequest(url: any, data: any, headers: any) {
|
|
5
|
-
return new Promise((resolve, reject) => {
|
|
6
|
-
const options = {
|
|
7
|
-
method: 'POST',
|
|
8
|
-
headers: {
|
|
9
|
-
...headers,
|
|
10
|
-
'Content-Type': 'application/json'
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const req = https.request(url, options, (res) => {
|
|
15
|
-
let responseData = '';
|
|
16
|
-
res.on('data', (chunk) => {
|
|
17
|
-
responseData += chunk;
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
res.on('end', () => {
|
|
21
|
-
resolve(responseData);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
req.on('error', (error) => {
|
|
26
|
-
reject(error);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
req.write(JSON.stringify(data));
|
|
30
|
-
req.end();
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Main logic
|
|
35
|
-
async function main() {
|
|
36
|
-
// Login request
|
|
37
|
-
let loginResponse: any = await makePostRequest('https://dmart.cc/dmart/user/login', {
|
|
38
|
-
password: 'Password1234',
|
|
39
|
-
shortname: 'dmart'
|
|
40
|
-
}, {});
|
|
41
|
-
const token = JSON.parse(loginResponse).records[0].attributes.access_token;
|
|
42
|
-
// Use the login response to generate the authorization header
|
|
43
|
-
let authHeader = `Bearer ${token}`;
|
|
44
|
-
|
|
45
|
-
// Request config
|
|
46
|
-
let config = {
|
|
47
|
-
method: 'post',
|
|
48
|
-
maxBodyLength: Infinity,
|
|
49
|
-
url: 'https://dmart.cc/dmart/managed/query',
|
|
50
|
-
headers: {
|
|
51
|
-
'Authorization': authHeader,
|
|
52
|
-
'Content-Type': 'application/json'
|
|
53
|
-
},
|
|
54
|
-
data: {
|
|
55
|
-
"type": "subpath",
|
|
56
|
-
"space_name": "management",
|
|
57
|
-
"subpath": "users",
|
|
58
|
-
"sort_by": "created_at",
|
|
59
|
-
"sort_type": "ascending",
|
|
60
|
-
"retrieve_json_payload": true
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// Making 100 requests
|
|
65
|
-
// for (let i = 0; i < 100; i++) {
|
|
66
|
-
// await makePostRequest(config.url, config.data, config.headers);
|
|
67
|
-
// }
|
|
68
|
-
const requests = [];
|
|
69
|
-
for (let i = 0; i < 500; i++) {
|
|
70
|
-
requests.push(makePostRequest(config.url, config.data, config.headers));
|
|
71
|
-
}
|
|
72
|
-
await Promise.all(requests);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Call main function
|
|
76
|
-
main();
|