@viasoftbr/shared-ui 0.0.7-1 → 0.0.7-3

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/services.js CHANGED
@@ -2766,19 +2766,24 @@ function formatAxiosError(err) {
2766
2766
  return err instanceof Error ? err : new Error(String(err));
2767
2767
  }
2768
2768
  var fetchApi = {
2769
- getJson: async (path, params, headers) => {
2769
+ getJson: async (path, params, headersOrOptions) => {
2770
2770
  try {
2771
- const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), { params, headers });
2771
+ const requestOptions = normalizeRequestOptions(params, headersOrOptions);
2772
+ const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
2773
+ params: withTokenQueryParams(requestOptions),
2774
+ headers: requestOptions.headers
2775
+ });
2772
2776
  return response.data;
2773
2777
  } catch (e) {
2774
2778
  throw formatAxiosError(e);
2775
2779
  }
2776
2780
  },
2777
- getText: async (path, params, headers) => {
2781
+ getText: async (path, params, headersOrOptions) => {
2778
2782
  try {
2783
+ const requestOptions = normalizeRequestOptions(params, headersOrOptions);
2779
2784
  const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
2780
- params,
2781
- headers,
2785
+ params: withTokenQueryParams(requestOptions),
2786
+ headers: requestOptions.headers,
2782
2787
  responseType: "text"
2783
2788
  });
2784
2789
  return response.data;
@@ -2786,65 +2791,104 @@ var fetchApi = {
2786
2791
  throw formatAxiosError(e);
2787
2792
  }
2788
2793
  },
2789
- getVoid: async (path, params, headers) => {
2794
+ getVoid: async (path, params, headersOrOptions) => {
2790
2795
  try {
2791
- await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), { params, headers });
2796
+ const requestOptions = normalizeRequestOptions(params, headersOrOptions);
2797
+ await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
2798
+ params: withTokenQueryParams(requestOptions),
2799
+ headers: requestOptions.headers
2800
+ });
2792
2801
  } catch (e) {
2793
2802
  throw formatAxiosError(e);
2794
2803
  }
2795
2804
  },
2796
- postJson: async (path, payload, headers) => {
2805
+ postJson: async (path, payload, headersOrOptions) => {
2797
2806
  try {
2798
- const response = await (path.includes("/auth") ? authApi : api).post(path.replace("/auth", ""), payload, { headers });
2807
+ const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
2808
+ const response = await (path.includes("/auth") ? authApi : api).post(path.replace("/auth", ""), payload, {
2809
+ headers: requestOptions.headers,
2810
+ params: withTokenQueryParams(requestOptions)
2811
+ });
2799
2812
  return response.data;
2800
2813
  } catch (e) {
2801
2814
  throw formatAxiosError(e);
2802
2815
  }
2803
2816
  },
2804
- patchJson: async (path, payload, headers) => {
2817
+ patchJson: async (path, payload, headersOrOptions) => {
2805
2818
  try {
2806
- const response = await (path.includes("/auth") ? authApi : api).patch(path.replace("/auth", ""), payload, { headers });
2819
+ const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
2820
+ const response = await (path.includes("/auth") ? authApi : api).patch(path.replace("/auth", ""), payload, {
2821
+ headers: requestOptions.headers,
2822
+ params: withTokenQueryParams(requestOptions)
2823
+ });
2807
2824
  return response.data;
2808
2825
  } catch (e) {
2809
2826
  throw formatAxiosError(e);
2810
2827
  }
2811
2828
  },
2812
- putJson: async (path, payload, headers) => {
2829
+ putJson: async (path, payload, headersOrOptions) => {
2813
2830
  try {
2814
- const response = await (path.includes("/auth") ? authApi : api).put(path.replace("/auth", ""), payload, { headers });
2831
+ const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
2832
+ const response = await (path.includes("/auth") ? authApi : api).put(path.replace("/auth", ""), payload, {
2833
+ headers: requestOptions.headers,
2834
+ params: withTokenQueryParams(requestOptions)
2835
+ });
2815
2836
  return response.data;
2816
2837
  } catch (e) {
2817
2838
  throw formatAxiosError(e);
2818
2839
  }
2819
2840
  },
2820
- deleteJson: async (path, headers) => {
2841
+ deleteJson: async (path, headersOrOptions) => {
2821
2842
  try {
2822
- const response = await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), { headers });
2843
+ const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
2844
+ const response = await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
2845
+ headers: requestOptions.headers,
2846
+ params: withTokenQueryParams(requestOptions)
2847
+ });
2823
2848
  return response.data;
2824
2849
  } catch (e) {
2825
2850
  throw formatAxiosError(e);
2826
2851
  }
2827
2852
  },
2828
- deleteVoid: async (path, headers) => {
2853
+ deleteVoid: async (path, headersOrOptions) => {
2829
2854
  try {
2830
- await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), { headers });
2855
+ const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
2856
+ await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
2857
+ headers: requestOptions.headers,
2858
+ params: withTokenQueryParams(requestOptions)
2859
+ });
2831
2860
  } catch (e) {
2832
2861
  throw formatAxiosError(e);
2833
2862
  }
2834
2863
  }
2835
2864
  };
2836
- function buildWsUrl(path = "/") {
2865
+ function buildWsUrl(path = "/", options = {}) {
2837
2866
  try {
2838
2867
  const origin2 = new URL(apiOrigin);
2839
2868
  origin2.protocol = origin2.protocol === "https:" ? "wss:" : "ws:";
2840
2869
  if (!path.startsWith("/"))
2841
2870
  path = "/" + path;
2842
2871
  origin2.pathname = path;
2843
- return origin2.toString();
2872
+ return withAccessTokenQuery(origin2.toString(), {
2873
+ headers: options.headers,
2874
+ params: options.query,
2875
+ token: options.token ?? options.bearerToken,
2876
+ tokenQueryParam: options.tokenQueryParam ?? options.bearerQueryParam,
2877
+ includeStoredToken: options.includeStoredToken
2878
+ });
2844
2879
  } catch (e) {
2845
2880
  const proto = apiOrigin.startsWith("https") ? "wss" : "ws";
2846
2881
  const host = apiOrigin.replace(/^https?:\/\//, "").replace(/\/$/, "");
2847
- return `${proto}://${host}${path.startsWith("/") ? path : "/" + path}`;
2882
+ return withAccessTokenQuery(
2883
+ `${proto}://${host}${path.startsWith("/") ? path : "/" + path}`,
2884
+ {
2885
+ headers: options.headers,
2886
+ params: options.query,
2887
+ token: options.token ?? options.bearerToken,
2888
+ tokenQueryParam: options.tokenQueryParam ?? options.bearerQueryParam,
2889
+ includeStoredToken: options.includeStoredToken
2890
+ }
2891
+ );
2848
2892
  }
2849
2893
  }
2850
2894
  function extractBearerToken(headers, explicitToken) {
@@ -2858,17 +2902,41 @@ function extractBearerToken(headers, explicitToken) {
2858
2902
  const match = authHeader.match(/^Bearer\s+(.+)$/i);
2859
2903
  return match ? match[1] : null;
2860
2904
  }
2861
- function appendWsQueryParam(url, key, value) {
2905
+ function resolveAuthToken(options = {}) {
2906
+ const explicitToken = options.token ?? options.bearerToken ?? null;
2907
+ const headerToken = extractBearerToken(options.headers, explicitToken);
2908
+ if (headerToken)
2909
+ return headerToken;
2910
+ if (options.includeStoredToken === false)
2911
+ return null;
2912
+ return getAccessToken();
2913
+ }
2914
+ function mergeQueryParams(params, key, value) {
2915
+ const nextParams = { ...params ?? {} };
2916
+ if (key && value)
2917
+ nextParams[key] = value;
2918
+ return Object.keys(nextParams).length > 0 ? nextParams : void 0;
2919
+ }
2920
+ function appendQueryParams(url, params) {
2921
+ if (!params || Object.keys(params).length === 0)
2922
+ return url;
2862
2923
  try {
2863
2924
  const parsed = new URL(
2864
2925
  url,
2865
2926
  typeof window !== "undefined" ? window.location.href : void 0
2866
2927
  );
2867
- parsed.searchParams.set(key, value);
2928
+ for (const [key, value] of Object.entries(params)) {
2929
+ if (value === void 0 || value === null)
2930
+ continue;
2931
+ parsed.searchParams.set(key, String(value));
2932
+ }
2868
2933
  return parsed.toString();
2869
2934
  } catch {
2935
+ const search = Object.entries(params).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`).join("&");
2936
+ if (!search)
2937
+ return url;
2870
2938
  const separator = url.includes("?") ? "&" : "?";
2871
- return `${url}${separator}${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
2939
+ return `${url}${separator}${search}`;
2872
2940
  }
2873
2941
  }
2874
2942
  function normalizeProtocols(protocols) {
@@ -2876,6 +2944,39 @@ function normalizeProtocols(protocols) {
2876
2944
  return void 0;
2877
2945
  return Array.isArray(protocols) ? protocols.filter(Boolean) : [protocols];
2878
2946
  }
2947
+ function normalizeRequestOptions(params, headersOrOptions) {
2948
+ const maybeOptions = headersOrOptions;
2949
+ const hasOptionShape = Boolean(
2950
+ maybeOptions && ("headers" in maybeOptions || "params" in maybeOptions || "sendTokenInQuery" in maybeOptions || "token" in maybeOptions || "tokenQueryParam" in maybeOptions || "includeStoredToken" in maybeOptions)
2951
+ );
2952
+ if (hasOptionShape) {
2953
+ return {
2954
+ ...maybeOptions,
2955
+ params: { ...params ?? {}, ...maybeOptions?.params ?? {} }
2956
+ };
2957
+ }
2958
+ return {
2959
+ params,
2960
+ headers: headersOrOptions
2961
+ };
2962
+ }
2963
+ function withTokenQueryParams(options) {
2964
+ if (!options.sendTokenInQuery)
2965
+ return options.params;
2966
+ const token = resolveAuthToken(options);
2967
+ return mergeQueryParams(
2968
+ options.params,
2969
+ options.tokenQueryParam ?? "access_token",
2970
+ token
2971
+ );
2972
+ }
2973
+ function withAccessTokenQuery(url, options = {}) {
2974
+ const token = resolveAuthToken(options);
2975
+ return appendQueryParams(
2976
+ url,
2977
+ mergeQueryParams(options.params, options.tokenQueryParam ?? "access_token", token)
2978
+ );
2979
+ }
2879
2980
  async function encodeFfurl(settings) {
2880
2981
  const { ffurl } = await fetchApi.postJson("/auth/protocols/ffurl/encode", settings);
2881
2982
  return ffurl;
@@ -2885,9 +2986,14 @@ async function decodeFfurl(ffurl) {
2885
2986
  return settings;
2886
2987
  }
2887
2988
  function subscribeToWebsocket(url, onMessage, options = {}) {
2888
- const bearerToken = extractBearerToken(options.headers, options.bearerToken);
2889
- const bearerStrategy = options.bearerStrategy ?? "query";
2890
- let resolvedUrl = url;
2989
+ const bearerToken = resolveAuthToken({
2990
+ headers: options.headers,
2991
+ token: options.token,
2992
+ bearerToken: options.bearerToken,
2993
+ includeStoredToken: options.includeStoredToken
2994
+ });
2995
+ const bearerStrategy = options.tokenTransport ?? options.bearerStrategy ?? "query";
2996
+ let resolvedUrl = appendQueryParams(url, options.query);
2891
2997
  const protocols = normalizeProtocols(options.protocols) ?? [];
2892
2998
  if (options.headers && Object.keys(options.headers).length > 0) {
2893
2999
  console.warn(
@@ -2898,11 +3004,11 @@ function subscribeToWebsocket(url, onMessage, options = {}) {
2898
3004
  if (bearerStrategy === "protocol") {
2899
3005
  protocols.push("bearer", bearerToken);
2900
3006
  } else {
2901
- resolvedUrl = appendWsQueryParam(
2902
- url,
2903
- options.bearerQueryParam ?? "access_token",
2904
- bearerToken
2905
- );
3007
+ resolvedUrl = withAccessTokenQuery(resolvedUrl, {
3008
+ token: bearerToken,
3009
+ tokenQueryParam: options.tokenQueryParam ?? options.bearerQueryParam,
3010
+ includeStoredToken: false
3011
+ });
2906
3012
  }
2907
3013
  }
2908
3014
  const socket = protocols.length > 0 ? new WebSocket(resolvedUrl, protocols) : new WebSocket(resolvedUrl);
@@ -3151,5 +3257,6 @@ export {
3151
3257
  setAccessToken,
3152
3258
  setRefreshToken,
3153
3259
  subscribeToWebsocket,
3154
- userService
3260
+ userService,
3261
+ withAccessTokenQuery
3155
3262
  };
@@ -25,10 +25,21 @@ export interface WebSocketData {
25
25
  };
26
26
  system: SystemInfo;
27
27
  }
28
+ export type AuthTokenTransport = 'query' | 'protocol';
29
+ export interface AuthTokenQueryOptions {
30
+ token?: string | null;
31
+ tokenQueryParam?: string;
32
+ includeStoredToken?: boolean;
33
+ }
28
34
  export interface WebSocketSubscribeOptions {
29
35
  headers?: Record<string, string>;
30
36
  protocols?: string | string[];
37
+ query?: Record<string, string | number | boolean | null | undefined>;
38
+ tokenTransport?: AuthTokenTransport;
39
+ token?: string | null;
40
+ tokenQueryParam?: string;
41
+ includeStoredToken?: boolean;
31
42
  bearerToken?: string | null;
32
- bearerStrategy?: 'query' | 'protocol';
43
+ bearerStrategy?: AuthTokenTransport;
33
44
  bearerQueryParam?: string;
34
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viasoftbr/shared-ui",
3
- "version": "0.0.7-1",
3
+ "version": "0.0.7-3",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/types/index.d.ts",
6
6
  "exports": {
@@ -1,8 +0,0 @@
1
- interface RemoteModuleProps {
2
- scope: string;
3
- url: string;
4
- module: string;
5
- fallback?: React.ReactNode;
6
- }
7
- export declare function RemoteModule({ scope, url, module, fallback }: RemoteModuleProps): import("react/jsx-runtime").JSX.Element;
8
- export default RemoteModule;
package/dist/package.json DELETED
@@ -1,111 +0,0 @@
1
- {
2
- "name": "@viasoftbr/shared-ui",
3
- "version": "0.0.3",
4
- "description": "Shared frontend utilities, components and i18n for Viasoft plugins and micro-frontends",
5
- "type": "module",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "import": "./dist/index.js",
11
- "types": "./dist/index.d.ts"
12
- },
13
- "./index": {
14
- "import": "./dist/index.js",
15
- "types": "./dist/index.d.ts"
16
- },
17
- "./context": {
18
- "import": "./dist/context.js",
19
- "types": "./dist/context/index.d.ts"
20
- },
21
- "./components": {
22
- "import": "./dist/components.js",
23
- "types": "./dist/components/index.d.ts"
24
- },
25
- "./services": {
26
- "import": "./dist/services.js",
27
- "types": "./dist/services/index.d.ts"
28
- },
29
- "./types": {
30
- "import": "./dist/types.js",
31
- "types": "./dist/types/index.d.ts"
32
- },
33
- "./i18n": {
34
- "import": "./dist/i18n.js",
35
- "types": "./dist/i18n.d.ts"
36
- },
37
- "./jsmpeg": {
38
- "default": "./dist/jsmpeg.vu.min.js"
39
- },
40
- "./locales/*": {
41
- "default": "./dist/locales/*"
42
- }
43
- },
44
- "scripts": {
45
- "build": "node scripts/build.js",
46
- "dev": "node scripts/build.js --watch",
47
- "typecheck": "tsc --noEmit"
48
- },
49
- "peerDependencies": {
50
- "react": "^19.0.0"
51
- },
52
- "devDependencies": {
53
- "@types/react": "^19.2.13",
54
- "esbuild": "^0.20.0",
55
- "typescript": "^5.0.0"
56
- },
57
- "files": [
58
- "dist"
59
- ],
60
- "overrides": {
61
- "use-sync-external-store": "1.6.1"
62
- },
63
- "resolutions": {
64
- "use-sync-external-store": "1.6.1"
65
- },
66
- "pnpm": {
67
- "overrides": {
68
- "use-sync-external-store": "1.6.1"
69
- }
70
- },
71
- "keywords": [
72
- "viasoft",
73
- "shared",
74
- "utils",
75
- "components",
76
- "i18n",
77
- "microfrontend"
78
- ],
79
- "author": "Viasoft",
80
- "license": "MIT",
81
- "publishConfig": {
82
- "access": "public"
83
- },
84
- "dependencies": {
85
- "@headlessui/react": "^2.2.9",
86
- "@reduxjs/toolkit": "^2.10.1",
87
- "@tanstack/react-query": "^5.90.10",
88
- "@types/react-dom": "^19.2.3",
89
- "@viasoftbr/shared-utils": "^0.0.1",
90
- "axios": "^1.13.2",
91
- "i18next": "^25.7.3",
92
- "json-server": "1.0.0-beta.3",
93
- "lucide-react": "^0.460.0",
94
- "react": "^19.2.4",
95
- "react-dom": "^19.2.4",
96
- "react-i18next": "^16.5.0",
97
- "react-redux": "^9.2.0",
98
- "react-router-dom": "^6.20.1",
99
- "react-tooltip": "^5.30.0",
100
- "redux-batch-middleware": "^0.2.0",
101
- "tailwind-scrollbar": "^4.0.2"
102
- },
103
- "repository": {
104
- "type": "git",
105
- "url": "git+https://github.com/viasoftbr/shared-ui.git"
106
- },
107
- "bugs": {
108
- "url": "https://github.com/viasoftbr/shared-ui/issues"
109
- },
110
- "homepage": "https://github.com/viasoftbr/shared-ui#readme"
111
- }
@@ -1,9 +0,0 @@
1
- import type { ComponentType } from 'react';
2
- declare global {
3
- var __federation_shared__: Record<string, Record<string, unknown>>;
4
- }
5
- export declare function loadRemoteModule(config: {
6
- scope: string;
7
- url: string;
8
- module: string;
9
- }): Promise<ComponentType>;
@@ -1,9 +0,0 @@
1
- import type { PageMetadata } from "../types/plugin.types";
2
- export declare class MetadataLoader {
3
- private metadataCache;
4
- loadMetadata(metadataUrl: string): Promise<PageMetadata[]>;
5
- loadFromDirectory(directoryUrl: string): Promise<PageMetadata[]>;
6
- clearCache(): void;
7
- getCachedMetadata(metadataUrl: string): PageMetadata[] | undefined;
8
- }
9
- export declare const metadataLoader: MetadataLoader;