@globalbrain/sefirot 3.50.0 → 3.51.1
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/lib/composables/Url.ts +12 -3
- package/lib/http/Http.ts +8 -0
- package/package.json +1 -1
package/lib/composables/Url.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import isEqual from 'lodash-es/isEqual'
|
|
2
|
-
import { type MaybeRef, nextTick, unref, watch } from 'vue'
|
|
2
|
+
import { type MaybeRef, computed, nextTick, unref, watch } from 'vue'
|
|
3
3
|
import { type LocationQuery, useRoute, useRouter } from 'vue-router'
|
|
4
4
|
|
|
5
5
|
export interface UseUrlQuerySyncOptions {
|
|
@@ -21,13 +21,22 @@ export function useUrlQuerySync(
|
|
|
21
21
|
const route = useRoute()
|
|
22
22
|
const router = useRouter()
|
|
23
23
|
|
|
24
|
+
const routeQuery = computed(() => ({
|
|
25
|
+
path: route.path,
|
|
26
|
+
query: route.query
|
|
27
|
+
}))
|
|
28
|
+
|
|
24
29
|
const flattenedDefaultState = flattenObject(unref(state))
|
|
25
30
|
|
|
26
31
|
let isSyncing = false
|
|
27
32
|
|
|
28
33
|
watch(
|
|
29
|
-
|
|
30
|
-
async () => {
|
|
34
|
+
routeQuery,
|
|
35
|
+
async (to, from) => {
|
|
36
|
+
if (from && from.path !== to.path) {
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
|
|
31
40
|
if (!isSyncing) {
|
|
32
41
|
isSyncing = true
|
|
33
42
|
await setState()
|
package/lib/http/Http.ts
CHANGED
|
@@ -5,6 +5,8 @@ import { type FetchOptions, type FetchRequest, type FetchResponse, ofetch } from
|
|
|
5
5
|
import { stringify } from 'qs'
|
|
6
6
|
import { type Lang } from '../composables/Lang'
|
|
7
7
|
|
|
8
|
+
type Awaitable<T> = T | PromiseLike<T>
|
|
9
|
+
|
|
8
10
|
export interface HttpClient {
|
|
9
11
|
<T = any>(request: FetchRequest, options?: Omit<FetchOptions, 'method'>): Promise<T>
|
|
10
12
|
raw<T = any>(request: FetchRequest, options?: Omit<FetchOptions, 'method'>): Promise<FetchResponse<T>>
|
|
@@ -16,6 +18,7 @@ export interface HttpOptions {
|
|
|
16
18
|
client?: HttpClient
|
|
17
19
|
lang?: Lang
|
|
18
20
|
payloadKey?: string
|
|
21
|
+
headers?: () => Awaitable<Record<string, string>>
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
export class Http {
|
|
@@ -24,6 +27,7 @@ export class Http {
|
|
|
24
27
|
private static client: HttpClient = ofetch
|
|
25
28
|
private static lang: Lang | undefined = undefined
|
|
26
29
|
private static payloadKey = '__payload__'
|
|
30
|
+
private static headers: () => Awaitable<Record<string, string>> = async () => ({})
|
|
27
31
|
|
|
28
32
|
static config(options: HttpOptions) {
|
|
29
33
|
if (options.baseUrl) {
|
|
@@ -41,6 +45,9 @@ export class Http {
|
|
|
41
45
|
if (options.payloadKey) {
|
|
42
46
|
Http.payloadKey = options.payloadKey
|
|
43
47
|
}
|
|
48
|
+
if (options.headers) {
|
|
49
|
+
Http.headers = options.headers
|
|
50
|
+
}
|
|
44
51
|
}
|
|
45
52
|
|
|
46
53
|
private async ensureXsrfToken(): Promise<string | undefined> {
|
|
@@ -81,6 +88,7 @@ export class Http {
|
|
|
81
88
|
...options,
|
|
82
89
|
headers: {
|
|
83
90
|
Accept: 'application/json',
|
|
91
|
+
...(await Http.headers()),
|
|
84
92
|
...(xsrfToken && { 'X-Xsrf-Token': xsrfToken }),
|
|
85
93
|
...(Http.lang && { 'Accept-Language': Http.lang }),
|
|
86
94
|
...options.headers
|