@fy-/fws-vue 2.3.58 → 2.3.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.
- package/composables/rest.ts +13 -1
- package/package.json +1 -1
package/composables/rest.ts
CHANGED
|
@@ -39,6 +39,8 @@ const inFlightRequests = new Map<number, Promise<any>>()
|
|
|
39
39
|
// Detect if we're in SSR mode once and cache the result
|
|
40
40
|
let isSSRMode: boolean | null = null
|
|
41
41
|
|
|
42
|
+
const secret = import.meta.env.VITE_API_SECRET
|
|
43
|
+
|
|
42
44
|
// Memoized function to extract URL pathname and search for hashing
|
|
43
45
|
function getUrlForHash(url: string): string {
|
|
44
46
|
const cached = urlParseCache.get(url)
|
|
@@ -134,8 +136,18 @@ params?: RestParams,
|
|
|
134
136
|
|
|
135
137
|
// Create the actual request function
|
|
136
138
|
const performRequest = async (): Promise<ResultType> => {
|
|
139
|
+
const h: { [key: string]: string } = {}
|
|
140
|
+
const timestamp = Date.now()
|
|
141
|
+
|
|
142
|
+
if (secret && secret !== '') {
|
|
143
|
+
const signature = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(`${method}${url}${timestamp}${secret}`),
|
|
144
|
+
)
|
|
145
|
+
h['X-Timestamp'] = timestamp.toString()
|
|
146
|
+
h['X-Signature'] = btoa(String.fromCharCode(...new Uint8Array(signature)))
|
|
147
|
+
}
|
|
148
|
+
|
|
137
149
|
try {
|
|
138
|
-
const restResult: ResultType = await rest(url, method, params)
|
|
150
|
+
const restResult: ResultType = await rest(url, method, params, h)
|
|
139
151
|
|
|
140
152
|
// Store result in server router if in SSR mode
|
|
141
153
|
if (checkSSRMode()) {
|