@viasoftbr/shared-ui 0.0.7-2 → 0.0.7-4
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/dist/components.cjs +157 -42
- package/dist/components.js +157 -42
- package/dist/hooks.cjs +98 -17
- package/dist/hooks.js +98 -17
- package/dist/index.cjs +159 -43
- package/dist/index.js +159 -43
- package/dist/services/api.d.ts +19 -33
- package/dist/services.cjs +159 -43
- package/dist/services.js +159 -43
- package/dist/types/websocket.d.ts +14 -24
- package/package.json +1 -1
- package/dist/components/RemoteModule.d.ts +0 -8
- package/dist/package.json +0 -111
- package/dist/services/loadRemoteModule.d.ts +0 -9
- package/dist/services/metadataLoader.d.ts +0 -9
package/dist/hooks.cjs
CHANGED
|
@@ -2793,19 +2793,24 @@ function formatAxiosError(err) {
|
|
|
2793
2793
|
return err instanceof Error ? err : new Error(String(err));
|
|
2794
2794
|
}
|
|
2795
2795
|
var fetchApi = {
|
|
2796
|
-
getJson: async (path, params,
|
|
2796
|
+
getJson: async (path, params, headersOrOptions) => {
|
|
2797
2797
|
try {
|
|
2798
|
-
const
|
|
2798
|
+
const requestOptions = normalizeRequestOptions(params, headersOrOptions);
|
|
2799
|
+
const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
2800
|
+
params: withTokenQueryParams(requestOptions),
|
|
2801
|
+
headers: requestOptions.headers
|
|
2802
|
+
});
|
|
2799
2803
|
return response.data;
|
|
2800
2804
|
} catch (e) {
|
|
2801
2805
|
throw formatAxiosError(e);
|
|
2802
2806
|
}
|
|
2803
2807
|
},
|
|
2804
|
-
getText: async (path, params,
|
|
2808
|
+
getText: async (path, params, headersOrOptions) => {
|
|
2805
2809
|
try {
|
|
2810
|
+
const requestOptions = normalizeRequestOptions(params, headersOrOptions);
|
|
2806
2811
|
const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
2807
|
-
params,
|
|
2808
|
-
headers,
|
|
2812
|
+
params: withTokenQueryParams(requestOptions),
|
|
2813
|
+
headers: requestOptions.headers,
|
|
2809
2814
|
responseType: "text"
|
|
2810
2815
|
});
|
|
2811
2816
|
return response.data;
|
|
@@ -2813,53 +2818,129 @@ var fetchApi = {
|
|
|
2813
2818
|
throw formatAxiosError(e);
|
|
2814
2819
|
}
|
|
2815
2820
|
},
|
|
2816
|
-
getVoid: async (path, params,
|
|
2821
|
+
getVoid: async (path, params, headersOrOptions) => {
|
|
2817
2822
|
try {
|
|
2818
|
-
|
|
2823
|
+
const requestOptions = normalizeRequestOptions(params, headersOrOptions);
|
|
2824
|
+
await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
2825
|
+
params: withTokenQueryParams(requestOptions),
|
|
2826
|
+
headers: requestOptions.headers
|
|
2827
|
+
});
|
|
2819
2828
|
} catch (e) {
|
|
2820
2829
|
throw formatAxiosError(e);
|
|
2821
2830
|
}
|
|
2822
2831
|
},
|
|
2823
|
-
postJson: async (path, payload,
|
|
2832
|
+
postJson: async (path, payload, headersOrOptions) => {
|
|
2824
2833
|
try {
|
|
2825
|
-
const
|
|
2834
|
+
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
2835
|
+
const response = await (path.includes("/auth") ? authApi : api).post(path.replace("/auth", ""), payload, {
|
|
2836
|
+
headers: requestOptions.headers,
|
|
2837
|
+
params: withTokenQueryParams(requestOptions)
|
|
2838
|
+
});
|
|
2826
2839
|
return response.data;
|
|
2827
2840
|
} catch (e) {
|
|
2828
2841
|
throw formatAxiosError(e);
|
|
2829
2842
|
}
|
|
2830
2843
|
},
|
|
2831
|
-
patchJson: async (path, payload,
|
|
2844
|
+
patchJson: async (path, payload, headersOrOptions) => {
|
|
2832
2845
|
try {
|
|
2833
|
-
const
|
|
2846
|
+
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
2847
|
+
const response = await (path.includes("/auth") ? authApi : api).patch(path.replace("/auth", ""), payload, {
|
|
2848
|
+
headers: requestOptions.headers,
|
|
2849
|
+
params: withTokenQueryParams(requestOptions)
|
|
2850
|
+
});
|
|
2834
2851
|
return response.data;
|
|
2835
2852
|
} catch (e) {
|
|
2836
2853
|
throw formatAxiosError(e);
|
|
2837
2854
|
}
|
|
2838
2855
|
},
|
|
2839
|
-
putJson: async (path, payload,
|
|
2856
|
+
putJson: async (path, payload, headersOrOptions) => {
|
|
2840
2857
|
try {
|
|
2841
|
-
const
|
|
2858
|
+
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
2859
|
+
const response = await (path.includes("/auth") ? authApi : api).put(path.replace("/auth", ""), payload, {
|
|
2860
|
+
headers: requestOptions.headers,
|
|
2861
|
+
params: withTokenQueryParams(requestOptions)
|
|
2862
|
+
});
|
|
2842
2863
|
return response.data;
|
|
2843
2864
|
} catch (e) {
|
|
2844
2865
|
throw formatAxiosError(e);
|
|
2845
2866
|
}
|
|
2846
2867
|
},
|
|
2847
|
-
deleteJson: async (path,
|
|
2868
|
+
deleteJson: async (path, headersOrOptions) => {
|
|
2848
2869
|
try {
|
|
2849
|
-
const
|
|
2870
|
+
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
2871
|
+
const response = await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
|
|
2872
|
+
headers: requestOptions.headers,
|
|
2873
|
+
params: withTokenQueryParams(requestOptions)
|
|
2874
|
+
});
|
|
2850
2875
|
return response.data;
|
|
2851
2876
|
} catch (e) {
|
|
2852
2877
|
throw formatAxiosError(e);
|
|
2853
2878
|
}
|
|
2854
2879
|
},
|
|
2855
|
-
deleteVoid: async (path,
|
|
2880
|
+
deleteVoid: async (path, headersOrOptions) => {
|
|
2856
2881
|
try {
|
|
2857
|
-
|
|
2882
|
+
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
2883
|
+
await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
|
|
2884
|
+
headers: requestOptions.headers,
|
|
2885
|
+
params: withTokenQueryParams(requestOptions)
|
|
2886
|
+
});
|
|
2858
2887
|
} catch (e) {
|
|
2859
2888
|
throw formatAxiosError(e);
|
|
2860
2889
|
}
|
|
2861
2890
|
}
|
|
2862
2891
|
};
|
|
2892
|
+
function extractBearerToken(headers, explicitToken) {
|
|
2893
|
+
if (explicitToken)
|
|
2894
|
+
return explicitToken;
|
|
2895
|
+
if (!headers)
|
|
2896
|
+
return null;
|
|
2897
|
+
const authHeader = headers.Authorization || headers.authorization;
|
|
2898
|
+
if (!authHeader)
|
|
2899
|
+
return null;
|
|
2900
|
+
const match = authHeader.match(/^Bearer\s+(.+)$/i);
|
|
2901
|
+
return match ? match[1] : null;
|
|
2902
|
+
}
|
|
2903
|
+
function resolveAuthToken(options = {}) {
|
|
2904
|
+
const explicitToken = options.token ?? options.bearerToken ?? null;
|
|
2905
|
+
const headerToken = extractBearerToken(options.headers, explicitToken);
|
|
2906
|
+
if (headerToken)
|
|
2907
|
+
return headerToken;
|
|
2908
|
+
if (options.includeStoredToken === false)
|
|
2909
|
+
return null;
|
|
2910
|
+
return getAccessToken();
|
|
2911
|
+
}
|
|
2912
|
+
function mergeQueryParams(params, key, value) {
|
|
2913
|
+
const nextParams = { ...params ?? {} };
|
|
2914
|
+
if (key && value)
|
|
2915
|
+
nextParams[key] = value;
|
|
2916
|
+
return Object.keys(nextParams).length > 0 ? nextParams : void 0;
|
|
2917
|
+
}
|
|
2918
|
+
function normalizeRequestOptions(params, headersOrOptions) {
|
|
2919
|
+
const maybeOptions = headersOrOptions;
|
|
2920
|
+
const hasOptionShape = Boolean(
|
|
2921
|
+
maybeOptions && ("headers" in maybeOptions || "params" in maybeOptions || "sendTokenInQuery" in maybeOptions || "token" in maybeOptions || "tokenQueryParam" in maybeOptions || "includeStoredToken" in maybeOptions)
|
|
2922
|
+
);
|
|
2923
|
+
if (hasOptionShape) {
|
|
2924
|
+
return {
|
|
2925
|
+
...maybeOptions,
|
|
2926
|
+
params: { ...params ?? {}, ...maybeOptions?.params ?? {} }
|
|
2927
|
+
};
|
|
2928
|
+
}
|
|
2929
|
+
return {
|
|
2930
|
+
params,
|
|
2931
|
+
headers: headersOrOptions
|
|
2932
|
+
};
|
|
2933
|
+
}
|
|
2934
|
+
function withTokenQueryParams(options) {
|
|
2935
|
+
if (!options.sendTokenInQuery)
|
|
2936
|
+
return options.params;
|
|
2937
|
+
const token = resolveAuthToken(options);
|
|
2938
|
+
return mergeQueryParams(
|
|
2939
|
+
options.params,
|
|
2940
|
+
options.tokenQueryParam ?? "access_token",
|
|
2941
|
+
token
|
|
2942
|
+
);
|
|
2943
|
+
}
|
|
2863
2944
|
|
|
2864
2945
|
// src/services/registry.ts
|
|
2865
2946
|
var PluginRegistryImpl = class {
|
package/dist/hooks.js
CHANGED
|
@@ -2770,19 +2770,24 @@ function formatAxiosError(err) {
|
|
|
2770
2770
|
return err instanceof Error ? err : new Error(String(err));
|
|
2771
2771
|
}
|
|
2772
2772
|
var fetchApi = {
|
|
2773
|
-
getJson: async (path, params,
|
|
2773
|
+
getJson: async (path, params, headersOrOptions) => {
|
|
2774
2774
|
try {
|
|
2775
|
-
const
|
|
2775
|
+
const requestOptions = normalizeRequestOptions(params, headersOrOptions);
|
|
2776
|
+
const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
2777
|
+
params: withTokenQueryParams(requestOptions),
|
|
2778
|
+
headers: requestOptions.headers
|
|
2779
|
+
});
|
|
2776
2780
|
return response.data;
|
|
2777
2781
|
} catch (e) {
|
|
2778
2782
|
throw formatAxiosError(e);
|
|
2779
2783
|
}
|
|
2780
2784
|
},
|
|
2781
|
-
getText: async (path, params,
|
|
2785
|
+
getText: async (path, params, headersOrOptions) => {
|
|
2782
2786
|
try {
|
|
2787
|
+
const requestOptions = normalizeRequestOptions(params, headersOrOptions);
|
|
2783
2788
|
const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
2784
|
-
params,
|
|
2785
|
-
headers,
|
|
2789
|
+
params: withTokenQueryParams(requestOptions),
|
|
2790
|
+
headers: requestOptions.headers,
|
|
2786
2791
|
responseType: "text"
|
|
2787
2792
|
});
|
|
2788
2793
|
return response.data;
|
|
@@ -2790,53 +2795,129 @@ var fetchApi = {
|
|
|
2790
2795
|
throw formatAxiosError(e);
|
|
2791
2796
|
}
|
|
2792
2797
|
},
|
|
2793
|
-
getVoid: async (path, params,
|
|
2798
|
+
getVoid: async (path, params, headersOrOptions) => {
|
|
2794
2799
|
try {
|
|
2795
|
-
|
|
2800
|
+
const requestOptions = normalizeRequestOptions(params, headersOrOptions);
|
|
2801
|
+
await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
2802
|
+
params: withTokenQueryParams(requestOptions),
|
|
2803
|
+
headers: requestOptions.headers
|
|
2804
|
+
});
|
|
2796
2805
|
} catch (e) {
|
|
2797
2806
|
throw formatAxiosError(e);
|
|
2798
2807
|
}
|
|
2799
2808
|
},
|
|
2800
|
-
postJson: async (path, payload,
|
|
2809
|
+
postJson: async (path, payload, headersOrOptions) => {
|
|
2801
2810
|
try {
|
|
2802
|
-
const
|
|
2811
|
+
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
2812
|
+
const response = await (path.includes("/auth") ? authApi : api).post(path.replace("/auth", ""), payload, {
|
|
2813
|
+
headers: requestOptions.headers,
|
|
2814
|
+
params: withTokenQueryParams(requestOptions)
|
|
2815
|
+
});
|
|
2803
2816
|
return response.data;
|
|
2804
2817
|
} catch (e) {
|
|
2805
2818
|
throw formatAxiosError(e);
|
|
2806
2819
|
}
|
|
2807
2820
|
},
|
|
2808
|
-
patchJson: async (path, payload,
|
|
2821
|
+
patchJson: async (path, payload, headersOrOptions) => {
|
|
2809
2822
|
try {
|
|
2810
|
-
const
|
|
2823
|
+
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
2824
|
+
const response = await (path.includes("/auth") ? authApi : api).patch(path.replace("/auth", ""), payload, {
|
|
2825
|
+
headers: requestOptions.headers,
|
|
2826
|
+
params: withTokenQueryParams(requestOptions)
|
|
2827
|
+
});
|
|
2811
2828
|
return response.data;
|
|
2812
2829
|
} catch (e) {
|
|
2813
2830
|
throw formatAxiosError(e);
|
|
2814
2831
|
}
|
|
2815
2832
|
},
|
|
2816
|
-
putJson: async (path, payload,
|
|
2833
|
+
putJson: async (path, payload, headersOrOptions) => {
|
|
2817
2834
|
try {
|
|
2818
|
-
const
|
|
2835
|
+
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
2836
|
+
const response = await (path.includes("/auth") ? authApi : api).put(path.replace("/auth", ""), payload, {
|
|
2837
|
+
headers: requestOptions.headers,
|
|
2838
|
+
params: withTokenQueryParams(requestOptions)
|
|
2839
|
+
});
|
|
2819
2840
|
return response.data;
|
|
2820
2841
|
} catch (e) {
|
|
2821
2842
|
throw formatAxiosError(e);
|
|
2822
2843
|
}
|
|
2823
2844
|
},
|
|
2824
|
-
deleteJson: async (path,
|
|
2845
|
+
deleteJson: async (path, headersOrOptions) => {
|
|
2825
2846
|
try {
|
|
2826
|
-
const
|
|
2847
|
+
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
2848
|
+
const response = await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
|
|
2849
|
+
headers: requestOptions.headers,
|
|
2850
|
+
params: withTokenQueryParams(requestOptions)
|
|
2851
|
+
});
|
|
2827
2852
|
return response.data;
|
|
2828
2853
|
} catch (e) {
|
|
2829
2854
|
throw formatAxiosError(e);
|
|
2830
2855
|
}
|
|
2831
2856
|
},
|
|
2832
|
-
deleteVoid: async (path,
|
|
2857
|
+
deleteVoid: async (path, headersOrOptions) => {
|
|
2833
2858
|
try {
|
|
2834
|
-
|
|
2859
|
+
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
2860
|
+
await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
|
|
2861
|
+
headers: requestOptions.headers,
|
|
2862
|
+
params: withTokenQueryParams(requestOptions)
|
|
2863
|
+
});
|
|
2835
2864
|
} catch (e) {
|
|
2836
2865
|
throw formatAxiosError(e);
|
|
2837
2866
|
}
|
|
2838
2867
|
}
|
|
2839
2868
|
};
|
|
2869
|
+
function extractBearerToken(headers, explicitToken) {
|
|
2870
|
+
if (explicitToken)
|
|
2871
|
+
return explicitToken;
|
|
2872
|
+
if (!headers)
|
|
2873
|
+
return null;
|
|
2874
|
+
const authHeader = headers.Authorization || headers.authorization;
|
|
2875
|
+
if (!authHeader)
|
|
2876
|
+
return null;
|
|
2877
|
+
const match = authHeader.match(/^Bearer\s+(.+)$/i);
|
|
2878
|
+
return match ? match[1] : null;
|
|
2879
|
+
}
|
|
2880
|
+
function resolveAuthToken(options = {}) {
|
|
2881
|
+
const explicitToken = options.token ?? options.bearerToken ?? null;
|
|
2882
|
+
const headerToken = extractBearerToken(options.headers, explicitToken);
|
|
2883
|
+
if (headerToken)
|
|
2884
|
+
return headerToken;
|
|
2885
|
+
if (options.includeStoredToken === false)
|
|
2886
|
+
return null;
|
|
2887
|
+
return getAccessToken();
|
|
2888
|
+
}
|
|
2889
|
+
function mergeQueryParams(params, key, value) {
|
|
2890
|
+
const nextParams = { ...params ?? {} };
|
|
2891
|
+
if (key && value)
|
|
2892
|
+
nextParams[key] = value;
|
|
2893
|
+
return Object.keys(nextParams).length > 0 ? nextParams : void 0;
|
|
2894
|
+
}
|
|
2895
|
+
function normalizeRequestOptions(params, headersOrOptions) {
|
|
2896
|
+
const maybeOptions = headersOrOptions;
|
|
2897
|
+
const hasOptionShape = Boolean(
|
|
2898
|
+
maybeOptions && ("headers" in maybeOptions || "params" in maybeOptions || "sendTokenInQuery" in maybeOptions || "token" in maybeOptions || "tokenQueryParam" in maybeOptions || "includeStoredToken" in maybeOptions)
|
|
2899
|
+
);
|
|
2900
|
+
if (hasOptionShape) {
|
|
2901
|
+
return {
|
|
2902
|
+
...maybeOptions,
|
|
2903
|
+
params: { ...params ?? {}, ...maybeOptions?.params ?? {} }
|
|
2904
|
+
};
|
|
2905
|
+
}
|
|
2906
|
+
return {
|
|
2907
|
+
params,
|
|
2908
|
+
headers: headersOrOptions
|
|
2909
|
+
};
|
|
2910
|
+
}
|
|
2911
|
+
function withTokenQueryParams(options) {
|
|
2912
|
+
if (!options.sendTokenInQuery)
|
|
2913
|
+
return options.params;
|
|
2914
|
+
const token = resolveAuthToken(options);
|
|
2915
|
+
return mergeQueryParams(
|
|
2916
|
+
options.params,
|
|
2917
|
+
options.tokenQueryParam ?? "access_token",
|
|
2918
|
+
token
|
|
2919
|
+
);
|
|
2920
|
+
}
|
|
2840
2921
|
|
|
2841
2922
|
// src/services/registry.ts
|
|
2842
2923
|
var PluginRegistryImpl = class {
|
package/dist/index.cjs
CHANGED
|
@@ -197,7 +197,8 @@ __export(src_exports, {
|
|
|
197
197
|
useAuth: () => useAuth,
|
|
198
198
|
useAvailableSubservices: () => useAvailableSubservices,
|
|
199
199
|
useSettings: () => useSettings,
|
|
200
|
-
userService: () => userService
|
|
200
|
+
userService: () => userService,
|
|
201
|
+
withAccessTokenQuery: () => withAccessTokenQuery
|
|
201
202
|
});
|
|
202
203
|
module.exports = __toCommonJS(src_exports);
|
|
203
204
|
|
|
@@ -2959,19 +2960,24 @@ function formatAxiosError(err) {
|
|
|
2959
2960
|
return err instanceof Error ? err : new Error(String(err));
|
|
2960
2961
|
}
|
|
2961
2962
|
var fetchApi = {
|
|
2962
|
-
getJson: async (path, params,
|
|
2963
|
+
getJson: async (path, params, headersOrOptions) => {
|
|
2963
2964
|
try {
|
|
2964
|
-
const
|
|
2965
|
+
const requestOptions = normalizeRequestOptions(params, headersOrOptions);
|
|
2966
|
+
const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
2967
|
+
params: withTokenQueryParams(requestOptions),
|
|
2968
|
+
headers: requestOptions.headers
|
|
2969
|
+
});
|
|
2965
2970
|
return response.data;
|
|
2966
2971
|
} catch (e10) {
|
|
2967
2972
|
throw formatAxiosError(e10);
|
|
2968
2973
|
}
|
|
2969
2974
|
},
|
|
2970
|
-
getText: async (path, params,
|
|
2975
|
+
getText: async (path, params, headersOrOptions) => {
|
|
2971
2976
|
try {
|
|
2977
|
+
const requestOptions = normalizeRequestOptions(params, headersOrOptions);
|
|
2972
2978
|
const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
2973
|
-
params,
|
|
2974
|
-
headers,
|
|
2979
|
+
params: withTokenQueryParams(requestOptions),
|
|
2980
|
+
headers: requestOptions.headers,
|
|
2975
2981
|
responseType: "text"
|
|
2976
2982
|
});
|
|
2977
2983
|
return response.data;
|
|
@@ -2979,78 +2985,152 @@ var fetchApi = {
|
|
|
2979
2985
|
throw formatAxiosError(e10);
|
|
2980
2986
|
}
|
|
2981
2987
|
},
|
|
2982
|
-
getVoid: async (path, params,
|
|
2988
|
+
getVoid: async (path, params, headersOrOptions) => {
|
|
2983
2989
|
try {
|
|
2984
|
-
|
|
2990
|
+
const requestOptions = normalizeRequestOptions(params, headersOrOptions);
|
|
2991
|
+
await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
2992
|
+
params: withTokenQueryParams(requestOptions),
|
|
2993
|
+
headers: requestOptions.headers
|
|
2994
|
+
});
|
|
2985
2995
|
} catch (e10) {
|
|
2986
2996
|
throw formatAxiosError(e10);
|
|
2987
2997
|
}
|
|
2988
2998
|
},
|
|
2989
|
-
postJson: async (path, payload,
|
|
2999
|
+
postJson: async (path, payload, headersOrOptions) => {
|
|
2990
3000
|
try {
|
|
2991
|
-
const
|
|
3001
|
+
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
3002
|
+
const response = await (path.includes("/auth") ? authApi : api).post(path.replace("/auth", ""), payload, {
|
|
3003
|
+
headers: requestOptions.headers,
|
|
3004
|
+
params: withTokenQueryParams(requestOptions)
|
|
3005
|
+
});
|
|
2992
3006
|
return response.data;
|
|
2993
3007
|
} catch (e10) {
|
|
2994
3008
|
throw formatAxiosError(e10);
|
|
2995
3009
|
}
|
|
2996
3010
|
},
|
|
2997
|
-
patchJson: async (path, payload,
|
|
3011
|
+
patchJson: async (path, payload, headersOrOptions) => {
|
|
2998
3012
|
try {
|
|
2999
|
-
const
|
|
3013
|
+
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
3014
|
+
const response = await (path.includes("/auth") ? authApi : api).patch(path.replace("/auth", ""), payload, {
|
|
3015
|
+
headers: requestOptions.headers,
|
|
3016
|
+
params: withTokenQueryParams(requestOptions)
|
|
3017
|
+
});
|
|
3000
3018
|
return response.data;
|
|
3001
3019
|
} catch (e10) {
|
|
3002
3020
|
throw formatAxiosError(e10);
|
|
3003
3021
|
}
|
|
3004
3022
|
},
|
|
3005
|
-
putJson: async (path, payload,
|
|
3023
|
+
putJson: async (path, payload, headersOrOptions) => {
|
|
3006
3024
|
try {
|
|
3007
|
-
const
|
|
3025
|
+
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
3026
|
+
const response = await (path.includes("/auth") ? authApi : api).put(path.replace("/auth", ""), payload, {
|
|
3027
|
+
headers: requestOptions.headers,
|
|
3028
|
+
params: withTokenQueryParams(requestOptions)
|
|
3029
|
+
});
|
|
3008
3030
|
return response.data;
|
|
3009
3031
|
} catch (e10) {
|
|
3010
3032
|
throw formatAxiosError(e10);
|
|
3011
3033
|
}
|
|
3012
3034
|
},
|
|
3013
|
-
deleteJson: async (path,
|
|
3035
|
+
deleteJson: async (path, headersOrOptions) => {
|
|
3014
3036
|
try {
|
|
3015
|
-
const
|
|
3037
|
+
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
3038
|
+
const response = await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
|
|
3039
|
+
headers: requestOptions.headers,
|
|
3040
|
+
params: withTokenQueryParams(requestOptions)
|
|
3041
|
+
});
|
|
3016
3042
|
return response.data;
|
|
3017
3043
|
} catch (e10) {
|
|
3018
3044
|
throw formatAxiosError(e10);
|
|
3019
3045
|
}
|
|
3020
3046
|
},
|
|
3021
|
-
deleteVoid: async (path,
|
|
3047
|
+
deleteVoid: async (path, headersOrOptions) => {
|
|
3022
3048
|
try {
|
|
3023
|
-
|
|
3049
|
+
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
3050
|
+
await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
|
|
3051
|
+
headers: requestOptions.headers,
|
|
3052
|
+
params: withTokenQueryParams(requestOptions)
|
|
3053
|
+
});
|
|
3024
3054
|
} catch (e10) {
|
|
3025
3055
|
throw formatAxiosError(e10);
|
|
3026
3056
|
}
|
|
3027
3057
|
}
|
|
3028
3058
|
};
|
|
3029
|
-
function buildWsUrl(path = "/") {
|
|
3059
|
+
function buildWsUrl(path = "/", options = {}) {
|
|
3030
3060
|
try {
|
|
3031
3061
|
const origin2 = new URL(apiOrigin);
|
|
3032
3062
|
origin2.protocol = origin2.protocol === "https:" ? "wss:" : "ws:";
|
|
3033
3063
|
if (!path.startsWith("/"))
|
|
3034
3064
|
path = "/" + path;
|
|
3035
3065
|
origin2.pathname = path;
|
|
3036
|
-
return origin2.toString()
|
|
3066
|
+
return withAccessTokenQuery(origin2.toString(), {
|
|
3067
|
+
headers: options.headers,
|
|
3068
|
+
params: options.query,
|
|
3069
|
+
token: options.token ?? options.bearerToken,
|
|
3070
|
+
tokenQueryParam: options.tokenQueryParam ?? options.bearerQueryParam,
|
|
3071
|
+
includeStoredToken: options.includeStoredToken
|
|
3072
|
+
});
|
|
3037
3073
|
} catch (e10) {
|
|
3038
3074
|
const proto = apiOrigin.startsWith("https") ? "wss" : "ws";
|
|
3039
3075
|
const host = apiOrigin.replace(/^https?:\/\//, "").replace(/\/$/, "");
|
|
3040
|
-
return
|
|
3076
|
+
return withAccessTokenQuery(
|
|
3077
|
+
`${proto}://${host}${path.startsWith("/") ? path : "/" + path}`,
|
|
3078
|
+
{
|
|
3079
|
+
headers: options.headers,
|
|
3080
|
+
params: options.query,
|
|
3081
|
+
token: options.token ?? options.bearerToken,
|
|
3082
|
+
tokenQueryParam: options.tokenQueryParam ?? options.bearerQueryParam,
|
|
3083
|
+
includeStoredToken: options.includeStoredToken
|
|
3084
|
+
}
|
|
3085
|
+
);
|
|
3041
3086
|
}
|
|
3042
3087
|
}
|
|
3043
|
-
function
|
|
3088
|
+
function extractBearerToken(headers, explicitToken) {
|
|
3089
|
+
if (explicitToken)
|
|
3090
|
+
return explicitToken;
|
|
3091
|
+
if (!headers)
|
|
3092
|
+
return null;
|
|
3093
|
+
const authHeader = headers.Authorization || headers.authorization;
|
|
3094
|
+
if (!authHeader)
|
|
3095
|
+
return null;
|
|
3096
|
+
const match = authHeader.match(/^Bearer\s+(.+)$/i);
|
|
3097
|
+
return match ? match[1] : null;
|
|
3098
|
+
}
|
|
3099
|
+
function resolveAuthToken(options = {}) {
|
|
3100
|
+
const explicitToken = options.token ?? options.bearerToken ?? null;
|
|
3101
|
+
const headerToken = extractBearerToken(options.headers, explicitToken);
|
|
3102
|
+
if (headerToken)
|
|
3103
|
+
return headerToken;
|
|
3104
|
+
if (options.includeStoredToken === false)
|
|
3105
|
+
return null;
|
|
3106
|
+
return getAccessToken();
|
|
3107
|
+
}
|
|
3108
|
+
function mergeQueryParams(params, key, value) {
|
|
3109
|
+
const nextParams = { ...params ?? {} };
|
|
3110
|
+
if (key && value)
|
|
3111
|
+
nextParams[key] = value;
|
|
3112
|
+
return Object.keys(nextParams).length > 0 ? nextParams : void 0;
|
|
3113
|
+
}
|
|
3114
|
+
function appendQueryParams(url, params) {
|
|
3115
|
+
if (!params || Object.keys(params).length === 0)
|
|
3116
|
+
return url;
|
|
3044
3117
|
try {
|
|
3045
3118
|
const parsed = new URL(
|
|
3046
3119
|
url,
|
|
3047
3120
|
typeof window !== "undefined" ? window.location.href : void 0
|
|
3048
3121
|
);
|
|
3049
|
-
|
|
3122
|
+
for (const [key, value] of Object.entries(params)) {
|
|
3123
|
+
if (value === void 0 || value === null)
|
|
3124
|
+
continue;
|
|
3125
|
+
parsed.searchParams.set(key, String(value));
|
|
3126
|
+
}
|
|
3050
3127
|
return parsed.toString();
|
|
3051
3128
|
} catch {
|
|
3129
|
+
const search = Object.entries(params).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`).join("&");
|
|
3130
|
+
if (!search)
|
|
3131
|
+
return url;
|
|
3052
3132
|
const separator = url.includes("?") ? "&" : "?";
|
|
3053
|
-
return `${url}${separator}${
|
|
3133
|
+
return `${url}${separator}${search}`;
|
|
3054
3134
|
}
|
|
3055
3135
|
}
|
|
3056
3136
|
function normalizeProtocols(protocols) {
|
|
@@ -3058,6 +3138,39 @@ function normalizeProtocols(protocols) {
|
|
|
3058
3138
|
return void 0;
|
|
3059
3139
|
return Array.isArray(protocols) ? protocols.filter(Boolean) : [protocols];
|
|
3060
3140
|
}
|
|
3141
|
+
function normalizeRequestOptions(params, headersOrOptions) {
|
|
3142
|
+
const maybeOptions = headersOrOptions;
|
|
3143
|
+
const hasOptionShape = Boolean(
|
|
3144
|
+
maybeOptions && ("headers" in maybeOptions || "params" in maybeOptions || "sendTokenInQuery" in maybeOptions || "token" in maybeOptions || "tokenQueryParam" in maybeOptions || "includeStoredToken" in maybeOptions)
|
|
3145
|
+
);
|
|
3146
|
+
if (hasOptionShape) {
|
|
3147
|
+
return {
|
|
3148
|
+
...maybeOptions,
|
|
3149
|
+
params: { ...params ?? {}, ...maybeOptions?.params ?? {} }
|
|
3150
|
+
};
|
|
3151
|
+
}
|
|
3152
|
+
return {
|
|
3153
|
+
params,
|
|
3154
|
+
headers: headersOrOptions
|
|
3155
|
+
};
|
|
3156
|
+
}
|
|
3157
|
+
function withTokenQueryParams(options) {
|
|
3158
|
+
if (!options.sendTokenInQuery)
|
|
3159
|
+
return options.params;
|
|
3160
|
+
const token = resolveAuthToken(options);
|
|
3161
|
+
return mergeQueryParams(
|
|
3162
|
+
options.params,
|
|
3163
|
+
options.tokenQueryParam ?? "access_token",
|
|
3164
|
+
token
|
|
3165
|
+
);
|
|
3166
|
+
}
|
|
3167
|
+
function withAccessTokenQuery(url, options = {}) {
|
|
3168
|
+
const token = resolveAuthToken(options);
|
|
3169
|
+
return appendQueryParams(
|
|
3170
|
+
url,
|
|
3171
|
+
mergeQueryParams(options.params, options.tokenQueryParam ?? "access_token", token)
|
|
3172
|
+
);
|
|
3173
|
+
}
|
|
3061
3174
|
async function encodeFfurl(settings) {
|
|
3062
3175
|
const { ffurl } = await fetchApi.postJson("/auth/protocols/ffurl/encode", settings);
|
|
3063
3176
|
return ffurl;
|
|
@@ -3066,27 +3179,30 @@ async function decodeFfurl(ffurl) {
|
|
|
3066
3179
|
const { settings } = await fetchApi.postJson("/auth/protocols/ffurl/decode", { ffurl });
|
|
3067
3180
|
return settings;
|
|
3068
3181
|
}
|
|
3069
|
-
function resolveWsBearerToken(options) {
|
|
3070
|
-
if (options.bearerToken)
|
|
3071
|
-
return options.bearerToken;
|
|
3072
|
-
if (options.autoAuth)
|
|
3073
|
-
return getAccessToken();
|
|
3074
|
-
return null;
|
|
3075
|
-
}
|
|
3076
3182
|
function subscribeToWebsocket(url, onMessage, options = {}) {
|
|
3077
|
-
const
|
|
3078
|
-
|
|
3183
|
+
const bearerToken = resolveAuthToken({
|
|
3184
|
+
headers: options.headers,
|
|
3185
|
+
token: options.token,
|
|
3186
|
+
bearerToken: options.bearerToken,
|
|
3187
|
+
includeStoredToken: options.includeStoredToken
|
|
3188
|
+
});
|
|
3189
|
+
const bearerStrategy = options.tokenTransport ?? options.bearerStrategy ?? "query";
|
|
3190
|
+
let resolvedUrl = appendQueryParams(url, options.query);
|
|
3079
3191
|
const protocols = normalizeProtocols(options.protocols) ?? [];
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3192
|
+
if (options.headers && Object.keys(options.headers).length > 0) {
|
|
3193
|
+
console.warn(
|
|
3194
|
+
"WebSocket connections in browsers do not support custom HTTP headers. shared-ui will derive bearer auth from Authorization and forward it using query string or subprotocol."
|
|
3195
|
+
);
|
|
3196
|
+
}
|
|
3197
|
+
if (bearerToken) {
|
|
3198
|
+
if (bearerStrategy === "protocol") {
|
|
3199
|
+
protocols.push("bearer", bearerToken);
|
|
3084
3200
|
} else {
|
|
3085
|
-
resolvedUrl =
|
|
3086
|
-
|
|
3087
|
-
options.
|
|
3088
|
-
|
|
3089
|
-
);
|
|
3201
|
+
resolvedUrl = withAccessTokenQuery(resolvedUrl, {
|
|
3202
|
+
token: bearerToken,
|
|
3203
|
+
tokenQueryParam: options.tokenQueryParam ?? options.bearerQueryParam,
|
|
3204
|
+
includeStoredToken: false
|
|
3205
|
+
});
|
|
3090
3206
|
}
|
|
3091
3207
|
}
|
|
3092
3208
|
const socket = protocols.length > 0 ? new WebSocket(resolvedUrl, protocols) : new WebSocket(resolvedUrl);
|
|
@@ -3095,7 +3211,7 @@ function subscribeToWebsocket(url, onMessage, options = {}) {
|
|
|
3095
3211
|
const data = JSON.parse(event.data);
|
|
3096
3212
|
onMessage(data);
|
|
3097
3213
|
} catch (e10) {
|
|
3098
|
-
console.error("
|
|
3214
|
+
console.error("Parse error", e10);
|
|
3099
3215
|
}
|
|
3100
3216
|
};
|
|
3101
3217
|
socket.onerror = (err) => console.error("WebSocket error", err);
|