@agentpaid/paid-nextjs-client 0.1.1 → 0.3.0-test.1

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.
Files changed (54) hide show
  1. package/README.md +57 -0
  2. package/dist/api/api/handlePaidInvoicePdf.ts +79 -0
  3. package/dist/api/api/handlePaidInvoices.ts +77 -0
  4. package/dist/api/api/handlePaidPayments.ts +77 -0
  5. package/dist/api/handlePaidInvoicePdf.d.ts +6 -0
  6. package/dist/api/handlePaidInvoicePdf.d.ts.map +1 -0
  7. package/dist/api/handlePaidInvoicePdf.js +60 -0
  8. package/dist/api/handlePaidInvoicePdf.js.map +1 -0
  9. package/dist/api/handlePaidInvoices.d.ts +6 -0
  10. package/dist/api/handlePaidInvoices.d.ts.map +1 -0
  11. package/dist/api/handlePaidInvoices.js +56 -0
  12. package/dist/api/handlePaidInvoices.js.map +1 -0
  13. package/dist/api/handlePaidPayments.d.ts +6 -0
  14. package/dist/api/handlePaidPayments.d.ts.map +1 -0
  15. package/dist/api/handlePaidPayments.js +56 -0
  16. package/dist/api/handlePaidPayments.js.map +1 -0
  17. package/dist/components/PaidActivityLog.d.ts +27 -1
  18. package/dist/components/PaidActivityLog.d.ts.map +1 -1
  19. package/dist/components/PaidActivityLog.js +28 -6
  20. package/dist/components/PaidActivityLog.js.map +1 -1
  21. package/dist/components/PaidContainer.d.ts +45 -0
  22. package/dist/components/PaidContainer.d.ts.map +1 -0
  23. package/dist/components/PaidContainer.js +29 -0
  24. package/dist/components/PaidContainer.js.map +1 -0
  25. package/dist/components/PaidInvoiceTable.d.ts +35 -0
  26. package/dist/components/PaidInvoiceTable.d.ts.map +1 -0
  27. package/dist/components/PaidInvoiceTable.js +138 -0
  28. package/dist/components/PaidInvoiceTable.js.map +1 -0
  29. package/dist/components/PaidPaymentsTable.d.ts +35 -0
  30. package/dist/components/PaidPaymentsTable.d.ts.map +1 -0
  31. package/dist/components/PaidPaymentsTable.js +99 -0
  32. package/dist/components/PaidPaymentsTable.js.map +1 -0
  33. package/dist/components/components/PaidActivityLog.js +73 -20
  34. package/dist/components/components/PaidContainer.js +113 -0
  35. package/dist/components/components/PaidInvoiceTable.js +321 -0
  36. package/dist/components/components/PaidPaymentsTable.js +216 -0
  37. package/dist/hooks/useCache.d.ts +12 -0
  38. package/dist/hooks/useCache.d.ts.map +1 -0
  39. package/dist/hooks/useCache.js +43 -0
  40. package/dist/hooks/useCache.js.map +1 -0
  41. package/dist/index.d.ts +7 -1
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +7 -1
  44. package/dist/index.js.map +1 -1
  45. package/dist/styles/activity-log-table.css +29 -27
  46. package/dist/styles/paid-container.css +139 -0
  47. package/dist/styles/paid-invoice-table.css +344 -0
  48. package/dist/styles/paid-payments-table.css +238 -0
  49. package/dist/tsconfig.tsbuildinfo +1 -1
  50. package/dist/utils/cache.d.ts +30 -0
  51. package/dist/utils/cache.d.ts.map +1 -0
  52. package/dist/utils/cache.js +101 -0
  53. package/dist/utils/cache.js.map +1 -0
  54. package/package.json +9 -3
package/README.md CHANGED
@@ -94,3 +94,60 @@ export default function AgentDashboard() {
94
94
  }
95
95
  ```
96
96
 
97
+ ---
98
+
99
+ ## Styling & Customization
100
+
101
+ The `PaidActivityLog` component is fully customizable through the `paidStyle` prop. You can override the visual design of the component, such as fonts, colors, borders, and layout, by passing an object with our predefined styling variables.
102
+
103
+ These custom CSS properties map directly to visual elements inside the component and allow full control over typography, layout, and colors without modifying any stylesheets.
104
+
105
+ ## Example
106
+
107
+ ```html
108
+ <PaidActivityLog
109
+ accountExternalId="customer_123"
110
+ paidStyle={{
111
+ paidTitleColor: '#ff0000',
112
+ paidTitleFontWeight: 'bold',
113
+ paidFontFamily: 'Comic Sans MS, Comic Sans, sans-serif',
114
+ paidWrapperBorder: 'none',
115
+ paidHeaderBorderBottom: 'none',
116
+ paidThBorderBottom: 'none',
117
+ paidTdBorderBottom: 'none',
118
+ paidTdColor: '#00ff00',
119
+ paidTdBg: '#0000ff',
120
+ paidRowHoverBg: '#000000',
121
+ }}
122
+ />
123
+ ```
124
+
125
+ ## Available Style Variables
126
+
127
+ | Variable Name | CSS Custom Property | Description |
128
+ | --- | --- | --- |
129
+ | `paidFontFamily` | `--paid-font-family` | Global font for all content |
130
+ | `paidTitleFontSize` | `--paid-title-font-size` | Title font size |
131
+ | `paidTitleFontWeight` | `--paid-title-font-weight` | Title font weight |
132
+ | `paidTitleColor` | `--paid-title-color` | Title color |
133
+ | `paidToggleFontSize` | `--paid-toggle-font-size` | Toggle font size |
134
+ | `paidToggleFontWeight` | `--paid-toggle-font-weight` | Toggle font weight |
135
+ | `paidToggleColor` | `--paid-toggle-color` | Toggle color |
136
+ | `paidThFontSize` | `--paid-th-font-size` | Table header font size |
137
+ | `paidThFontWeight` | `--paid-th-font-weight` | Table header font weight |
138
+ | `paidThColor` | `--paid-th-color` | Table header text color |
139
+ | `paidTdFontSize` | `--paid-td-font-size` | Table data font size |
140
+ | `paidTdFontWeight` | `--paid-td-font-weight` | Table data font weight |
141
+ | `paidTdColor` | `--paid-td-color` | Table data text color |
142
+ | `paidEmptyColor` | `--paid-empty-color` | “No usage data” message color |
143
+ | `paidWrapperBg` | `--paid-wrapper-bg` | Outer wrapper background |
144
+ | `paidWrapperBorder` | `--paid-wrapper-border` | Outer wrapper border |
145
+ | `paidHeaderBg` | `--paid-header-bg` | Header bar background |
146
+ | `paidHeaderBorderBottom` | `--paid-header-border-bottom` | Header bottom border |
147
+ | `paidTableBg` | `--paid-table-bg` | Table background |
148
+ | `paidThBg` | `--paid-th-bg` | Header cell background |
149
+ | `paidThBorderBottom` | `--paid-th-border-bottom` | Header cell bottom border |
150
+ | `paidTdBg` | `--paid-td-bg` | Data cell background |
151
+ | `paidTdBorderBottom` | `--paid-td-border-bottom` | Data cell bottom border |
152
+ | `paidRowHoverBg` | `--paid-row-hover-bg` | Data row hover background |
153
+
@@ -0,0 +1,79 @@
1
+ export function handlePaidInvoicePdf(apiKey: string, apiBase?: string) {
2
+ return async function GET(
3
+ _: Request,
4
+ { params }: { params: { invoiceId: string } }
5
+ ) {
6
+ try {
7
+ if (!apiBase) {
8
+ apiBase = 'https://api.agentpaid.io';
9
+ }
10
+
11
+ const { invoiceId } = params;
12
+
13
+ if (!apiKey) {
14
+ return new Response(
15
+ JSON.stringify({ error: 'API key not configured' }),
16
+ {
17
+ status: 500,
18
+ headers: { 'Content-Type': 'application/json' }
19
+ }
20
+ );
21
+ }
22
+
23
+ const url = `${apiBase}/api/organizations/org/invoices/${invoiceId}/pdf`;
24
+
25
+ const response = await fetch(url, {
26
+ headers: {
27
+ 'Authorization': `Bearer ${apiKey}`,
28
+ },
29
+ }
30
+ );
31
+
32
+ if (!response.ok) {
33
+ let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
34
+ try {
35
+ const errorData = await response.json();
36
+ errorMessage = errorData.error || errorData.message || errorMessage;
37
+ } catch (parseError) {
38
+ try {
39
+ const errorText = await response.text();
40
+ if (errorText) {
41
+ errorMessage = errorText;
42
+ }
43
+ } catch (textError) {
44
+ console.log('handlePaidInvoicePdf - Could not parse error response');
45
+ }
46
+ }
47
+
48
+ return new Response(
49
+ JSON.stringify({ error: errorMessage }),
50
+ {
51
+ status: response.status,
52
+ headers: { 'Content-Type': 'application/json' }
53
+ }
54
+ );
55
+ }
56
+
57
+ const data = await response.json();
58
+ return new Response(
59
+ JSON.stringify(data),
60
+ {
61
+ status: 200,
62
+ headers: { 'Content-Type': 'application/json' }
63
+ }
64
+ );
65
+ } catch (error) {
66
+ console.error('Error fetching invoice PDF:', error);
67
+ return new Response(
68
+ JSON.stringify({
69
+ error: 'Failed to fetch invoice PDF',
70
+ details: error instanceof Error ? error.message : String(error)
71
+ }),
72
+ {
73
+ status: 500,
74
+ headers: { 'Content-Type': 'application/json' }
75
+ }
76
+ );
77
+ }
78
+ }
79
+ }
@@ -0,0 +1,77 @@
1
+ export function handlePaidInvoices(apiKey: string, apiBase?: string) {
2
+ return async function GET(
3
+ _: Request,
4
+ { params }: { params: { accountExternalId: string } }
5
+ ) {
6
+ try {
7
+
8
+ if (!apiBase) {
9
+ apiBase = 'https://api.agentpaid.io';
10
+ }
11
+
12
+ const { accountExternalId } = params;
13
+
14
+ if (!apiKey) {
15
+ console.log('handlePaidInvoices - No API key provided');
16
+ return new Response(
17
+ JSON.stringify({ error: 'API key not configured' }),
18
+ {
19
+ status: 500,
20
+ headers: { 'Content-Type': 'application/json' }
21
+ }
22
+ );
23
+ }
24
+
25
+ const url = `${apiBase}/api/organizations/org/customer/external/${accountExternalId}/invoices`;
26
+
27
+ const response = await fetch(url, {
28
+ headers: {
29
+ 'Authorization': `Bearer ${apiKey}`,
30
+ },
31
+ }
32
+ );
33
+
34
+ if (!response.ok) {
35
+ let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
36
+ try {
37
+ // Try to read as JSON first
38
+ const errorData = await response.json();
39
+ errorMessage = errorData.error || errorData.message || errorMessage;
40
+ } catch (parseError) {
41
+ // If JSON parsing fails, the body has been consumed, so we can't read it as text
42
+ // Just use the HTTP status message
43
+ console.log('handlePaidInvoices - Could not parse error response as JSON');
44
+ }
45
+
46
+ return new Response(
47
+ JSON.stringify({ error: errorMessage }),
48
+ {
49
+ status: response.status,
50
+ headers: { 'Content-Type': 'application/json' }
51
+ }
52
+ );
53
+ }
54
+
55
+ const data = await response.json();
56
+ return new Response(
57
+ JSON.stringify(data),
58
+ {
59
+ status: 200,
60
+ headers: { 'Content-Type': 'application/json' }
61
+ }
62
+ );
63
+ } catch (error) {
64
+ console.error('Error fetching invoices:', error);
65
+ return new Response(
66
+ JSON.stringify({
67
+ error: 'Failed to fetch invoices',
68
+ details: error instanceof Error ? error.message : String(error)
69
+ }),
70
+ {
71
+ status: 500,
72
+ headers: { 'Content-Type': 'application/json' }
73
+ }
74
+ );
75
+ }
76
+ }
77
+ }
@@ -0,0 +1,77 @@
1
+ export function handlePaidPayments(apiKey: string, apiBase?: string) {
2
+ return async function GET(
3
+ _: Request,
4
+ { params }: { params: { accountExternalId: string } }
5
+ ) {
6
+ try {
7
+
8
+ if (!apiBase) {
9
+ apiBase = 'https://api.agentpaid.io';
10
+ }
11
+
12
+ const { accountExternalId } = params;
13
+
14
+ if (!apiKey) {
15
+ console.log('handlePaidPayments - No API key provided');
16
+ return new Response(
17
+ JSON.stringify({ error: 'API key not configured' }),
18
+ {
19
+ status: 500,
20
+ headers: { 'Content-Type': 'application/json' }
21
+ }
22
+ );
23
+ }
24
+
25
+ const url = `${apiBase}/api/organizations/org/customer/external/${accountExternalId}/payments`;
26
+
27
+ const response = await fetch(url, {
28
+ headers: {
29
+ 'Authorization': `Bearer ${apiKey}`,
30
+ },
31
+ }
32
+ );
33
+
34
+ if (!response.ok) {
35
+ let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
36
+ try {
37
+ // Try to read as JSON first
38
+ const errorData = await response.json();
39
+ errorMessage = errorData.error || errorData.message || errorMessage;
40
+ } catch (parseError) {
41
+ // If JSON parsing fails, the body has been consumed, so we can't read it as text
42
+ // Just use the HTTP status message
43
+ console.log('handlePaidPayments - Could not parse error response as JSON');
44
+ }
45
+
46
+ return new Response(
47
+ JSON.stringify({ error: errorMessage }),
48
+ {
49
+ status: response.status,
50
+ headers: { 'Content-Type': 'application/json' }
51
+ }
52
+ );
53
+ }
54
+
55
+ const data = await response.json();
56
+ return new Response(
57
+ JSON.stringify(data),
58
+ {
59
+ status: 200,
60
+ headers: { 'Content-Type': 'application/json' }
61
+ }
62
+ );
63
+ } catch (error) {
64
+ console.error('Error fetching payments:', error);
65
+ return new Response(
66
+ JSON.stringify({
67
+ error: 'Failed to fetch payments',
68
+ details: error instanceof Error ? error.message : String(error)
69
+ }),
70
+ {
71
+ status: 500,
72
+ headers: { 'Content-Type': 'application/json' }
73
+ }
74
+ );
75
+ }
76
+ }
77
+ }
@@ -0,0 +1,6 @@
1
+ export declare function handlePaidInvoicePdf(apiKey: string, apiBase?: string): (_: Request, { params }: {
2
+ params: {
3
+ invoiceId: string;
4
+ };
5
+ }) => Promise<Response>;
6
+ //# sourceMappingURL=handlePaidInvoicePdf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlePaidInvoicePdf.d.ts","sourceRoot":"","sources":["../../src/api/handlePaidInvoicePdf.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,OAE5D,OAAO;YACY;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE;wBA2E9C"}
@@ -0,0 +1,60 @@
1
+ export function handlePaidInvoicePdf(apiKey, apiBase) {
2
+ return async function GET(_, { params }) {
3
+ try {
4
+ if (!apiBase) {
5
+ apiBase = 'https://api.agentpaid.io';
6
+ }
7
+ const { invoiceId } = params;
8
+ if (!apiKey) {
9
+ return new Response(JSON.stringify({ error: 'API key not configured' }), {
10
+ status: 500,
11
+ headers: { 'Content-Type': 'application/json' }
12
+ });
13
+ }
14
+ const url = `${apiBase}/api/organizations/org/invoices/${invoiceId}/pdf`;
15
+ const response = await fetch(url, {
16
+ headers: {
17
+ 'Authorization': `Bearer ${apiKey}`,
18
+ },
19
+ });
20
+ if (!response.ok) {
21
+ let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
22
+ try {
23
+ const errorData = await response.json();
24
+ errorMessage = errorData.error || errorData.message || errorMessage;
25
+ }
26
+ catch (parseError) {
27
+ try {
28
+ const errorText = await response.text();
29
+ if (errorText) {
30
+ errorMessage = errorText;
31
+ }
32
+ }
33
+ catch (textError) {
34
+ console.log('handlePaidInvoicePdf - Could not parse error response');
35
+ }
36
+ }
37
+ return new Response(JSON.stringify({ error: errorMessage }), {
38
+ status: response.status,
39
+ headers: { 'Content-Type': 'application/json' }
40
+ });
41
+ }
42
+ const data = await response.json();
43
+ return new Response(JSON.stringify(data), {
44
+ status: 200,
45
+ headers: { 'Content-Type': 'application/json' }
46
+ });
47
+ }
48
+ catch (error) {
49
+ console.error('Error fetching invoice PDF:', error);
50
+ return new Response(JSON.stringify({
51
+ error: 'Failed to fetch invoice PDF',
52
+ details: error instanceof Error ? error.message : String(error)
53
+ }), {
54
+ status: 500,
55
+ headers: { 'Content-Type': 'application/json' }
56
+ });
57
+ }
58
+ };
59
+ }
60
+ //# sourceMappingURL=handlePaidInvoicePdf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlePaidInvoicePdf.js","sourceRoot":"","sources":["../../src/api/handlePaidInvoicePdf.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,oBAAoB,CAAC,MAAc,EAAE,OAAgB;IACjE,OAAO,KAAK,UAAU,GAAG,CACvB,CAAU,EACV,EAAE,MAAM,EAAqC;QAE7C,IAAI,CAAC;YACH,IAAI,CAAC,OAAO,EAAE,CAAC;gBACX,OAAO,GAAG,0BAA0B,CAAC;YACzC,CAAC;YAED,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;YAE7B,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO,IAAI,QAAQ,CACjB,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,wBAAwB,EAAE,CAAC,EACnD;oBACE,MAAM,EAAE,GAAG;oBACX,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;iBAChD,CACF,CAAC;YACJ,CAAC;YAED,MAAM,GAAG,GAAG,GAAG,OAAO,mCAAmC,SAAS,MAAM,CAAC;YAEzE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;gBAC9B,OAAO,EAAE;oBACP,eAAe,EAAE,UAAU,MAAM,EAAE;iBACpC;aACF,CACF,CAAC;YAEF,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,IAAI,YAAY,GAAG,QAAQ,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,UAAU,EAAE,CAAC;gBACrE,IAAI,CAAC;oBACH,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC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AE;aAChD,CACF,CAAC;QACJ,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare function handlePaidInvoices(apiKey: string, apiBase?: string): (_: Request, { params }: {
2
+ params: {
3
+ accountExternalId: string;
4
+ };
5
+ }) => Promise<Response>;
6
+ //# sourceMappingURL=handlePaidInvoices.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlePaidInvoices.d.ts","sourceRoot":"","sources":["../../src/api/handlePaidInvoices.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,OAE1D,OAAO;YACY;QAAE,iBAAiB,EAAE,MAAM,CAAA;KAAE;wBAyEtD"}
@@ -0,0 +1,56 @@
1
+ export function handlePaidInvoices(apiKey, apiBase) {
2
+ return async function GET(_, { params }) {
3
+ try {
4
+ if (!apiBase) {
5
+ apiBase = 'https://api.agentpaid.io';
6
+ }
7
+ const { accountExternalId } = params;
8
+ if (!apiKey) {
9
+ console.log('handlePaidInvoices - No API key provided');
10
+ return new Response(JSON.stringify({ error: 'API key not configured' }), {
11
+ status: 500,
12
+ headers: { 'Content-Type': 'application/json' }
13
+ });
14
+ }
15
+ const url = `${apiBase}/api/organizations/org/customer/external/${accountExternalId}/invoices`;
16
+ const response = await fetch(url, {
17
+ headers: {
18
+ 'Authorization': `Bearer ${apiKey}`,
19
+ },
20
+ });
21
+ if (!response.ok) {
22
+ let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
23
+ try {
24
+ // Try to read as JSON first
25
+ const errorData = await response.json();
26
+ errorMessage = errorData.error || errorData.message || errorMessage;
27
+ }
28
+ catch (parseError) {
29
+ // If JSON parsing fails, the body has been consumed, so we can't read it as text
30
+ // Just use the HTTP status message
31
+ console.log('handlePaidInvoices - Could not parse error response as JSON');
32
+ }
33
+ return new Response(JSON.stringify({ error: errorMessage }), {
34
+ status: response.status,
35
+ headers: { 'Content-Type': 'application/json' }
36
+ });
37
+ }
38
+ const data = await response.json();
39
+ return new Response(JSON.stringify(data), {
40
+ status: 200,
41
+ headers: { 'Content-Type': 'application/json' }
42
+ });
43
+ }
44
+ catch (error) {
45
+ console.error('Error fetching invoices:', error);
46
+ return new Response(JSON.stringify({
47
+ error: 'Failed to fetch invoices',
48
+ details: error instanceof Error ? error.message : String(error)
49
+ }), {
50
+ status: 500,
51
+ headers: { 'Content-Type': 'application/json' }
52
+ });
53
+ }
54
+ };
55
+ }
56
+ //# sourceMappingURL=handlePaidInvoices.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlePaidInvoices.js","sourceRoot":"","sources":["../../src/api/handlePaidInvoices.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,kBAAkB,CAAC,MAAc,EAAE,OAAgB;IAC/D,OAAO,KAAK,UAAU,GAAG,CACvB,CAAU,EACV,EAAE,MAAM,EAA6C;QAErD,IAAI,CAAC;YAEH,IAAI,CAAC,OAAO,EAAE,CAAC;gBACX,OAAO,GAAG,0BAA0B,CAAC;YACzC,CAAC;YAED,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;YAErC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;gBACxD,OAAO,IAAI,QAAQ,CACjB,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,wBAAwB,EAAE,CAAC,EACnD;oBACE,MAAM,EAAE,GAAG;oBACX,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;iBAChD,CACF,CAAC;YACJ,CAAC;YAED,MAAM,GAAG,GAAG,GAAG,OAAO,4CAA4C,iBAAiB,WAAW,CAAC;YAE/F,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;gBAC9B,OAAO,EAAE;oBACP,eAAe,EAAE,UAAU,MAAM,EAAE;iBACpC;aACF,CACF,CAAC;YAEF,IAAI,CAAC,QAAQ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AE,EAAE,cAAc,EAAE,kBAAkB,EAAE;aAChD,CACF,CAAC;QACJ,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare function handlePaidPayments(apiKey: string, apiBase?: string): (_: Request, { params }: {
2
+ params: {
3
+ accountExternalId: string;
4
+ };
5
+ }) => Promise<Response>;
6
+ //# sourceMappingURL=handlePaidPayments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlePaidPayments.d.ts","sourceRoot":"","sources":["../../src/api/handlePaidPayments.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,OAE1D,OAAO;YACY;QAAE,iBAAiB,EAAE,MAAM,CAAA;KAAE;wBAyEtD"}
@@ -0,0 +1,56 @@
1
+ export function handlePaidPayments(apiKey, apiBase) {
2
+ return async function GET(_, { params }) {
3
+ try {
4
+ if (!apiBase) {
5
+ apiBase = 'https://api.agentpaid.io';
6
+ }
7
+ const { accountExternalId } = params;
8
+ if (!apiKey) {
9
+ console.log('handlePaidPayments - No API key provided');
10
+ return new Response(JSON.stringify({ error: 'API key not configured' }), {
11
+ status: 500,
12
+ headers: { 'Content-Type': 'application/json' }
13
+ });
14
+ }
15
+ const url = `${apiBase}/api/organizations/org/customer/external/${accountExternalId}/payments`;
16
+ const response = await fetch(url, {
17
+ headers: {
18
+ 'Authorization': `Bearer ${apiKey}`,
19
+ },
20
+ });
21
+ if (!response.ok) {
22
+ let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
23
+ try {
24
+ // Try to read as JSON first
25
+ const errorData = await response.json();
26
+ errorMessage = errorData.error || errorData.message || errorMessage;
27
+ }
28
+ catch (parseError) {
29
+ // If JSON parsing fails, the body has been consumed, so we can't read it as text
30
+ // Just use the HTTP status message
31
+ console.log('handlePaidPayments - Could not parse error response as JSON');
32
+ }
33
+ return new Response(JSON.stringify({ error: errorMessage }), {
34
+ status: response.status,
35
+ headers: { 'Content-Type': 'application/json' }
36
+ });
37
+ }
38
+ const data = await response.json();
39
+ return new Response(JSON.stringify(data), {
40
+ status: 200,
41
+ headers: { 'Content-Type': 'application/json' }
42
+ });
43
+ }
44
+ catch (error) {
45
+ console.error('Error fetching payments:', error);
46
+ return new Response(JSON.stringify({
47
+ error: 'Failed to fetch payments',
48
+ details: error instanceof Error ? error.message : String(error)
49
+ }), {
50
+ status: 500,
51
+ headers: { 'Content-Type': 'application/json' }
52
+ });
53
+ }
54
+ };
55
+ }
56
+ //# sourceMappingURL=handlePaidPayments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlePaidPayments.js","sourceRoot":"","sources":["../../src/api/handlePaidPayments.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,kBAAkB,CAAC,MAAc,EAAE,OAAgB;IAC/D,OAAO,KAAK,UAAU,GAAG,CACvB,CAAU,EACV,EAAE,MAAM,EAA6C;QAErD,IAAI,CAAC;YAEH,IAAI,CAAC,OAAO,EAAE,CAAC;gBACX,OAAO,GAAG,0BAA0B,CAAC;YACzC,CAAC;YAED,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;YAErC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;gBACxD,OAAO,IAAI,QAAQ,CACjB,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,wBAAwB,EAAE,CAAC,EACnD;oBACE,MAAM,EAAE,GAAG;oBACX,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;iBAChD,CACF,CAAC;YACJ,CAAC;YAED,MAAM,GAAG,GAAG,GAAG,OAAO,4CAA4C,iBAAiB,WAAW,CAAC;YAE/F,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;gBAC9B,OAAO,EAAE;oBACP,eAAe,EAAE,UAAU,MAAM,EAAE;iBACpC;aACF,CACF,CAAC;YAEF,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G;gBACX,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;aAChD,CACF,CAAC;QACJ,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
@@ -1,8 +1,34 @@
1
1
  import React from 'react';
2
2
  import '../styles/activity-log-table.css';
3
+ interface PaidStyleProperties {
4
+ paidTitleColor?: string;
5
+ paidTitleFontWeight?: string;
6
+ paidFontFamily?: string;
7
+ paidWrapperBorder?: string;
8
+ paidHeaderBorderBottom?: string;
9
+ paidThBorderBottom?: string;
10
+ paidTdBorderBottom?: string;
11
+ paidTdBg?: string;
12
+ paidTdFontWeight?: string;
13
+ paidTitleFontSize?: string;
14
+ paidToggleFontSize?: string;
15
+ paidToggleFontWeight?: string;
16
+ paidToggleColor?: string;
17
+ paidThFontSize?: string;
18
+ paidThFontWeight?: string;
19
+ paidThColor?: string;
20
+ paidTdFontSize?: string;
21
+ paidTdColor?: string;
22
+ paidEmptyColor?: string;
23
+ paidWrapperBg?: string;
24
+ paidHeaderBg?: string;
25
+ paidTableBg?: string;
26
+ paidThBg?: string;
27
+ paidRowHoverBg?: string;
28
+ }
3
29
  interface PaidActivityLogProps {
4
30
  accountExternalId: string;
5
- host?: string;
31
+ paidStyle?: PaidStyleProperties;
6
32
  }
7
33
  export declare const PaidActivityLog: React.FC<PaidActivityLogProps>;
8
34
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"PaidActivityLog.d.ts","sourceRoot":"","sources":["../../src/components/PaidActivityLog.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,kCAAkC,CAAC;AAoB1C,UAAU,oBAAoB;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAoH1D,CAAC"}
1
+ {"version":3,"file":"PaidActivityLog.d.ts","sourceRoot":"","sources":["../../src/components/Pa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client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useEffect, useState } from 'react';
4
+ import { useIsInContainer } from './PaidContainer';
4
5
  import '../styles/activity-log-table.css';
5
- export const PaidActivityLog = ({ accountExternalId, host }) => {
6
+ export const PaidActivityLog = ({ accountExternalId, paidStyle = {} }) => {
6
7
  const [usageSummaries, setUsageSummaries] = useState([]);
7
8
  const [loading, setLoading] = useState(true);
8
9
  const [error, setError] = useState(null);
9
- const [showAll, setShowAll] = useState(false);
10
+ const isInContainer = useIsInContainer();
11
+ // Convert paidStyle entries into CSS custom properties
12
+ const cssVariables = Object.entries(paidStyle).reduce((vars, [key, value]) => {
13
+ let varName;
14
+ if (key.startsWith('--')) {
15
+ varName = key;
16
+ }
17
+ else {
18
+ const raw = key.replace(/([A-Z])/g, '-$1').toLowerCase();
19
+ varName = raw.startsWith('--') ? raw : `--${raw}`;
20
+ }
21
+ // @ts-ignore allow custom property
22
+ vars[varName] = value;
23
+ return vars;
24
+ }, {});
10
25
  const formatCurrency = (amount) => {
11
26
  return new Intl.NumberFormat("en-US", {
12
27
  style: "currency",
@@ -32,9 +47,17 @@ export const PaidActivityLog = ({ accountExternalId, host }) => {
32
47
  const fetchUsageData = async () => {
33
48
  try {
34
49
  setLoading(true);
50
+ // TEMPORARILY DISABLED: Use cached fetch for usage data
51
+ // const cacheKey = getCacheKey.usage(accountExternalId);
52
+ // const data = await cachedFetch<UsageApiResponse>(
53
+ // `/api/usage/${accountExternalId}`,
54
+ // cacheKey,
55
+ // CACHE_TTL.DATA
56
+ // );
57
+ // Direct fetch without caching
35
58
  const response = await fetch(`/api/usage/${accountExternalId}`);
36
59
  if (!response.ok) {
37
- throw new Error('Failed to fetch usage data');
60
+ throw new Error(`Failed to fetch: ${response.statusText}`);
38
61
  }
39
62
  const data = await response.json();
40
63
  const mappedUsageSummaries = (data.data.usageSummary || []).map((summary) => ({
@@ -52,14 +75,13 @@ export const PaidActivityLog = ({ accountExternalId, host }) => {
52
75
  };
53
76
  fetchUsageData();
54
77
  }, [accountExternalId]);
55
- const displayedSummaries = showAll ? usageSummaries : usageSummaries.slice(0, 4);
56
- const hasMoreSummaries = usageSummaries.length > 4;
78
+ const displayedSummaries = usageSummaries;
57
79
  if (loading) {
58
80
  return _jsx("div", { children: "Loading usage data..." });
59
81
  }
60
82
  if (error) {
61
83
  return _jsxs("div", { children: ["Error: ", error] });
62
84
  }
63
- return (_jsx("div", { className: "paid-activity-log-container", style: { position: 'relative', minWidth: 0 }, children: _jsxs("div", { className: "paid-activity-log-table-wrapper", style: { position: 'static', width: '100%', height: 'auto', left: undefined, top: undefined, boxShadow: undefined, cursor: undefined }, children: [_jsxs("div", { className: "paid-activity-log-header", children: [_jsx("h3", { className: "paid-activity-log-title", children: "Paid.ai Activity Log" }), hasMoreSummaries && (_jsx("button", { onClick: () => setShowAll(!showAll), className: "paid-activity-log-toggle-btn", children: showAll ? 'Show less' : 'Show all usage' }))] }), _jsx("div", { style: { background: '#fff', overflow: 'auto' }, children: _jsxs("table", { className: "paid-activity-log-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: "Event" }), _jsx("th", { children: "Start Date" }), _jsx("th", { children: "End Date" }), _jsx("th", { style: { textAlign: 'center' }, children: "Current Usage" }), _jsx("th", { style: { textAlign: 'center' }, children: "Total" })] }) }), _jsx("tbody", { children: displayedSummaries.length === 0 ? (_jsx("tr", { children: _jsx("td", { colSpan: 5, className: "paid-activity-log-empty", children: "No usage data found" }) })) : (displayedSummaries.map((summary) => (_jsxs("tr", { children: [_jsx("td", { style: { fontWeight: 500 }, children: formatEventName(summary.eventName) }), _jsx("td", { children: formatDate(summary.startDate) }), _jsx("td", { children: formatDate(summary.endDate) }), _jsx("td", { style: { textAlign: 'center' }, children: summary.eventsQuantity }), _jsx("td", { style: { textAlign: 'center', fontWeight: 500 }, children: formatCurrency(summary.subtotal) })] }, summary.id)))) })] }) })] }) }));
85
+ return (_jsx("div", { className: "paid-activity-log-container", style: { position: 'relative', minWidth: 0, ...cssVariables }, children: _jsxs("div", { className: "paid-activity-log-table-wrapper", style: { position: 'static', width: '100%', height: 'auto', left: undefined, top: undefined, boxShadow: undefined, cursor: undefined }, children: [!isInContainer && (_jsx("div", { className: "paid-activity-log-header", children: _jsx("h3", { className: "paid-activity-log-title", children: "Paid.ai Activity Log" }) })), _jsx("div", { style: { background: '#fff', overflow: 'auto' }, children: _jsxs("table", { className: "paid-activity-log-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: "Event" }), _jsx("th", { children: "Start Date" }), _jsx("th", { children: "End Date" }), _jsx("th", { style: { textAlign: 'center' }, children: "Current Usage" }), _jsx("th", { style: { textAlign: 'center' }, children: "Total" })] }) }), _jsx("tbody", { children: displayedSummaries.length === 0 ? (_jsx("tr", { children: _jsx("td", { colSpan: 5, className: "paid-activity-log-empty", children: "No usage data found" }) })) : (displayedSummaries.map((summary) => (_jsxs("tr", { children: [_jsx("td", { style: { fontWeight: 500 }, children: formatEventName(summary.eventName) }), _jsx("td", { children: formatDate(summary.startDate) }), _jsx("td", { children: formatDate(summary.endDate) }), _jsx("td", { style: { textAlign: 'center' }, children: summary.eventsQuantity }), _jsx("td", { style: { textAlign: 'center', fontWeight: 500 }, children: formatCurrency(summary.subtotal) })] }, summary.id)))) })] }) })] }) }));
64
86
  };
65
87
  //# sourceMappingURL=PaidActivityLog.js.map