@edraj/tsdmart 1.0.6 → 1.0.7

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/index.ts +66 -59
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 1.0.7
2
+
3
+ - Implementing DMART apis up to 1.1.12
4
+
1
5
  ## 1.0.0
2
6
 
3
7
  - Initial version.
8
+
package/index.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import axios from "axios";
2
2
 
3
3
 
4
-
5
4
  axios.defaults.withCredentials = true;
6
5
 
7
6
  export enum Status {
@@ -222,6 +221,7 @@ export enum ContentType {
222
221
  sqlite = "sqlite",
223
222
  parquet = "parquet",
224
223
  }
224
+
225
225
  export enum ContentTypeMedia {
226
226
  text = "text",
227
227
  html = "html",
@@ -324,9 +324,9 @@ export default class Dmart {
324
324
  static baseURL = "http://localhost:8282";
325
325
 
326
326
  public static async login(shortname: string, password: string) {
327
- const { data } = await axios.post<
327
+ const {data} = await axios.post<
328
328
  ApiResponse & { records: Array<LoginResponseRecord> }
329
- >(this.baseURL + "/user/login", { shortname, password }, { headers });
329
+ >(this.baseURL + "/user/login", {shortname, password}, {headers});
330
330
  //console.log(JSON.stringify(data, null, 2));
331
331
  // FIXME settins Authorization is only needed when the code is running on the server
332
332
  /*headers.Authorization = "";
@@ -337,20 +337,20 @@ export default class Dmart {
337
337
  }
338
338
 
339
339
  public static async logout() {
340
- const { data } = await axios.post<ApiResponse>(
340
+ const {data} = await axios.post<ApiResponse>(
341
341
  this.baseURL + "/user/logout",
342
342
  {},
343
- { headers }
343
+ {headers}
344
344
  );
345
345
  return data;
346
346
  }
347
347
 
348
348
  public static async create_user(request: any) {
349
349
  try {
350
- const { data } = await axios.post<ActionResponse>(
350
+ const {data} = await axios.post<ActionResponse>(
351
351
  this.baseURL + "/user/create",
352
352
  request,
353
- { headers }
353
+ {headers}
354
354
  );
355
355
  return data;
356
356
  } catch (error: any) {
@@ -360,10 +360,10 @@ export default class Dmart {
360
360
 
361
361
  public static async update_user(request: any) {
362
362
  try {
363
- const { data } = await axios.post<ActionResponse>(
363
+ const {data} = await axios.post<ActionResponse>(
364
364
  this.baseURL + "/user/profile",
365
365
  request,
366
- { headers }
366
+ {headers}
367
367
  );
368
368
  return data;
369
369
  } catch (error: any) {
@@ -373,9 +373,9 @@ export default class Dmart {
373
373
 
374
374
  public static async check_existing(prop: string, value: string) {
375
375
  try {
376
- const { data } = await axios.get<ResponseEntry>(
376
+ const {data} = await axios.get<ResponseEntry>(
377
377
  `${this.baseURL}/user/check-existing?${prop}=${value}`,
378
- { headers }
378
+ {headers}
379
379
  );
380
380
  return data;
381
381
  } catch (error: any) {
@@ -385,7 +385,7 @@ export default class Dmart {
385
385
 
386
386
  public static async get_profile() {
387
387
  try {
388
- const { data } = await axios.get<ProfileResponse>(
388
+ const {data} = await axios.get<ProfileResponse>(
389
389
  this.baseURL + "/user/profile",
390
390
  {
391
391
  headers,
@@ -407,17 +407,17 @@ export default class Dmart {
407
407
  }
408
408
  }
409
409
 
410
- public static async query(query: QueryRequest): Promise<ApiQueryResponse|null> {
410
+ public static async query(query: QueryRequest, scope: string = "managed"): Promise<ApiQueryResponse | null> {
411
411
  try {
412
412
  if (query.type != QueryType.spaces) {
413
413
  query.sort_type = query.sort_type || SortyType.ascending;
414
414
  query.sort_by = query.sort_by || "created_at";
415
415
  }
416
416
  query.subpath = query.subpath.replace(/\/+/g, "/");
417
- const { data } = await axios.post<ApiQueryResponse>(
418
- this.baseURL + "/managed/query",
417
+ const {data} = await axios.post<ApiQueryResponse>(
418
+ this.baseURL + `/${scope}/query`,
419
419
  query,
420
- { headers , timeout: 3000 }
420
+ {headers, timeout: 3000}
421
421
  );
422
422
  return data;
423
423
  } catch (e) {
@@ -430,10 +430,10 @@ export default class Dmart {
430
430
  query.sort_type = query.sort_type || SortyType.ascending;
431
431
  query.sort_by = "created_at";
432
432
  query.subpath = query.subpath.replace(/\/+/g, "/");
433
- const { data } = await axios.post<ApiQueryResponse>(
433
+ const {data} = await axios.post<ApiQueryResponse>(
434
434
  this.baseURL + "/managed/csv",
435
435
  query,
436
- { headers }
436
+ {headers}
437
437
  );
438
438
  return data;
439
439
  } catch (error: any) {
@@ -443,10 +443,10 @@ export default class Dmart {
443
443
 
444
444
  public static async space(action: ActionRequest): Promise<ActionResponse> {
445
445
  try {
446
- const { data } = await axios.post<ActionResponse>(
446
+ const {data} = await axios.post<ActionResponse>(
447
447
  this.baseURL + "/managed/space",
448
448
  action,
449
- { headers }
449
+ {headers}
450
450
  );
451
451
  return data;
452
452
  } catch (error: any) {
@@ -456,10 +456,10 @@ export default class Dmart {
456
456
 
457
457
  public static async request(action: ActionRequest): Promise<ActionResponse> {
458
458
  try {
459
- const { data } = await axios.post<ActionResponse>(
459
+ const {data} = await axios.post<ActionResponse>(
460
460
  this.baseURL + "/managed/request",
461
461
  action,
462
- { headers }
462
+ {headers}
463
463
  );
464
464
  return data;
465
465
  } catch (error: any) {
@@ -474,16 +474,17 @@ export default class Dmart {
474
474
  shortname: string,
475
475
  retrieve_json_payload: boolean = false,
476
476
  retrieve_attachments: boolean = false,
477
- validate_schema: boolean = true
478
- ): Promise<ResponseEntry|null> {
477
+ validate_schema: boolean = true,
478
+ scope: string = "managed"
479
+ ): Promise<ResponseEntry | null> {
479
480
  try {
480
481
  if (!subpath || subpath == "/") subpath = "__root__";
481
- const { data } = await axios.get<ResponseEntry>(
482
- `${this.baseURL}/managed/entry/${resource_type}/${space_name}/${subpath}/${shortname}?retrieve_json_payload=${retrieve_json_payload}&retrieve_attachments=${retrieve_attachments}&validate_schema=${validate_schema}`.replace(
482
+ const {data} = await axios.get<ResponseEntry>(
483
+ `${this.baseURL}/${scope}/entry/${resource_type}/${space_name}/${subpath}/${shortname}?retrieve_json_payload=${retrieve_json_payload}&retrieve_attachments=${retrieve_attachments}&validate_schema=${validate_schema}`.replace(
483
484
  /\/+/g,
484
485
  "/"
485
486
  ),
486
- { headers }
487
+ {headers}
487
488
  );
488
489
  return data;
489
490
  } catch (error: any) {
@@ -500,16 +501,16 @@ export default class Dmart {
500
501
  content_type?: ContentType,
501
502
  schema_shortname?: string
502
503
  ): Promise<ApiResponse> {
503
- const request_record_body:any = {
504
+ const request_record_body: any = {
504
505
  resource_type,
505
506
  subpath,
506
507
  shortname,
507
- attributes: { is_active: true, payload: {body:{}} },
508
+ attributes: {is_active: true, payload: {body: {}}},
508
509
  };
509
- if (content_type){
510
+ if (content_type) {
510
511
  request_record_body.attributes.payload.content_type = content_type;
511
512
  }
512
- if (schema_shortname){
513
+ if (schema_shortname) {
513
514
  request_record_body.attributes.payload.schema_shortname = schema_shortname;
514
515
  }
515
516
 
@@ -517,7 +518,7 @@ export default class Dmart {
517
518
  [
518
519
  JSON.stringify(request_record_body),
519
520
  ],
520
- { type: "application/json" }
521
+ {type: "application/json"}
521
522
  );
522
523
 
523
524
  const form_data = new FormData();
@@ -525,12 +526,12 @@ export default class Dmart {
525
526
  form_data.append("request_record", request_record);
526
527
  form_data.append("payload_file", payload_file);
527
528
 
528
- const headers = { "Content-Type": "multipart/form-data" };
529
+ const headers = {"Content-Type": "multipart/form-data"};
529
530
 
530
- const { data } = await axios.post<ApiResponse>(
531
+ const {data} = await axios.post<ApiResponse>(
531
532
  this.baseURL + "/managed/resource_with_payload",
532
533
  form_data,
533
- { headers }
534
+ {headers}
534
535
  );
535
536
 
536
537
  return data;
@@ -549,7 +550,7 @@ export default class Dmart {
549
550
  ) {
550
551
  try {
551
552
  const url = `${this.baseURL}/managed/data-asset`;
552
- const { data } = await axios.post(
553
+ const {data} = await axios.post(
553
554
  url,
554
555
  {
555
556
  space_name: spaceName,
@@ -561,7 +562,7 @@ export default class Dmart {
561
562
  filter_data_assets,
562
563
  branch_name,
563
564
  },
564
- { headers }
565
+ {headers}
565
566
  );
566
567
  return data;
567
568
  } catch (error: any) {
@@ -604,10 +605,11 @@ export default class Dmart {
604
605
  subpath: string,
605
606
  parent_shortname: string,
606
607
  shortname: string,
607
- ext: string
608
+ ext: string,
609
+ scope: string = "managed"
608
610
  ) {
609
611
  return (
610
- `${this.baseURL}/managed/payload/${resource_type}/${space_name}/${subpath.replace(
612
+ `${this.baseURL}/${scope}/payload/${resource_type}/${space_name}/${subpath.replace(
611
613
  /\/+$/,
612
614
  ""
613
615
  )}/${parent_shortname}/${shortname}.${ext}`.replaceAll("..", ".")
@@ -615,9 +617,9 @@ export default class Dmart {
615
617
  }
616
618
 
617
619
  public static async get_space_health(space_name: string) {
618
- const { data } = await axios.get<
620
+ const {data} = await axios.get<
619
621
  ApiQueryResponse & { attributes: { folders_report: Object } }
620
- >(this.baseURL + `/managed/health/${space_name}`, { headers });
622
+ >(this.baseURL + `/managed/health/${space_name}`, {headers});
621
623
  return data;
622
624
  }
623
625
 
@@ -626,36 +628,41 @@ export default class Dmart {
626
628
  space_name: string,
627
629
  subpath: string,
628
630
  shortname: string,
631
+ scope: string = "managed"
629
632
  ) {
630
- const { data } = await axios.get<any>(
631
- `${this.baseURL}/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}`,
632
- { headers }
633
+ const {data} = await axios.get<any>(
634
+ `${this.baseURL}/${scope}/payload/${resource_type}/${space_name}/${subpath}/${shortname}`,
635
+ {headers}
633
636
  );
634
637
  return data;
635
638
  }
639
+
636
640
  public static async get_payload(
637
641
  resource_type: string,
638
642
  space_name: string,
639
643
  subpath: string,
640
644
  shortname: string,
641
- ext: string = ".json"
645
+ ext: string = ".json",
646
+ scope: string = "managed"
642
647
  ) {
643
- const { data } = await axios.get<any>(
644
- `${this.baseURL}/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
645
- { headers }
648
+ const {data} = await axios.get<any>(
649
+ `${this.baseURL}/${scope}/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
650
+ {headers}
646
651
  );
647
652
  return data;
648
653
  }
654
+
649
655
  public static async get_payload_content(
650
656
  resource_type: string,
651
657
  space_name: string,
652
658
  subpath: string,
653
659
  shortname: string,
654
- ext: string = ".json"
660
+ ext: string = ".json",
661
+ scope: string = "managed"
655
662
  ) {
656
- const { data } = await axios.get<any>(
657
- `${this.baseURL}/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
658
- { headers }
663
+ const {data} = await axios.get<any>(
664
+ `${this.baseURL}/${scope}/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
665
+ {headers}
659
666
  );
660
667
  return data;
661
668
  }
@@ -670,18 +677,18 @@ export default class Dmart {
670
677
  ) {
671
678
  try {
672
679
  const payload: any = {}
673
- if(resolution){
680
+ if (resolution) {
674
681
  payload.resolution = resolution;
675
682
  }
676
- if(comment){
683
+ if (comment) {
677
684
  payload.comment = comment;
678
685
  }
679
- const { data } = await axios.put<
686
+ const {data} = await axios.put<
680
687
  ApiQueryResponse & { attributes: { folders_report: Object } }
681
688
  >(
682
689
  `${this.baseURL}/managed/progress-ticket/${space_name}/${subpath}/${shortname}/${action}`,
683
690
  payload,
684
- { headers }
691
+ {headers}
685
692
  );
686
693
  return data;
687
694
  } catch (error: any) {
@@ -694,7 +701,7 @@ export default class Dmart {
694
701
  schemaShortname: string,
695
702
  subpath: string,
696
703
  record: any // More general than Map<String, dynamic>
697
- ){
704
+ ) {
698
705
  try {
699
706
  const {data} = await axios.post(
700
707
  `${this.baseURL}/public/submit/${spaceName}/${schemaShortname}/${subpath}`,
@@ -708,14 +715,14 @@ export default class Dmart {
708
715
  }
709
716
 
710
717
  public static async get_manifest() {
711
- const { data } = await axios.get<any>(this.baseURL + `/info/manifest`, {
718
+ const {data} = await axios.get<any>(this.baseURL + `/info/manifest`, {
712
719
  headers,
713
720
  });
714
721
  return data;
715
722
  }
716
723
 
717
724
  public static async get_settings() {
718
- const { data } = await axios.get<any>(this.baseURL + `/info/settings`, {
725
+ const {data} = await axios.get<any>(this.baseURL + `/info/settings`, {
719
726
  headers,
720
727
  });
721
728
  return data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edraj/tsdmart",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "A TypeScript implementation of the Dmart that depends on axios.",
5
5
  "author": "Kefah T. Issa",
6
6
  "email": "kefah.issa@gmail.com",