@pagamio/frontend-commons-lib 0.8.292 → 0.8.294

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/api/client.js CHANGED
@@ -160,10 +160,24 @@ export class ApiClient {
160
160
  */
161
161
  createUrl(endpoint, params) {
162
162
  const raw = endpoint.startsWith('http') ? endpoint : `${this.config.baseURL}${endpoint}`;
163
- // When baseURL is a relative path (e.g. /api/v1) we need window.location.origin
164
- // as the base for the URL constructor.
165
- const base = typeof window !== 'undefined' ? window.location.origin : undefined;
166
- const url = new URL(raw, base);
163
+ // Absolute URLs work directly. Relative paths need a base for the URL
164
+ // constructor use window.location.origin in the browser, or the
165
+ // server-side API_BASE_URL during SSR.
166
+ let url;
167
+ if (raw.startsWith('http')) {
168
+ url = new URL(raw);
169
+ }
170
+ else if (typeof window !== 'undefined') {
171
+ url = new URL(raw, window.location.origin);
172
+ }
173
+ else {
174
+ // SSR: resolve relative path against the backend URL so server-side
175
+ // fetch calls go directly to the backend (no proxy needed server→server).
176
+ const ssrBase = process.env?.API_BASE_URL?.replace(/\/api\/v1$/, '');
177
+ if (!ssrBase)
178
+ throw new Error('API_BASE_URL env var is required for SSR');
179
+ url = new URL(raw, ssrBase);
180
+ }
167
181
  if (params) {
168
182
  Object.entries(params).forEach(([key, value]) => {
169
183
  url.searchParams.append(key, value);
@@ -63,7 +63,19 @@ export class LogoutService {
63
63
  }
64
64
  }
65
65
  async invalidateServerSession(endpoint, token) {
66
- const fullEndpoint = endpoint.startsWith('http') ? endpoint : `${this.baseUrl}${endpoint}`;
66
+ let fullEndpoint = endpoint.startsWith('http') ? endpoint : `${this.baseUrl}${endpoint}`;
67
+ // Resolve relative URLs for SSR — Node's fetch requires absolute URLs.
68
+ if (!fullEndpoint.startsWith('http')) {
69
+ if (typeof window !== 'undefined') {
70
+ fullEndpoint = `${window.location.origin}${fullEndpoint}`;
71
+ }
72
+ else {
73
+ const serverBase = process.env?.API_BASE_URL?.replace(/\/api\/v1$/, '');
74
+ if (!serverBase)
75
+ throw new Error('API_BASE_URL env var is required for SSR');
76
+ fullEndpoint = `${serverBase}${fullEndpoint}`;
77
+ }
78
+ }
67
79
  const response = await fetch(fullEndpoint, {
68
80
  method: 'POST',
69
81
  headers: {
@@ -64,7 +64,20 @@ export class TokenManager {
64
64
  // Requests go through the same-origin proxy so cookies are first-party
65
65
  // and sent automatically with credentials: 'same-origin'.
66
66
  const oldRefreshToken = this.getRefreshToken();
67
- const response = await fetch(`${this.baseUrl}${this.refreshEndpoint}`, {
67
+ // Resolve relative URLs for SSR — Node's fetch requires absolute URLs.
68
+ let refreshUrl = `${this.baseUrl}${this.refreshEndpoint}`;
69
+ if (!refreshUrl.startsWith('http')) {
70
+ if (typeof window !== 'undefined') {
71
+ refreshUrl = `${window.location.origin}${refreshUrl}`;
72
+ }
73
+ else {
74
+ const serverBase = process.env?.API_BASE_URL?.replace(/\/api\/v1$/, '');
75
+ if (!serverBase)
76
+ throw new Error('API_BASE_URL env var is required for SSR');
77
+ refreshUrl = `${serverBase}${refreshUrl}`;
78
+ }
79
+ }
80
+ const response = await fetch(refreshUrl, {
68
81
  method: 'POST',
69
82
  credentials: 'same-origin',
70
83
  headers: {
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @fileoverview ChartDetailsModal
3
+ *
4
+ * Standardized 3-tab modal shell for chart drill-down views.
5
+ * Provides Visual Chart, Data Table, and Analytics tabs with a consistent
6
+ * layout across all dashboards.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * <ChartDetailsModal
11
+ * isOpen={isOpen}
12
+ * onClose={onClose}
13
+ * title="Top Products"
14
+ * chartContent={<BarChartV2 ... />}
15
+ * tableContent={<MyTable data={data} />}
16
+ * analyticsContent={<MyStats data={data} />}
17
+ * />
18
+ * ```
19
+ */
20
+ import * as React from 'react';
21
+ export interface ChartDetailsModalProps {
22
+ /** Whether the modal is open */
23
+ isOpen: boolean;
24
+ /** Callback to close the modal */
25
+ onClose: () => void;
26
+ /** Modal title (shown in header) */
27
+ title: string;
28
+ /** Content for the Visual Chart tab */
29
+ chartContent: React.ReactNode;
30
+ /** Content for the Data Table tab */
31
+ tableContent: React.ReactNode;
32
+ /** Content for the Analytics tab */
33
+ analyticsContent: React.ReactNode;
34
+ /** Modal width size — defaults to 7xl */
35
+ size?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl' | '6xl' | '7xl';
36
+ }
37
+ declare const ChartDetailsModal: React.FC<ChartDetailsModalProps>;
38
+ export default ChartDetailsModal;
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Modal } from '../../../components';
3
+ import { PagamioTabs } from '../../../components';
4
+ // =============================================================================
5
+ // COMPONENT
6
+ // =============================================================================
7
+ const ChartDetailsModal = ({ isOpen, onClose, title, chartContent, tableContent, analyticsContent, size = '7xl', }) => {
8
+ const tabs = [
9
+ {
10
+ id: 1,
11
+ title: 'Visual Chart',
12
+ content: _jsx("div", { className: "py-2", children: chartContent }),
13
+ },
14
+ {
15
+ id: 2,
16
+ title: 'Data Table',
17
+ content: _jsx("div", { className: "py-2", children: tableContent }),
18
+ },
19
+ {
20
+ id: 3,
21
+ title: 'Analytics',
22
+ content: _jsx("div", { className: "py-2", children: analyticsContent }),
23
+ },
24
+ ];
25
+ return (_jsx(Modal, { isOpen: isOpen, onClose: onClose, title: `${title} — Detailed Analysis`, size: size, children: _jsx(PagamioTabs, { tabs: tabs, defaultTab: 0, variant: "pills" }) }));
26
+ };
27
+ export default ChartDetailsModal;
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ export interface ChartExpandButtonProps {
3
+ /** Handler called when the button is clicked */
4
+ onClick: () => void;
5
+ /** Optional accessible label — defaults to "View Details" */
6
+ label?: string;
7
+ }
8
+ declare const ChartExpandButton: React.FC<ChartExpandButtonProps>;
9
+ export default ChartExpandButton;
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * @fileoverview ChartExpandButton
4
+ *
5
+ * Standardized icon button used to open chart detail modals.
6
+ * Renders in the DashboardCard `actions` slot (top-right of chart cards).
7
+ * Replaces all "View All" text links with a consistent icon button.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * // Inside a DashboardWrapperV2 ChartConfig:
12
+ * action: <ChartExpandButton onClick={() => setIsOpen(true)} />,
13
+ * ```
14
+ */
15
+ import { HiArrowsExpand } from 'react-icons/hi';
16
+ import { IconButton } from '../../../components';
17
+ // =============================================================================
18
+ // COMPONENT
19
+ // =============================================================================
20
+ const ChartExpandButton = ({ onClick, label = 'View Details' }) => {
21
+ return _jsx(IconButton, { icon: HiArrowsExpand, label: label, variant: "ghost", size: "sm", onClick: onClick });
22
+ };
23
+ export default ChartExpandButton;
@@ -11,3 +11,7 @@ export { DashboardStatCardRow, DashboardStatCard } from './DashboardStatCardRow'
11
11
  export type { DashboardStatCardRowProps, DashboardStatCardProps } from './DashboardStatCardRow';
12
12
  export { DashboardChartRow, ChartRenderer } from './DashboardChartRow';
13
13
  export type { DashboardChartRowProps, ChartRendererProps } from './DashboardChartRow';
14
+ export { default as ChartDetailsModal } from './ChartDetailsModal';
15
+ export type { ChartDetailsModalProps } from './ChartDetailsModal';
16
+ export { default as ChartExpandButton } from './ChartExpandButton';
17
+ export type { ChartExpandButtonProps } from './ChartExpandButton';
@@ -12,3 +12,7 @@ export { DashboardWrapperV2 } from './DashboardWrapperV2';
12
12
  export { DashboardStatCardRow, DashboardStatCard } from './DashboardStatCardRow';
13
13
  // Chart Row
14
14
  export { DashboardChartRow, ChartRenderer } from './DashboardChartRow';
15
+ // Chart Details Modal — standardized 3-tab drill-down shell
16
+ export { default as ChartDetailsModal } from './ChartDetailsModal';
17
+ // Chart Expand Button — icon button for opening chart detail modals
18
+ export { default as ChartExpandButton } from './ChartExpandButton';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pagamio/frontend-commons-lib",
3
3
  "description": "Pagamio library for Frontend reusable components like the form engine and table container",
4
- "version": "0.8.292",
4
+ "version": "0.8.294",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "provenance": false