@edraj/tsdmart 1.0.5 → 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.
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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A TypeScript implementation of the Dmart that depends on axios.
4
4
 
5
- ## APIs
5
+ ## APIs
6
6
 
7
7
  * `login(shortname: string, password: string) -> Promise<ApiResponse>` - Performs a login action.
8
8
  * `logout() -> Promise<ApiResponse>` - Performs a logout action.
@@ -25,5 +25,6 @@ A TypeScript implementation of the Dmart that depends on axios.
25
25
  * `get_payload(resource_type: string, space_name: string, subpath: string, shortname: string, ext: string = ".json") -> Promise<any>` - Gets the payload of a resource.
26
26
  * `get_payload_content(resource_type: string, space_name: string, subpath: string, shortname: string, ext: string = ".json") -> Promise<any>` - Gets the content of a payload.
27
27
  * `progress_ticket(space_name: string, subpath: string, shortname: string, action: string, resolution?: string, comment?: string) -> Promise<ApiQueryResponse & { attributes: { folders_report: Object } }>` - Performs a progress ticket action.
28
+ * `submit(spaceName: string, schemaShortname: string, subpath: string, record: any) -> Promise<any>` - Submits a record (log/feedback) to Dmart.
28
29
  * `get_manifest() -> Promise<any>` - Gets the manifest of the current instance.
29
30
  * `get_settings() -> Promise<any>` - Gets the settings of the current instance.
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 {
@@ -163,6 +162,8 @@ export enum RequestType {
163
162
  replace = "replace",
164
163
  delete = "delete",
165
164
  move = "move",
165
+ updateACL = "update_acl",
166
+ assign = "assign",
166
167
  }
167
168
 
168
169
  export enum ResourceAttachmentType {
@@ -220,6 +221,7 @@ export enum ContentType {
220
221
  sqlite = "sqlite",
221
222
  parquet = "parquet",
222
223
  }
224
+
223
225
  export enum ContentTypeMedia {
224
226
  text = "text",
225
227
  html = "html",
@@ -322,9 +324,9 @@ export default class Dmart {
322
324
  static baseURL = "http://localhost:8282";
323
325
 
324
326
  public static async login(shortname: string, password: string) {
325
- const { data } = await axios.post<
327
+ const {data} = await axios.post<
326
328
  ApiResponse & { records: Array<LoginResponseRecord> }
327
- >(this.baseURL + "/user/login", { shortname, password }, { headers });
329
+ >(this.baseURL + "/user/login", {shortname, password}, {headers});
328
330
  //console.log(JSON.stringify(data, null, 2));
329
331
  // FIXME settins Authorization is only needed when the code is running on the server
330
332
  /*headers.Authorization = "";
@@ -335,20 +337,20 @@ export default class Dmart {
335
337
  }
336
338
 
337
339
  public static async logout() {
338
- const { data } = await axios.post<ApiResponse>(
340
+ const {data} = await axios.post<ApiResponse>(
339
341
  this.baseURL + "/user/logout",
340
342
  {},
341
- { headers }
343
+ {headers}
342
344
  );
343
345
  return data;
344
346
  }
345
347
 
346
348
  public static async create_user(request: any) {
347
349
  try {
348
- const { data } = await axios.post<ActionResponse>(
350
+ const {data} = await axios.post<ActionResponse>(
349
351
  this.baseURL + "/user/create",
350
352
  request,
351
- { headers }
353
+ {headers}
352
354
  );
353
355
  return data;
354
356
  } catch (error: any) {
@@ -358,10 +360,10 @@ export default class Dmart {
358
360
 
359
361
  public static async update_user(request: any) {
360
362
  try {
361
- const { data } = await axios.post<ActionResponse>(
363
+ const {data} = await axios.post<ActionResponse>(
362
364
  this.baseURL + "/user/profile",
363
365
  request,
364
- { headers }
366
+ {headers}
365
367
  );
366
368
  return data;
367
369
  } catch (error: any) {
@@ -371,10 +373,9 @@ export default class Dmart {
371
373
 
372
374
  public static async check_existing(prop: string, value: string) {
373
375
  try {
374
- const { data } = await axios.get<ResponseEntry>(
375
- this.baseURL +
376
- `/user/check-existing?${prop}=${value}`,
377
- { headers }
376
+ const {data} = await axios.get<ResponseEntry>(
377
+ `${this.baseURL}/user/check-existing?${prop}=${value}`,
378
+ {headers}
378
379
  );
379
380
  return data;
380
381
  } catch (error: any) {
@@ -384,7 +385,7 @@ export default class Dmart {
384
385
 
385
386
  public static async get_profile() {
386
387
  try {
387
- const { data } = await axios.get<ProfileResponse>(
388
+ const {data} = await axios.get<ProfileResponse>(
388
389
  this.baseURL + "/user/profile",
389
390
  {
390
391
  headers,
@@ -406,17 +407,17 @@ export default class Dmart {
406
407
  }
407
408
  }
408
409
 
409
- public static async query(query: QueryRequest): Promise<ApiQueryResponse|null> {
410
+ public static async query(query: QueryRequest, scope: string = "managed"): Promise<ApiQueryResponse | null> {
410
411
  try {
411
412
  if (query.type != QueryType.spaces) {
412
413
  query.sort_type = query.sort_type || SortyType.ascending;
413
414
  query.sort_by = query.sort_by || "created_at";
414
415
  }
415
416
  query.subpath = query.subpath.replace(/\/+/g, "/");
416
- const { data } = await axios.post<ApiQueryResponse>(
417
- this.baseURL + "/managed/query",
417
+ const {data} = await axios.post<ApiQueryResponse>(
418
+ this.baseURL + `/${scope}/query`,
418
419
  query,
419
- { headers , timeout: 3000 }
420
+ {headers, timeout: 3000}
420
421
  );
421
422
  return data;
422
423
  } catch (e) {
@@ -429,10 +430,10 @@ export default class Dmart {
429
430
  query.sort_type = query.sort_type || SortyType.ascending;
430
431
  query.sort_by = "created_at";
431
432
  query.subpath = query.subpath.replace(/\/+/g, "/");
432
- const { data } = await axios.post<ApiQueryResponse>(
433
+ const {data} = await axios.post<ApiQueryResponse>(
433
434
  this.baseURL + "/managed/csv",
434
435
  query,
435
- { headers }
436
+ {headers}
436
437
  );
437
438
  return data;
438
439
  } catch (error: any) {
@@ -442,10 +443,10 @@ export default class Dmart {
442
443
 
443
444
  public static async space(action: ActionRequest): Promise<ActionResponse> {
444
445
  try {
445
- const { data } = await axios.post<ActionResponse>(
446
+ const {data} = await axios.post<ActionResponse>(
446
447
  this.baseURL + "/managed/space",
447
448
  action,
448
- { headers }
449
+ {headers}
449
450
  );
450
451
  return data;
451
452
  } catch (error: any) {
@@ -455,10 +456,10 @@ export default class Dmart {
455
456
 
456
457
  public static async request(action: ActionRequest): Promise<ActionResponse> {
457
458
  try {
458
- const { data } = await axios.post<ActionResponse>(
459
+ const {data} = await axios.post<ActionResponse>(
459
460
  this.baseURL + "/managed/request",
460
461
  action,
461
- { headers }
462
+ {headers}
462
463
  );
463
464
  return data;
464
465
  } catch (error: any) {
@@ -473,17 +474,17 @@ export default class Dmart {
473
474
  shortname: string,
474
475
  retrieve_json_payload: boolean = false,
475
476
  retrieve_attachments: boolean = false,
476
- validate_schema: boolean = true
477
- ): Promise<ResponseEntry|null> {
477
+ validate_schema: boolean = true,
478
+ scope: string = "managed"
479
+ ): Promise<ResponseEntry | null> {
478
480
  try {
479
481
  if (!subpath || subpath == "/") subpath = "__root__";
480
- const { data } = await axios.get<ResponseEntry>(
481
- this.baseURL +
482
- `/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;
@@ -548,9 +549,8 @@ export default class Dmart {
548
549
  branch_name?: string
549
550
  ) {
550
551
  try {
551
- const endpoint = "/managed/data-asset";
552
- const url = `${this.baseURL}${endpoint}`;
553
- const { data } = await axios.post(
552
+ const url = `${this.baseURL}/managed/data-asset`;
553
+ const {data} = await axios.post(
554
554
  url,
555
555
  {
556
556
  space_name: spaceName,
@@ -562,9 +562,8 @@ export default class Dmart {
562
562
  filter_data_assets,
563
563
  branch_name,
564
564
  },
565
- { headers }
565
+ {headers}
566
566
  );
567
-
568
567
  return data;
569
568
  } catch (error: any) {
570
569
  return error;
@@ -606,11 +605,11 @@ export default class Dmart {
606
605
  subpath: string,
607
606
  parent_shortname: string,
608
607
  shortname: string,
609
- ext: string
608
+ ext: string,
609
+ scope: string = "managed"
610
610
  ) {
611
611
  return (
612
- this.baseURL +
613
- `/managed/payload/${resource_type}/${space_name}/${subpath.replace(
612
+ `${this.baseURL}/${scope}/payload/${resource_type}/${space_name}/${subpath.replace(
614
613
  /\/+$/,
615
614
  ""
616
615
  )}/${parent_shortname}/${shortname}.${ext}`.replaceAll("..", ".")
@@ -618,9 +617,9 @@ export default class Dmart {
618
617
  }
619
618
 
620
619
  public static async get_space_health(space_name: string) {
621
- const { data } = await axios.get<
620
+ const {data} = await axios.get<
622
621
  ApiQueryResponse & { attributes: { folders_report: Object } }
623
- >(this.baseURL + `/managed/health/${space_name}`, { headers });
622
+ >(this.baseURL + `/managed/health/${space_name}`, {headers});
624
623
  return data;
625
624
  }
626
625
 
@@ -629,39 +628,41 @@ export default class Dmart {
629
628
  space_name: string,
630
629
  subpath: string,
631
630
  shortname: string,
631
+ scope: string = "managed"
632
632
  ) {
633
- const { data } = await axios.get<any>(
634
- this.baseURL +
635
- `/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}`,
636
- { headers }
633
+ const {data} = await axios.get<any>(
634
+ `${this.baseURL}/${scope}/payload/${resource_type}/${space_name}/${subpath}/${shortname}`,
635
+ {headers}
637
636
  );
638
637
  return data;
639
638
  }
639
+
640
640
  public static async get_payload(
641
641
  resource_type: string,
642
642
  space_name: string,
643
643
  subpath: string,
644
644
  shortname: string,
645
- ext: string = ".json"
645
+ ext: string = ".json",
646
+ scope: string = "managed"
646
647
  ) {
647
- const { data } = await axios.get<any>(
648
- this.baseURL +
649
- `/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
650
- { headers }
648
+ const {data} = await axios.get<any>(
649
+ `${this.baseURL}/${scope}/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
650
+ {headers}
651
651
  );
652
652
  return data;
653
653
  }
654
+
654
655
  public static async get_payload_content(
655
656
  resource_type: string,
656
657
  space_name: string,
657
658
  subpath: string,
658
659
  shortname: string,
659
- ext: string = ".json"
660
+ ext: string = ".json",
661
+ scope: string = "managed"
660
662
  ) {
661
- const { data } = await axios.get<any>(
662
- this.baseURL +
663
- `/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
664
- { headers }
663
+ const {data} = await axios.get<any>(
664
+ `${this.baseURL}/${scope}/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
665
+ {headers}
665
666
  );
666
667
  return data;
667
668
  }
@@ -676,19 +677,36 @@ export default class Dmart {
676
677
  ) {
677
678
  try {
678
679
  const payload: any = {}
679
- if(resolution){
680
+ if (resolution) {
680
681
  payload.resolution = resolution;
681
682
  }
682
- if(comment){
683
+ if (comment) {
683
684
  payload.comment = comment;
684
685
  }
685
- const { data } = await axios.put<
686
+ const {data} = await axios.put<
686
687
  ApiQueryResponse & { attributes: { folders_report: Object } }
687
688
  >(
688
- this.baseURL +
689
- `/managed/progress-ticket/${space_name}/${subpath}/${shortname}/${action}`,
689
+ `${this.baseURL}/managed/progress-ticket/${space_name}/${subpath}/${shortname}/${action}`,
690
690
  payload,
691
- { headers }
691
+ {headers}
692
+ );
693
+ return data;
694
+ } catch (error: any) {
695
+ return error.response.data;
696
+ }
697
+ }
698
+
699
+ public static async submit(
700
+ spaceName: string,
701
+ schemaShortname: string,
702
+ subpath: string,
703
+ record: any // More general than Map<String, dynamic>
704
+ ) {
705
+ try {
706
+ const {data} = await axios.post(
707
+ `${this.baseURL}/public/submit/${spaceName}/${schemaShortname}/${subpath}`,
708
+ record,
709
+ {headers}
692
710
  );
693
711
  return data;
694
712
  } catch (error: any) {
@@ -697,17 +715,16 @@ export default class Dmart {
697
715
  }
698
716
 
699
717
  public static async get_manifest() {
700
- const { data } = await axios.get<any>(this.baseURL + `/info/manifest`, {
718
+ const {data} = await axios.get<any>(this.baseURL + `/info/manifest`, {
701
719
  headers,
702
720
  });
703
721
  return data;
704
722
  }
705
723
 
706
724
  public static async get_settings() {
707
- const { data } = await axios.get<any>(this.baseURL + `/info/settings`, {
725
+ const {data} = await axios.get<any>(this.baseURL + `/info/settings`, {
708
726
  headers,
709
727
  });
710
728
  return data;
711
729
  }
712
730
  }
713
- // 23 funcs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edraj/tsdmart",
3
- "version": "1.0.5",
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",