@edraj/tsdmart 1.0.4 → 1.0.6

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/README.md +2 -1
  2. package/index.ts +45 -33
  3. package/package.json +1 -1
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,6 +1,6 @@
1
1
  import axios from "axios";
2
2
 
3
- let baseURL = "http://localhost:8282";
3
+
4
4
 
5
5
  axios.defaults.withCredentials = true;
6
6
 
@@ -163,6 +163,8 @@ export enum RequestType {
163
163
  replace = "replace",
164
164
  delete = "delete",
165
165
  move = "move",
166
+ updateACL = "update_acl",
167
+ assign = "assign",
166
168
  }
167
169
 
168
170
  export enum ResourceAttachmentType {
@@ -319,10 +321,12 @@ type ApiQueryResponse = ApiResponse & {
319
321
  };
320
322
 
321
323
  export default class Dmart {
324
+ static baseURL = "http://localhost:8282";
325
+
322
326
  public static async login(shortname: string, password: string) {
323
327
  const { data } = await axios.post<
324
328
  ApiResponse & { records: Array<LoginResponseRecord> }
325
- >(baseURL + "/user/login", { shortname, password }, { headers });
329
+ >(this.baseURL + "/user/login", { shortname, password }, { headers });
326
330
  //console.log(JSON.stringify(data, null, 2));
327
331
  // FIXME settins Authorization is only needed when the code is running on the server
328
332
  /*headers.Authorization = "";
@@ -334,7 +338,7 @@ export default class Dmart {
334
338
 
335
339
  public static async logout() {
336
340
  const { data } = await axios.post<ApiResponse>(
337
- baseURL + "/user/logout",
341
+ this.baseURL + "/user/logout",
338
342
  {},
339
343
  { headers }
340
344
  );
@@ -344,7 +348,7 @@ export default class Dmart {
344
348
  public static async create_user(request: any) {
345
349
  try {
346
350
  const { data } = await axios.post<ActionResponse>(
347
- baseURL + "/user/create",
351
+ this.baseURL + "/user/create",
348
352
  request,
349
353
  { headers }
350
354
  );
@@ -357,7 +361,7 @@ export default class Dmart {
357
361
  public static async update_user(request: any) {
358
362
  try {
359
363
  const { data } = await axios.post<ActionResponse>(
360
- baseURL + "/user/profile",
364
+ this.baseURL + "/user/profile",
361
365
  request,
362
366
  { headers }
363
367
  );
@@ -370,8 +374,7 @@ export default class Dmart {
370
374
  public static async check_existing(prop: string, value: string) {
371
375
  try {
372
376
  const { data } = await axios.get<ResponseEntry>(
373
- baseURL +
374
- `/user/check-existing?${prop}=${value}`,
377
+ `${this.baseURL}/user/check-existing?${prop}=${value}`,
375
378
  { headers }
376
379
  );
377
380
  return data;
@@ -383,7 +386,7 @@ export default class Dmart {
383
386
  public static async get_profile() {
384
387
  try {
385
388
  const { data } = await axios.get<ProfileResponse>(
386
- baseURL + "/user/profile",
389
+ this.baseURL + "/user/profile",
387
390
  {
388
391
  headers,
389
392
  }
@@ -412,7 +415,7 @@ export default class Dmart {
412
415
  }
413
416
  query.subpath = query.subpath.replace(/\/+/g, "/");
414
417
  const { data } = await axios.post<ApiQueryResponse>(
415
- baseURL + "/managed/query",
418
+ this.baseURL + "/managed/query",
416
419
  query,
417
420
  { headers , timeout: 3000 }
418
421
  );
@@ -428,7 +431,7 @@ export default class Dmart {
428
431
  query.sort_by = "created_at";
429
432
  query.subpath = query.subpath.replace(/\/+/g, "/");
430
433
  const { data } = await axios.post<ApiQueryResponse>(
431
- baseURL + "/managed/csv",
434
+ this.baseURL + "/managed/csv",
432
435
  query,
433
436
  { headers }
434
437
  );
@@ -441,7 +444,7 @@ export default class Dmart {
441
444
  public static async space(action: ActionRequest): Promise<ActionResponse> {
442
445
  try {
443
446
  const { data } = await axios.post<ActionResponse>(
444
- baseURL + "/managed/space",
447
+ this.baseURL + "/managed/space",
445
448
  action,
446
449
  { headers }
447
450
  );
@@ -454,7 +457,7 @@ export default class Dmart {
454
457
  public static async request(action: ActionRequest): Promise<ActionResponse> {
455
458
  try {
456
459
  const { data } = await axios.post<ActionResponse>(
457
- baseURL + "/managed/request",
460
+ this.baseURL + "/managed/request",
458
461
  action,
459
462
  { headers }
460
463
  );
@@ -476,8 +479,7 @@ export default class Dmart {
476
479
  try {
477
480
  if (!subpath || subpath == "/") subpath = "__root__";
478
481
  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(
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(
481
483
  /\/+/g,
482
484
  "/"
483
485
  ),
@@ -526,7 +528,7 @@ export default class Dmart {
526
528
  const headers = { "Content-Type": "multipart/form-data" };
527
529
 
528
530
  const { data } = await axios.post<ApiResponse>(
529
- baseURL + "/managed/resource_with_payload",
531
+ this.baseURL + "/managed/resource_with_payload",
530
532
  form_data,
531
533
  { headers }
532
534
  );
@@ -546,8 +548,7 @@ export default class Dmart {
546
548
  branch_name?: string
547
549
  ) {
548
550
  try {
549
- const endpoint = "/managed/data-asset";
550
- const url = `${baseURL}${endpoint}`;
551
+ const url = `${this.baseURL}/managed/data-asset`;
551
552
  const { data } = await axios.post(
552
553
  url,
553
554
  {
@@ -562,7 +563,6 @@ export default class Dmart {
562
563
  },
563
564
  { headers }
564
565
  );
565
-
566
566
  return data;
567
567
  } catch (error: any) {
568
568
  return error;
@@ -598,7 +598,7 @@ export default class Dmart {
598
598
  });
599
599
  }
600
600
 
601
- public get_attachment_url(
601
+ public static get_attachment_url(
602
602
  resource_type: ResourceType,
603
603
  space_name: string,
604
604
  subpath: string,
@@ -607,8 +607,7 @@ export default class Dmart {
607
607
  ext: string
608
608
  ) {
609
609
  return (
610
- baseURL +
611
- `/managed/payload/${resource_type}/${space_name}/${subpath.replace(
610
+ `${this.baseURL}/managed/payload/${resource_type}/${space_name}/${subpath.replace(
612
611
  /\/+$/,
613
612
  ""
614
613
  )}/${parent_shortname}/${shortname}.${ext}`.replaceAll("..", ".")
@@ -618,7 +617,7 @@ export default class Dmart {
618
617
  public static async get_space_health(space_name: string) {
619
618
  const { data } = await axios.get<
620
619
  ApiQueryResponse & { attributes: { folders_report: Object } }
621
- >(baseURL + `/managed/health/${space_name}`, { headers });
620
+ >(this.baseURL + `/managed/health/${space_name}`, { headers });
622
621
  return data;
623
622
  }
624
623
 
@@ -629,8 +628,7 @@ export default class Dmart {
629
628
  shortname: string,
630
629
  ) {
631
630
  const { data } = await axios.get<any>(
632
- baseURL +
633
- `/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}`,
631
+ `${this.baseURL}/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}`,
634
632
  { headers }
635
633
  );
636
634
  return data;
@@ -643,8 +641,7 @@ export default class Dmart {
643
641
  ext: string = ".json"
644
642
  ) {
645
643
  const { data } = await axios.get<any>(
646
- baseURL +
647
- `/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
644
+ `${this.baseURL}/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
648
645
  { headers }
649
646
  );
650
647
  return data;
@@ -657,8 +654,7 @@ export default class Dmart {
657
654
  ext: string = ".json"
658
655
  ) {
659
656
  const { data } = await axios.get<any>(
660
- baseURL +
661
- `/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
657
+ `${this.baseURL}/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
662
658
  { headers }
663
659
  );
664
660
  return data;
@@ -683,8 +679,7 @@ export default class Dmart {
683
679
  const { data } = await axios.put<
684
680
  ApiQueryResponse & { attributes: { folders_report: Object } }
685
681
  >(
686
- baseURL +
687
- `/managed/progress-ticket/${space_name}/${subpath}/${shortname}/${action}`,
682
+ `${this.baseURL}/managed/progress-ticket/${space_name}/${subpath}/${shortname}/${action}`,
688
683
  payload,
689
684
  { headers }
690
685
  );
@@ -694,18 +689,35 @@ export default class Dmart {
694
689
  }
695
690
  }
696
691
 
692
+ public static async submit(
693
+ spaceName: string,
694
+ schemaShortname: string,
695
+ subpath: string,
696
+ record: any // More general than Map<String, dynamic>
697
+ ){
698
+ try {
699
+ const {data} = await axios.post(
700
+ `${this.baseURL}/public/submit/${spaceName}/${schemaShortname}/${subpath}`,
701
+ record,
702
+ {headers}
703
+ );
704
+ return data;
705
+ } catch (error: any) {
706
+ return error.response.data;
707
+ }
708
+ }
709
+
697
710
  public static async get_manifest() {
698
- const { data } = await axios.get<any>(baseURL + `/info/manifest`, {
711
+ const { data } = await axios.get<any>(this.baseURL + `/info/manifest`, {
699
712
  headers,
700
713
  });
701
714
  return data;
702
715
  }
703
716
 
704
717
  public static async get_settings() {
705
- const { data } = await axios.get<any>(baseURL + `/info/settings`, {
718
+ const { data } = await axios.get<any>(this.baseURL + `/info/settings`, {
706
719
  headers,
707
720
  });
708
721
  return data;
709
722
  }
710
723
  }
711
- // 23 funcs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edraj/tsdmart",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
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",