@bexis2/bexis2-core-ui 0.4.59 → 0.4.60

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.
@@ -10,10 +10,11 @@ import Notification from "./Notification.svelte";
10
10
  import { computePosition, autoUpdate, offset, shift, flip, arrow } from "@floating-ui/dom";
11
11
  import { storePopup } from "@skeletonlabs/skeleton";
12
12
  import { breadcrumbStore, notificationStore } from "../../stores/pageStores";
13
- import { errorStore } from "../../stores/apiStores";
13
+ import { errorStore, csrfTokenStore } from "../../stores/apiStores";
14
14
  storePopup.set({ computePosition, autoUpdate, offset, shift, flip, arrow });
15
15
  import Docs from "./Docs.svelte";
16
16
  import GoToTop from "./GoToTop.svelte";
17
+ import { getAntiForgeryToken } from "./PageCaller";
17
18
  export let title = "";
18
19
  export let note = "";
19
20
  export let links = [];
@@ -22,6 +23,7 @@ export let footer = true;
22
23
  export let help = false;
23
24
  export let contentLayoutType = pageContentLayoutType.center;
24
25
  export let fixLeft = true;
26
+ let aftIsReady = false;
25
27
  errorStore.subscribe((error) => {
26
28
  console.log("\u{1F680} ~ errorStore.subscribe ~ value:", error.error);
27
29
  notificationStore.showNotification({
@@ -33,6 +35,13 @@ onMount(async () => {
33
35
  console.log("page");
34
36
  breadcrumbStore.clean();
35
37
  breadcrumbStore.addItem({ label: title, link: window.location.pathname });
38
+ const data = await getAntiForgeryToken();
39
+ csrfTokenStore.set(data.csrfToken);
40
+ });
41
+ csrfTokenStore.subscribe((value) => {
42
+ if (value.length > 0) {
43
+ aftIsReady = true;
44
+ }
36
45
  });
37
46
  let app;
38
47
  function scrollToTop() {
@@ -61,6 +70,8 @@ function scrollToTop() {
61
70
 
62
71
  <slot name="description" />
63
72
 
73
+ {#if aftIsReady}
74
+
64
75
  <div class="flex flex-initial space-x-5">
65
76
  {#if $$slots.left}
66
77
  <div class="p-5 flex-shrink-0 w-96 w-min-96 border-y border-solid border-surface-500">
@@ -89,7 +100,7 @@ function scrollToTop() {
89
100
  {/if}
90
101
  </div>
91
102
 
92
-
103
+ {/if}
93
104
 
94
105
  <GoToTop/>
95
106
  <HelpPopUp active={help} />
@@ -1,2 +1,3 @@
1
1
  export function getFooter(): Promise<any>;
2
2
  export function getHeader(): Promise<any>;
3
+ export function getAntiForgeryToken(): Promise<any>;
@@ -17,3 +17,12 @@ export const getHeader = async () => {
17
17
  console.error(error);
18
18
  }
19
19
  };
20
+
21
+ export const getAntiForgeryToken = async () => {
22
+ try {
23
+ const response = await Api.get('/tokens/getAntiForgeryToken');
24
+ return response.data;
25
+ } catch (error) {
26
+ console.error(error);
27
+ }
28
+ };
@@ -1,6 +1,6 @@
1
1
  // Api.js
2
2
  import axios from 'axios';
3
- import { host, username, password, errorStore } from '../stores/apiStores';
3
+ import { host, username, password, errorStore, csrfToken } from '../stores/apiStores';
4
4
  console.log('setup axios');
5
5
  // implement a method to execute all the request from here.
6
6
  const apiRequest = (method, url, request) => {
@@ -8,8 +8,10 @@ const apiRequest = (method, url, request) => {
8
8
  const axiosAPI = axios.create({
9
9
  baseURL: host
10
10
  });
11
+ const requestVerificationToken = csrfToken;
11
12
  const headers = {
12
- authorization: 'Basic ' + btoa(username + ':' + password)
13
+ authorization: 'Basic ' + btoa(username + ':' + password),
14
+ '__RequestVerificationToken': requestVerificationToken
13
15
  };
14
16
  //using the axios instance to perform the request that received from each http method
15
17
  return axiosAPI({
@@ -19,7 +21,7 @@ const apiRequest = (method, url, request) => {
19
21
  headers
20
22
  })
21
23
  .then((res) => {
22
- // console.log("res",res);
24
+ //console.log("res-test",res);
23
25
  return Promise.resolve(res);
24
26
  })
25
27
  .catch((er) => {
@@ -2,5 +2,7 @@ import { errorType } from '../models/Models';
2
2
  export declare let host: string;
3
3
  export declare let username: string;
4
4
  export declare let password: string;
5
+ export declare let csrfToken: string;
6
+ export declare const csrfTokenStore: import("svelte/store").Writable<string>;
5
7
  export declare const errorStore: import("svelte/store").Writable<errorType>;
6
8
  export declare function setApiConfig(_host: string, _user: string, _pw: string): void;
@@ -3,6 +3,8 @@ import { errorType } from '../models/Models';
3
3
  export let host = 'window.location.origin';
4
4
  export let username = '';
5
5
  export let password = '';
6
+ export let csrfToken = '';
7
+ export const csrfTokenStore = writable('');
6
8
  const hostStore = writable(''); //writable(window.location.origin);
7
9
  const usernameStore = writable('');
8
10
  const passwordStore = writable('');
@@ -10,6 +12,9 @@ export const errorStore = writable(new errorType());
10
12
  hostStore.subscribe((value) => {
11
13
  host = value;
12
14
  });
15
+ csrfTokenStore.subscribe((value) => {
16
+ csrfToken = value;
17
+ });
13
18
  usernameStore.subscribe((value) => {
14
19
  username = value;
15
20
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bexis2/bexis2-core-ui",
3
- "version": "0.4.59",
3
+ "version": "0.4.60",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -17,7 +17,7 @@
17
17
  import { computePosition, autoUpdate, offset, shift, flip, arrow } from '@floating-ui/dom';
18
18
  import { storePopup } from '@skeletonlabs/skeleton';
19
19
  import { breadcrumbStore,notificationStore } from '$store/pageStores';
20
- import { errorStore } from '$store/apiStores';
20
+ import { errorStore,csrfTokenStore } from '$store/apiStores';
21
21
 
22
22
  storePopup.set({ computePosition, autoUpdate, offset, shift, flip, arrow });
23
23
 
@@ -27,6 +27,8 @@ import type { helpItemType, helpStoreType } from '$models/Models';
27
27
 
28
28
  import Docs from './Docs.svelte';
29
29
  import GoToTop from './GoToTop.svelte';
30
+ import { getAntiForgeryToken } from './PageCaller';
31
+
30
32
 
31
33
  export let title = '';
32
34
  export let note = '';
@@ -39,6 +41,8 @@ import type { helpItemType, helpStoreType } from '$models/Models';
39
41
  export let contentLayoutType: pageContentLayoutType = pageContentLayoutType.center;
40
42
  export let fixLeft: boolean = true;
41
43
 
44
+ let aftIsReady = false;
45
+
42
46
  errorStore.subscribe((error:errorType) => {
43
47
  console.log("🚀 ~ errorStore.subscribe ~ value:", error.error)
44
48
  notificationStore.showNotification({
@@ -51,8 +55,18 @@ import type { helpItemType, helpStoreType } from '$models/Models';
51
55
  console.log('page');
52
56
  breadcrumbStore.clean();
53
57
  breadcrumbStore.addItem({ label: title, link: window.location.pathname });
58
+ const data = await getAntiForgeryToken();
59
+ csrfTokenStore.set(data.csrfToken);
60
+ });
61
+
62
+
63
+ csrfTokenStore.subscribe(value => {
64
+ if(value.length>0){
65
+ aftIsReady = true;
66
+ }
54
67
  });
55
68
 
69
+
56
70
  let app;
57
71
  function scrollToTop() {
58
72
  app.scrollIntoView();
@@ -81,6 +95,8 @@ import type { helpItemType, helpStoreType } from '$models/Models';
81
95
 
82
96
  <slot name="description" />
83
97
 
98
+ {#if aftIsReady}
99
+
84
100
  <div class="flex flex-initial space-x-5">
85
101
  {#if $$slots.left}
86
102
  <div class="p-5 flex-shrink-0 w-96 w-min-96 border-y border-solid border-surface-500">
@@ -109,7 +125,7 @@ import type { helpItemType, helpStoreType } from '$models/Models';
109
125
  {/if}
110
126
  </div>
111
127
 
112
-
128
+ {/if}
113
129
 
114
130
  <GoToTop/>
115
131
  <HelpPopUp active={help} />
@@ -17,3 +17,12 @@ export const getHeader = async () => {
17
17
  console.error(error);
18
18
  }
19
19
  };
20
+
21
+ export const getAntiForgeryToken = async () => {
22
+ try {
23
+ const response = await Api.get('/tokens/getAntiForgeryToken');
24
+ return response.data;
25
+ } catch (error) {
26
+ console.error(error);
27
+ }
28
+ };
@@ -1,6 +1,6 @@
1
1
  // Api.js
2
2
  import axios from 'axios';
3
- import { host, username, password, errorStore } from '../stores/apiStores';
3
+ import { host, username, password, errorStore, csrfToken } from '../stores/apiStores';
4
4
  import type { errorType } from '$models/Models';
5
5
 
6
6
  console.log('setup axios');
@@ -12,10 +12,13 @@ const apiRequest = (method, url, request) => {
12
12
  baseURL: host
13
13
  });
14
14
 
15
+ const requestVerificationToken = csrfToken;
15
16
  const headers = {
16
- authorization: 'Basic ' + btoa(username + ':' + password)
17
+ authorization: 'Basic ' + btoa(username + ':' + password),
18
+ '__RequestVerificationToken': requestVerificationToken
17
19
  };
18
20
 
21
+
19
22
  //using the axios instance to perform the request that received from each http method
20
23
  return axiosAPI({
21
24
  method,
@@ -24,7 +27,7 @@ const apiRequest = (method, url, request) => {
24
27
  headers
25
28
  })
26
29
  .then((res) => {
27
- // console.log("res",res);
30
+ //console.log("res-test",res);
28
31
 
29
32
  return Promise.resolve(res);
30
33
 
@@ -4,17 +4,28 @@ import { errorType } from '$models/Models'
4
4
  export let host = 'window.location.origin';
5
5
  export let username = '';
6
6
  export let password = '';
7
+ export let csrfToken = '';
8
+
9
+
10
+ export const csrfTokenStore = writable('');
11
+
7
12
 
8
13
  const hostStore = writable(''); //writable(window.location.origin);
9
14
  const usernameStore = writable('');
10
15
  const passwordStore = writable('');
11
16
 
17
+
12
18
  export const errorStore = writable(new errorType());
13
19
 
14
20
  hostStore.subscribe((value) => {
15
21
  host = value;
16
22
  });
17
23
 
24
+ csrfTokenStore.subscribe((value) => {
25
+ csrfToken = value;
26
+ });
27
+
28
+
18
29
  usernameStore.subscribe((value) => {
19
30
  username = value;
20
31
  });
@@ -214,3 +214,5 @@ function createNotificationStore() {
214
214
 
215
215
  //crate and export the instance of the store
216
216
  export const notificationStore = createNotificationStore();
217
+
218
+