@edraj/tsdmart 1.0.4 → 1.0.5

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 (2) hide show
  1. package/index.ts +25 -23
  2. package/package.json +1 -1
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
 
@@ -319,10 +319,12 @@ type ApiQueryResponse = ApiResponse & {
319
319
  };
320
320
 
321
321
  export default class Dmart {
322
+ static baseURL = "http://localhost:8282";
323
+
322
324
  public static async login(shortname: string, password: string) {
323
325
  const { data } = await axios.post<
324
326
  ApiResponse & { records: Array<LoginResponseRecord> }
325
- >(baseURL + "/user/login", { shortname, password }, { headers });
327
+ >(this.baseURL + "/user/login", { shortname, password }, { headers });
326
328
  //console.log(JSON.stringify(data, null, 2));
327
329
  // FIXME settins Authorization is only needed when the code is running on the server
328
330
  /*headers.Authorization = "";
@@ -334,7 +336,7 @@ export default class Dmart {
334
336
 
335
337
  public static async logout() {
336
338
  const { data } = await axios.post<ApiResponse>(
337
- baseURL + "/user/logout",
339
+ this.baseURL + "/user/logout",
338
340
  {},
339
341
  { headers }
340
342
  );
@@ -344,7 +346,7 @@ export default class Dmart {
344
346
  public static async create_user(request: any) {
345
347
  try {
346
348
  const { data } = await axios.post<ActionResponse>(
347
- baseURL + "/user/create",
349
+ this.baseURL + "/user/create",
348
350
  request,
349
351
  { headers }
350
352
  );
@@ -357,7 +359,7 @@ export default class Dmart {
357
359
  public static async update_user(request: any) {
358
360
  try {
359
361
  const { data } = await axios.post<ActionResponse>(
360
- baseURL + "/user/profile",
362
+ this.baseURL + "/user/profile",
361
363
  request,
362
364
  { headers }
363
365
  );
@@ -370,7 +372,7 @@ export default class Dmart {
370
372
  public static async check_existing(prop: string, value: string) {
371
373
  try {
372
374
  const { data } = await axios.get<ResponseEntry>(
373
- baseURL +
375
+ this.baseURL +
374
376
  `/user/check-existing?${prop}=${value}`,
375
377
  { headers }
376
378
  );
@@ -383,7 +385,7 @@ export default class Dmart {
383
385
  public static async get_profile() {
384
386
  try {
385
387
  const { data } = await axios.get<ProfileResponse>(
386
- baseURL + "/user/profile",
388
+ this.baseURL + "/user/profile",
387
389
  {
388
390
  headers,
389
391
  }
@@ -412,7 +414,7 @@ export default class Dmart {
412
414
  }
413
415
  query.subpath = query.subpath.replace(/\/+/g, "/");
414
416
  const { data } = await axios.post<ApiQueryResponse>(
415
- baseURL + "/managed/query",
417
+ this.baseURL + "/managed/query",
416
418
  query,
417
419
  { headers , timeout: 3000 }
418
420
  );
@@ -428,7 +430,7 @@ export default class Dmart {
428
430
  query.sort_by = "created_at";
429
431
  query.subpath = query.subpath.replace(/\/+/g, "/");
430
432
  const { data } = await axios.post<ApiQueryResponse>(
431
- baseURL + "/managed/csv",
433
+ this.baseURL + "/managed/csv",
432
434
  query,
433
435
  { headers }
434
436
  );
@@ -441,7 +443,7 @@ export default class Dmart {
441
443
  public static async space(action: ActionRequest): Promise<ActionResponse> {
442
444
  try {
443
445
  const { data } = await axios.post<ActionResponse>(
444
- baseURL + "/managed/space",
446
+ this.baseURL + "/managed/space",
445
447
  action,
446
448
  { headers }
447
449
  );
@@ -454,7 +456,7 @@ export default class Dmart {
454
456
  public static async request(action: ActionRequest): Promise<ActionResponse> {
455
457
  try {
456
458
  const { data } = await axios.post<ActionResponse>(
457
- baseURL + "/managed/request",
459
+ this.baseURL + "/managed/request",
458
460
  action,
459
461
  { headers }
460
462
  );
@@ -476,7 +478,7 @@ export default class Dmart {
476
478
  try {
477
479
  if (!subpath || subpath == "/") subpath = "__root__";
478
480
  const { data } = await axios.get<ResponseEntry>(
479
- baseURL +
481
+ this.baseURL +
480
482
  `/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
  "/"
@@ -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
  );
@@ -547,7 +549,7 @@ export default class Dmart {
547
549
  ) {
548
550
  try {
549
551
  const endpoint = "/managed/data-asset";
550
- const url = `${baseURL}${endpoint}`;
552
+ const url = `${this.baseURL}${endpoint}`;
551
553
  const { data } = await axios.post(
552
554
  url,
553
555
  {
@@ -598,7 +600,7 @@ export default class Dmart {
598
600
  });
599
601
  }
600
602
 
601
- public get_attachment_url(
603
+ public static get_attachment_url(
602
604
  resource_type: ResourceType,
603
605
  space_name: string,
604
606
  subpath: string,
@@ -607,7 +609,7 @@ export default class Dmart {
607
609
  ext: string
608
610
  ) {
609
611
  return (
610
- baseURL +
612
+ this.baseURL +
611
613
  `/managed/payload/${resource_type}/${space_name}/${subpath.replace(
612
614
  /\/+$/,
613
615
  ""
@@ -618,7 +620,7 @@ export default class Dmart {
618
620
  public static async get_space_health(space_name: string) {
619
621
  const { data } = await axios.get<
620
622
  ApiQueryResponse & { attributes: { folders_report: Object } }
621
- >(baseURL + `/managed/health/${space_name}`, { headers });
623
+ >(this.baseURL + `/managed/health/${space_name}`, { headers });
622
624
  return data;
623
625
  }
624
626
 
@@ -629,7 +631,7 @@ export default class Dmart {
629
631
  shortname: string,
630
632
  ) {
631
633
  const { data } = await axios.get<any>(
632
- baseURL +
634
+ this.baseURL +
633
635
  `/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}`,
634
636
  { headers }
635
637
  );
@@ -643,7 +645,7 @@ export default class Dmart {
643
645
  ext: string = ".json"
644
646
  ) {
645
647
  const { data } = await axios.get<any>(
646
- baseURL +
648
+ this.baseURL +
647
649
  `/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
648
650
  { headers }
649
651
  );
@@ -657,7 +659,7 @@ export default class Dmart {
657
659
  ext: string = ".json"
658
660
  ) {
659
661
  const { data } = await axios.get<any>(
660
- baseURL +
662
+ this.baseURL +
661
663
  `/managed/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
662
664
  { headers }
663
665
  );
@@ -683,7 +685,7 @@ export default class Dmart {
683
685
  const { data } = await axios.put<
684
686
  ApiQueryResponse & { attributes: { folders_report: Object } }
685
687
  >(
686
- baseURL +
688
+ this.baseURL +
687
689
  `/managed/progress-ticket/${space_name}/${subpath}/${shortname}/${action}`,
688
690
  payload,
689
691
  { headers }
@@ -695,14 +697,14 @@ export default class Dmart {
695
697
  }
696
698
 
697
699
  public static async get_manifest() {
698
- const { data } = await axios.get<any>(baseURL + `/info/manifest`, {
700
+ const { data } = await axios.get<any>(this.baseURL + `/info/manifest`, {
699
701
  headers,
700
702
  });
701
703
  return data;
702
704
  }
703
705
 
704
706
  public static async get_settings() {
705
- const { data } = await axios.get<any>(baseURL + `/info/settings`, {
707
+ const { data } = await axios.get<any>(this.baseURL + `/info/settings`, {
706
708
  headers,
707
709
  });
708
710
  return data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edraj/tsdmart",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
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",