@viasoftbr/shared-ui 0.0.7-4 → 0.0.7-6
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 +45 -121
- package/dist/components.js +45 -121
- package/dist/hooks.cjs +18 -88
- package/dist/hooks.js +18 -88
- package/dist/index.cjs +46 -123
- package/dist/index.js +46 -123
- package/dist/services/api.d.ts +9 -18
- package/dist/services.cjs +46 -123
- package/dist/services.js +46 -123
- package/dist/types/websocket.d.ts +5 -8
- package/package.json +1 -1
package/dist/hooks.cjs
CHANGED
|
@@ -2793,24 +2793,22 @@ 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, headers) => {
|
|
2797
2797
|
try {
|
|
2798
|
-
const requestOptions = normalizeRequestOptions(params, headersOrOptions);
|
|
2799
2798
|
const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
2800
|
-
params
|
|
2801
|
-
headers
|
|
2799
|
+
params,
|
|
2800
|
+
headers
|
|
2802
2801
|
});
|
|
2803
2802
|
return response.data;
|
|
2804
2803
|
} catch (e) {
|
|
2805
2804
|
throw formatAxiosError(e);
|
|
2806
2805
|
}
|
|
2807
2806
|
},
|
|
2808
|
-
getText: async (path, params,
|
|
2807
|
+
getText: async (path, params, headers) => {
|
|
2809
2808
|
try {
|
|
2810
|
-
const requestOptions = normalizeRequestOptions(params, headersOrOptions);
|
|
2811
2809
|
const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
2812
|
-
params
|
|
2813
|
-
headers
|
|
2810
|
+
params,
|
|
2811
|
+
headers,
|
|
2814
2812
|
responseType: "text"
|
|
2815
2813
|
});
|
|
2816
2814
|
return response.data;
|
|
@@ -2818,129 +2816,61 @@ var fetchApi = {
|
|
|
2818
2816
|
throw formatAxiosError(e);
|
|
2819
2817
|
}
|
|
2820
2818
|
},
|
|
2821
|
-
getVoid: async (path, params,
|
|
2819
|
+
getVoid: async (path, params, headers) => {
|
|
2822
2820
|
try {
|
|
2823
|
-
|
|
2824
|
-
await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
2825
|
-
params: withTokenQueryParams(requestOptions),
|
|
2826
|
-
headers: requestOptions.headers
|
|
2827
|
-
});
|
|
2821
|
+
await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), { params, headers });
|
|
2828
2822
|
} catch (e) {
|
|
2829
2823
|
throw formatAxiosError(e);
|
|
2830
2824
|
}
|
|
2831
2825
|
},
|
|
2832
|
-
postJson: async (path, payload,
|
|
2826
|
+
postJson: async (path, payload, headers) => {
|
|
2833
2827
|
try {
|
|
2834
|
-
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
2835
2828
|
const response = await (path.includes("/auth") ? authApi : api).post(path.replace("/auth", ""), payload, {
|
|
2836
|
-
headers
|
|
2837
|
-
params: withTokenQueryParams(requestOptions)
|
|
2829
|
+
headers
|
|
2838
2830
|
});
|
|
2839
2831
|
return response.data;
|
|
2840
2832
|
} catch (e) {
|
|
2841
2833
|
throw formatAxiosError(e);
|
|
2842
2834
|
}
|
|
2843
2835
|
},
|
|
2844
|
-
patchJson: async (path, payload,
|
|
2836
|
+
patchJson: async (path, payload, headers) => {
|
|
2845
2837
|
try {
|
|
2846
|
-
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
2847
2838
|
const response = await (path.includes("/auth") ? authApi : api).patch(path.replace("/auth", ""), payload, {
|
|
2848
|
-
headers
|
|
2849
|
-
params: withTokenQueryParams(requestOptions)
|
|
2839
|
+
headers
|
|
2850
2840
|
});
|
|
2851
2841
|
return response.data;
|
|
2852
2842
|
} catch (e) {
|
|
2853
2843
|
throw formatAxiosError(e);
|
|
2854
2844
|
}
|
|
2855
2845
|
},
|
|
2856
|
-
putJson: async (path, payload,
|
|
2846
|
+
putJson: async (path, payload, headers) => {
|
|
2857
2847
|
try {
|
|
2858
|
-
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
2859
2848
|
const response = await (path.includes("/auth") ? authApi : api).put(path.replace("/auth", ""), payload, {
|
|
2860
|
-
headers
|
|
2861
|
-
params: withTokenQueryParams(requestOptions)
|
|
2849
|
+
headers
|
|
2862
2850
|
});
|
|
2863
2851
|
return response.data;
|
|
2864
2852
|
} catch (e) {
|
|
2865
2853
|
throw formatAxiosError(e);
|
|
2866
2854
|
}
|
|
2867
2855
|
},
|
|
2868
|
-
deleteJson: async (path,
|
|
2856
|
+
deleteJson: async (path, headers) => {
|
|
2869
2857
|
try {
|
|
2870
|
-
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
2871
2858
|
const response = await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
|
|
2872
|
-
headers
|
|
2873
|
-
params: withTokenQueryParams(requestOptions)
|
|
2859
|
+
headers
|
|
2874
2860
|
});
|
|
2875
2861
|
return response.data;
|
|
2876
2862
|
} catch (e) {
|
|
2877
2863
|
throw formatAxiosError(e);
|
|
2878
2864
|
}
|
|
2879
2865
|
},
|
|
2880
|
-
deleteVoid: async (path,
|
|
2866
|
+
deleteVoid: async (path, headers) => {
|
|
2881
2867
|
try {
|
|
2882
|
-
|
|
2883
|
-
await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
|
|
2884
|
-
headers: requestOptions.headers,
|
|
2885
|
-
params: withTokenQueryParams(requestOptions)
|
|
2886
|
-
});
|
|
2868
|
+
await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), { headers });
|
|
2887
2869
|
} catch (e) {
|
|
2888
2870
|
throw formatAxiosError(e);
|
|
2889
2871
|
}
|
|
2890
2872
|
}
|
|
2891
2873
|
};
|
|
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
|
-
}
|
|
2944
2874
|
|
|
2945
2875
|
// src/services/registry.ts
|
|
2946
2876
|
var PluginRegistryImpl = class {
|
package/dist/hooks.js
CHANGED
|
@@ -2770,24 +2770,22 @@ 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, headers) => {
|
|
2774
2774
|
try {
|
|
2775
|
-
const requestOptions = normalizeRequestOptions(params, headersOrOptions);
|
|
2776
2775
|
const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
2777
|
-
params
|
|
2778
|
-
headers
|
|
2776
|
+
params,
|
|
2777
|
+
headers
|
|
2779
2778
|
});
|
|
2780
2779
|
return response.data;
|
|
2781
2780
|
} catch (e) {
|
|
2782
2781
|
throw formatAxiosError(e);
|
|
2783
2782
|
}
|
|
2784
2783
|
},
|
|
2785
|
-
getText: async (path, params,
|
|
2784
|
+
getText: async (path, params, headers) => {
|
|
2786
2785
|
try {
|
|
2787
|
-
const requestOptions = normalizeRequestOptions(params, headersOrOptions);
|
|
2788
2786
|
const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
2789
|
-
params
|
|
2790
|
-
headers
|
|
2787
|
+
params,
|
|
2788
|
+
headers,
|
|
2791
2789
|
responseType: "text"
|
|
2792
2790
|
});
|
|
2793
2791
|
return response.data;
|
|
@@ -2795,129 +2793,61 @@ var fetchApi = {
|
|
|
2795
2793
|
throw formatAxiosError(e);
|
|
2796
2794
|
}
|
|
2797
2795
|
},
|
|
2798
|
-
getVoid: async (path, params,
|
|
2796
|
+
getVoid: async (path, params, headers) => {
|
|
2799
2797
|
try {
|
|
2800
|
-
|
|
2801
|
-
await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
2802
|
-
params: withTokenQueryParams(requestOptions),
|
|
2803
|
-
headers: requestOptions.headers
|
|
2804
|
-
});
|
|
2798
|
+
await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), { params, headers });
|
|
2805
2799
|
} catch (e) {
|
|
2806
2800
|
throw formatAxiosError(e);
|
|
2807
2801
|
}
|
|
2808
2802
|
},
|
|
2809
|
-
postJson: async (path, payload,
|
|
2803
|
+
postJson: async (path, payload, headers) => {
|
|
2810
2804
|
try {
|
|
2811
|
-
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
2812
2805
|
const response = await (path.includes("/auth") ? authApi : api).post(path.replace("/auth", ""), payload, {
|
|
2813
|
-
headers
|
|
2814
|
-
params: withTokenQueryParams(requestOptions)
|
|
2806
|
+
headers
|
|
2815
2807
|
});
|
|
2816
2808
|
return response.data;
|
|
2817
2809
|
} catch (e) {
|
|
2818
2810
|
throw formatAxiosError(e);
|
|
2819
2811
|
}
|
|
2820
2812
|
},
|
|
2821
|
-
patchJson: async (path, payload,
|
|
2813
|
+
patchJson: async (path, payload, headers) => {
|
|
2822
2814
|
try {
|
|
2823
|
-
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
2824
2815
|
const response = await (path.includes("/auth") ? authApi : api).patch(path.replace("/auth", ""), payload, {
|
|
2825
|
-
headers
|
|
2826
|
-
params: withTokenQueryParams(requestOptions)
|
|
2816
|
+
headers
|
|
2827
2817
|
});
|
|
2828
2818
|
return response.data;
|
|
2829
2819
|
} catch (e) {
|
|
2830
2820
|
throw formatAxiosError(e);
|
|
2831
2821
|
}
|
|
2832
2822
|
},
|
|
2833
|
-
putJson: async (path, payload,
|
|
2823
|
+
putJson: async (path, payload, headers) => {
|
|
2834
2824
|
try {
|
|
2835
|
-
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
2836
2825
|
const response = await (path.includes("/auth") ? authApi : api).put(path.replace("/auth", ""), payload, {
|
|
2837
|
-
headers
|
|
2838
|
-
params: withTokenQueryParams(requestOptions)
|
|
2826
|
+
headers
|
|
2839
2827
|
});
|
|
2840
2828
|
return response.data;
|
|
2841
2829
|
} catch (e) {
|
|
2842
2830
|
throw formatAxiosError(e);
|
|
2843
2831
|
}
|
|
2844
2832
|
},
|
|
2845
|
-
deleteJson: async (path,
|
|
2833
|
+
deleteJson: async (path, headers) => {
|
|
2846
2834
|
try {
|
|
2847
|
-
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
2848
2835
|
const response = await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
|
|
2849
|
-
headers
|
|
2850
|
-
params: withTokenQueryParams(requestOptions)
|
|
2836
|
+
headers
|
|
2851
2837
|
});
|
|
2852
2838
|
return response.data;
|
|
2853
2839
|
} catch (e) {
|
|
2854
2840
|
throw formatAxiosError(e);
|
|
2855
2841
|
}
|
|
2856
2842
|
},
|
|
2857
|
-
deleteVoid: async (path,
|
|
2843
|
+
deleteVoid: async (path, headers) => {
|
|
2858
2844
|
try {
|
|
2859
|
-
|
|
2860
|
-
await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
|
|
2861
|
-
headers: requestOptions.headers,
|
|
2862
|
-
params: withTokenQueryParams(requestOptions)
|
|
2863
|
-
});
|
|
2845
|
+
await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), { headers });
|
|
2864
2846
|
} catch (e) {
|
|
2865
2847
|
throw formatAxiosError(e);
|
|
2866
2848
|
}
|
|
2867
2849
|
}
|
|
2868
2850
|
};
|
|
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
|
-
}
|
|
2921
2851
|
|
|
2922
2852
|
// src/services/registry.ts
|
|
2923
2853
|
var PluginRegistryImpl = class {
|
package/dist/index.cjs
CHANGED
|
@@ -197,8 +197,7 @@ __export(src_exports, {
|
|
|
197
197
|
useAuth: () => useAuth,
|
|
198
198
|
useAvailableSubservices: () => useAvailableSubservices,
|
|
199
199
|
useSettings: () => useSettings,
|
|
200
|
-
userService: () => userService
|
|
201
|
-
withAccessTokenQuery: () => withAccessTokenQuery
|
|
200
|
+
userService: () => userService
|
|
202
201
|
});
|
|
203
202
|
module.exports = __toCommonJS(src_exports);
|
|
204
203
|
|
|
@@ -2960,24 +2959,22 @@ function formatAxiosError(err) {
|
|
|
2960
2959
|
return err instanceof Error ? err : new Error(String(err));
|
|
2961
2960
|
}
|
|
2962
2961
|
var fetchApi = {
|
|
2963
|
-
getJson: async (path, params,
|
|
2962
|
+
getJson: async (path, params, headers) => {
|
|
2964
2963
|
try {
|
|
2965
|
-
const requestOptions = normalizeRequestOptions(params, headersOrOptions);
|
|
2966
2964
|
const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
2967
|
-
params
|
|
2968
|
-
headers
|
|
2965
|
+
params,
|
|
2966
|
+
headers
|
|
2969
2967
|
});
|
|
2970
2968
|
return response.data;
|
|
2971
2969
|
} catch (e10) {
|
|
2972
2970
|
throw formatAxiosError(e10);
|
|
2973
2971
|
}
|
|
2974
2972
|
},
|
|
2975
|
-
getText: async (path, params,
|
|
2973
|
+
getText: async (path, params, headers) => {
|
|
2976
2974
|
try {
|
|
2977
|
-
const requestOptions = normalizeRequestOptions(params, headersOrOptions);
|
|
2978
2975
|
const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
2979
|
-
params
|
|
2980
|
-
headers
|
|
2976
|
+
params,
|
|
2977
|
+
headers,
|
|
2981
2978
|
responseType: "text"
|
|
2982
2979
|
});
|
|
2983
2980
|
return response.data;
|
|
@@ -2985,106 +2982,61 @@ var fetchApi = {
|
|
|
2985
2982
|
throw formatAxiosError(e10);
|
|
2986
2983
|
}
|
|
2987
2984
|
},
|
|
2988
|
-
getVoid: async (path, params,
|
|
2985
|
+
getVoid: async (path, params, headers) => {
|
|
2989
2986
|
try {
|
|
2990
|
-
|
|
2991
|
-
await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
2992
|
-
params: withTokenQueryParams(requestOptions),
|
|
2993
|
-
headers: requestOptions.headers
|
|
2994
|
-
});
|
|
2987
|
+
await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), { params, headers });
|
|
2995
2988
|
} catch (e10) {
|
|
2996
2989
|
throw formatAxiosError(e10);
|
|
2997
2990
|
}
|
|
2998
2991
|
},
|
|
2999
|
-
postJson: async (path, payload,
|
|
2992
|
+
postJson: async (path, payload, headers) => {
|
|
3000
2993
|
try {
|
|
3001
|
-
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
3002
2994
|
const response = await (path.includes("/auth") ? authApi : api).post(path.replace("/auth", ""), payload, {
|
|
3003
|
-
headers
|
|
3004
|
-
params: withTokenQueryParams(requestOptions)
|
|
2995
|
+
headers
|
|
3005
2996
|
});
|
|
3006
2997
|
return response.data;
|
|
3007
2998
|
} catch (e10) {
|
|
3008
2999
|
throw formatAxiosError(e10);
|
|
3009
3000
|
}
|
|
3010
3001
|
},
|
|
3011
|
-
patchJson: async (path, payload,
|
|
3002
|
+
patchJson: async (path, payload, headers) => {
|
|
3012
3003
|
try {
|
|
3013
|
-
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
3014
3004
|
const response = await (path.includes("/auth") ? authApi : api).patch(path.replace("/auth", ""), payload, {
|
|
3015
|
-
headers
|
|
3016
|
-
params: withTokenQueryParams(requestOptions)
|
|
3005
|
+
headers
|
|
3017
3006
|
});
|
|
3018
3007
|
return response.data;
|
|
3019
3008
|
} catch (e10) {
|
|
3020
3009
|
throw formatAxiosError(e10);
|
|
3021
3010
|
}
|
|
3022
3011
|
},
|
|
3023
|
-
putJson: async (path, payload,
|
|
3012
|
+
putJson: async (path, payload, headers) => {
|
|
3024
3013
|
try {
|
|
3025
|
-
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
3026
3014
|
const response = await (path.includes("/auth") ? authApi : api).put(path.replace("/auth", ""), payload, {
|
|
3027
|
-
headers
|
|
3028
|
-
params: withTokenQueryParams(requestOptions)
|
|
3015
|
+
headers
|
|
3029
3016
|
});
|
|
3030
3017
|
return response.data;
|
|
3031
3018
|
} catch (e10) {
|
|
3032
3019
|
throw formatAxiosError(e10);
|
|
3033
3020
|
}
|
|
3034
3021
|
},
|
|
3035
|
-
deleteJson: async (path,
|
|
3022
|
+
deleteJson: async (path, headers) => {
|
|
3036
3023
|
try {
|
|
3037
|
-
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
3038
3024
|
const response = await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
|
|
3039
|
-
headers
|
|
3040
|
-
params: withTokenQueryParams(requestOptions)
|
|
3025
|
+
headers
|
|
3041
3026
|
});
|
|
3042
3027
|
return response.data;
|
|
3043
3028
|
} catch (e10) {
|
|
3044
3029
|
throw formatAxiosError(e10);
|
|
3045
3030
|
}
|
|
3046
3031
|
},
|
|
3047
|
-
deleteVoid: async (path,
|
|
3032
|
+
deleteVoid: async (path, headers) => {
|
|
3048
3033
|
try {
|
|
3049
|
-
|
|
3050
|
-
await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
|
|
3051
|
-
headers: requestOptions.headers,
|
|
3052
|
-
params: withTokenQueryParams(requestOptions)
|
|
3053
|
-
});
|
|
3034
|
+
await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), { headers });
|
|
3054
3035
|
} catch (e10) {
|
|
3055
3036
|
throw formatAxiosError(e10);
|
|
3056
3037
|
}
|
|
3057
3038
|
}
|
|
3058
3039
|
};
|
|
3059
|
-
function buildWsUrl(path = "/", options = {}) {
|
|
3060
|
-
try {
|
|
3061
|
-
const origin2 = new URL(apiOrigin);
|
|
3062
|
-
origin2.protocol = origin2.protocol === "https:" ? "wss:" : "ws:";
|
|
3063
|
-
if (!path.startsWith("/"))
|
|
3064
|
-
path = "/" + path;
|
|
3065
|
-
origin2.pathname = path;
|
|
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
|
-
});
|
|
3073
|
-
} catch (e10) {
|
|
3074
|
-
const proto = apiOrigin.startsWith("https") ? "wss" : "ws";
|
|
3075
|
-
const host = apiOrigin.replace(/^https?:\/\//, "").replace(/\/$/, "");
|
|
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
|
-
);
|
|
3086
|
-
}
|
|
3087
|
-
}
|
|
3088
3040
|
function extractBearerToken(headers, explicitToken) {
|
|
3089
3041
|
if (explicitToken)
|
|
3090
3042
|
return explicitToken;
|
|
@@ -3096,7 +3048,7 @@ function extractBearerToken(headers, explicitToken) {
|
|
|
3096
3048
|
const match = authHeader.match(/^Bearer\s+(.+)$/i);
|
|
3097
3049
|
return match ? match[1] : null;
|
|
3098
3050
|
}
|
|
3099
|
-
function
|
|
3051
|
+
function resolveWebSocketToken(options = {}) {
|
|
3100
3052
|
const explicitToken = options.token ?? options.bearerToken ?? null;
|
|
3101
3053
|
const headerToken = extractBearerToken(options.headers, explicitToken);
|
|
3102
3054
|
if (headerToken)
|
|
@@ -3105,12 +3057,6 @@ function resolveAuthToken(options = {}) {
|
|
|
3105
3057
|
return null;
|
|
3106
3058
|
return getAccessToken();
|
|
3107
3059
|
}
|
|
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
3060
|
function appendQueryParams(url, params) {
|
|
3115
3061
|
if (!params || Object.keys(params).length === 0)
|
|
3116
3062
|
return url;
|
|
@@ -3133,43 +3079,32 @@ function appendQueryParams(url, params) {
|
|
|
3133
3079
|
return `${url}${separator}${search}`;
|
|
3134
3080
|
}
|
|
3135
3081
|
}
|
|
3082
|
+
function withWebSocketTokenQuery(url, options) {
|
|
3083
|
+
const token = resolveWebSocketToken(options);
|
|
3084
|
+
const params = { ...options.query ?? {} };
|
|
3085
|
+
if (token) {
|
|
3086
|
+
params[options.tokenQueryParam ?? options.bearerQueryParam ?? "token"] = token;
|
|
3087
|
+
}
|
|
3088
|
+
return appendQueryParams(url, params);
|
|
3089
|
+
}
|
|
3136
3090
|
function normalizeProtocols(protocols) {
|
|
3137
3091
|
if (!protocols)
|
|
3138
3092
|
return void 0;
|
|
3139
3093
|
return Array.isArray(protocols) ? protocols.filter(Boolean) : [protocols];
|
|
3140
3094
|
}
|
|
3141
|
-
function
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3095
|
+
function buildWsUrl(path = "/", options = {}) {
|
|
3096
|
+
try {
|
|
3097
|
+
const origin2 = new URL(apiOrigin);
|
|
3098
|
+
origin2.protocol = origin2.protocol === "https:" ? "wss:" : "ws:";
|
|
3099
|
+
if (!path.startsWith("/"))
|
|
3100
|
+
path = "/" + path;
|
|
3101
|
+
origin2.pathname = path;
|
|
3102
|
+
return withWebSocketTokenQuery(origin2.toString(), options);
|
|
3103
|
+
} catch (e10) {
|
|
3104
|
+
const proto = apiOrigin.startsWith("https") ? "wss" : "ws";
|
|
3105
|
+
const host = apiOrigin.replace(/^https?:\/\//, "").replace(/\/$/, "");
|
|
3106
|
+
return withWebSocketTokenQuery(`${proto}://${host}${path.startsWith("/") ? path : "/" + path}`, options);
|
|
3151
3107
|
}
|
|
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
3108
|
}
|
|
3174
3109
|
async function encodeFfurl(settings) {
|
|
3175
3110
|
const { ffurl } = await fetchApi.postJson("/auth/protocols/ffurl/encode", settings);
|
|
@@ -3180,30 +3115,18 @@ async function decodeFfurl(ffurl) {
|
|
|
3180
3115
|
return settings;
|
|
3181
3116
|
}
|
|
3182
3117
|
function subscribeToWebsocket(url, onMessage, options = {}) {
|
|
3183
|
-
const
|
|
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);
|
|
3118
|
+
const tokenTransport = options.tokenTransport ?? options.bearerStrategy ?? "query";
|
|
3191
3119
|
const protocols = normalizeProtocols(options.protocols) ?? [];
|
|
3192
3120
|
if (options.headers && Object.keys(options.headers).length > 0) {
|
|
3193
3121
|
console.warn(
|
|
3194
3122
|
"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
3123
|
);
|
|
3196
3124
|
}
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
token: bearerToken,
|
|
3203
|
-
tokenQueryParam: options.tokenQueryParam ?? options.bearerQueryParam,
|
|
3204
|
-
includeStoredToken: false
|
|
3205
|
-
});
|
|
3206
|
-
}
|
|
3125
|
+
let resolvedUrl = tokenTransport === "query" ? withWebSocketTokenQuery(url, options) : appendQueryParams(url, options.query);
|
|
3126
|
+
if (tokenTransport === "protocol") {
|
|
3127
|
+
const token = resolveWebSocketToken(options);
|
|
3128
|
+
if (token)
|
|
3129
|
+
protocols.push("bearer", token);
|
|
3207
3130
|
}
|
|
3208
3131
|
const socket = protocols.length > 0 ? new WebSocket(resolvedUrl, protocols) : new WebSocket(resolvedUrl);
|
|
3209
3132
|
socket.onmessage = (event) => {
|