@agentpaid/paid-nextjs-client 0.3.0-test.2 → 0.3.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.
- package/README.md +184 -79
- package/dist/api/api/handleBlocks.ts +144 -0
- package/dist/api/handleBlocks.d.ts +9 -0
- package/dist/api/handleBlocks.d.ts.map +1 -0
- package/dist/api/handleBlocks.js +107 -0
- package/dist/api/handleBlocks.js.map +1 -0
- package/dist/components/PaidActivityLog.d.ts +13 -26
- package/dist/components/PaidActivityLog.d.ts.map +1 -1
- package/dist/components/PaidActivityLog.js +70 -26
- package/dist/components/PaidActivityLog.js.map +1 -1
- package/dist/components/PaidContainer.d.ts +11 -24
- package/dist/components/PaidContainer.d.ts.map +1 -1
- package/dist/components/PaidContainer.js +18 -9
- package/dist/components/PaidContainer.js.map +1 -1
- package/dist/components/PaidInvoiceTable.d.ts +12 -25
- package/dist/components/PaidInvoiceTable.d.ts.map +1 -1
- package/dist/components/PaidInvoiceTable.js +78 -30
- package/dist/components/PaidInvoiceTable.js.map +1 -1
- package/dist/components/PaidPaymentsTable.d.ts +12 -25
- package/dist/components/PaidPaymentsTable.d.ts.map +1 -1
- package/dist/components/PaidPaymentsTable.js +63 -29
- package/dist/components/PaidPaymentsTable.js.map +1 -1
- package/dist/components/components/PaidActivityLog.js +115 -58
- package/dist/components/components/PaidContainer.js +42 -32
- package/dist/components/components/PaidInvoiceTable.js +126 -89
- package/dist/components/components/PaidPaymentsTable.js +111 -72
- package/dist/components/components/ui/Pagination.js +168 -0
- package/dist/components/ui/Pagination.d.ts +10 -0
- package/dist/components/ui/Pagination.d.ts.map +1 -0
- package/dist/components/ui/Pagination.js +111 -0
- package/dist/components/ui/Pagination.js.map +1 -0
- package/dist/hooks/useCache.d.ts +2 -2
- package/dist/hooks/useCache.d.ts.map +1 -1
- package/dist/hooks/useCache.js +10 -17
- package/dist/hooks/useCache.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/styles/paid-activity-log.css +154 -0
- package/dist/styles/paid-container.css +25 -16
- package/dist/styles/paid-invoice-table.css +135 -120
- package/dist/styles/paid-payments-table.css +65 -109
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/apiClient.d.ts +17 -0
- package/dist/utils/apiClient.d.ts.map +1 -0
- package/dist/utils/apiClient.js +60 -0
- package/dist/utils/apiClient.js.map +1 -0
- package/dist/utils/cache.js +1 -1
- package/dist/utils/cache.js.map +1 -1
- package/package.json +1 -1
- package/dist/api/api/handlePaidInvoicePdf.ts +0 -79
- package/dist/api/api/handlePaidInvoices.ts +0 -77
- package/dist/api/api/handlePaidPayments.ts +0 -77
- package/dist/api/api/handlePaidUsage.ts +0 -52
- package/dist/api/handlePaidInvoicePdf.d.ts +0 -6
- package/dist/api/handlePaidInvoicePdf.d.ts.map +0 -1
- package/dist/api/handlePaidInvoicePdf.js +0 -60
- package/dist/api/handlePaidInvoicePdf.js.map +0 -1
- package/dist/api/handlePaidInvoices.d.ts +0 -6
- package/dist/api/handlePaidInvoices.d.ts.map +0 -1
- package/dist/api/handlePaidInvoices.js +0 -56
- package/dist/api/handlePaidInvoices.js.map +0 -1
- package/dist/api/handlePaidPayments.d.ts +0 -6
- package/dist/api/handlePaidPayments.d.ts.map +0 -1
- package/dist/api/handlePaidPayments.js +0 -56
- package/dist/api/handlePaidPayments.js.map +0 -1
- package/dist/api/handlePaidUsage.d.ts +0 -6
- package/dist/api/handlePaidUsage.d.ts.map +0 -1
- package/dist/api/handlePaidUsage.js +0 -35
- package/dist/api/handlePaidUsage.js.map +0 -1
- package/dist/styles/activity-log-table.css +0 -138
package/README.md
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
# Paid
|
1
|
+
# Paid.ai Blocks
|
2
2
|
|
3
|
-
Easily embed
|
3
|
+
Easily embed Paid.ai blocks in your Next.js app to display payments, invoices, and activity logs for specific customers.
|
4
4
|
|
5
|
-
|
5
|
+
## Quick Setup
|
6
6
|
|
7
|
-
|
7
|
+
1. **Install**: `npm install @agentpaid/paid-nextjs-client`
|
8
|
+
2. **Add API key**: Set `PAID_API_KEY` in your `.env.local`
|
9
|
+
3. **Create one API route**: `src/app/api/[paidEndpoint]/[...params]/route.ts`
|
10
|
+
4. **Use components**: Import and use `PaidContainer` or individual blocks
|
8
11
|
|
9
|
-
|
10
|
-
- Designed for Next.js 13+ (App Router).
|
11
|
-
- Fetches usage data for a given account using your API key.
|
12
|
-
- Fully customizable and responsive.
|
12
|
+
That's it! No complex configuration needed.
|
13
13
|
|
14
14
|
---
|
15
15
|
|
@@ -23,68 +23,160 @@ yarn add @agentpaid/paid-nextjs-client
|
|
23
23
|
|
24
24
|
---
|
25
25
|
|
26
|
-
##
|
26
|
+
## Blocks
|
27
|
+
|
28
|
+
### PaidContainer (Recommended)
|
27
29
|
|
28
|
-
|
30
|
+
The `PaidContainer` is an all-in-one tabbed interface that displays payments, invoices, and activity logs in a single block. This is the easiest way to integrate all Paid.ai data views.
|
29
31
|
|
30
32
|
```tsx
|
31
|
-
import {
|
33
|
+
import {
|
34
|
+
PaidContainer,
|
35
|
+
PaidActivityLog,
|
36
|
+
PaidInvoiceTable,
|
37
|
+
PaidPaymentsTable
|
38
|
+
} from '@agentpaid/paid-nextjs-client';
|
39
|
+
|
40
|
+
<PaidContainer
|
41
|
+
title="Customer Overview"
|
42
|
+
description="Here's a breakdown of recent activity for your customer."
|
43
|
+
defaultActiveTab="payments"
|
44
|
+
tabs={[
|
45
|
+
{
|
46
|
+
id: 'payments',
|
47
|
+
label: 'Payments',
|
48
|
+
component: <PaidPaymentsTable customerExternalId="customer_123" />
|
49
|
+
},
|
50
|
+
{
|
51
|
+
id: 'invoices',
|
52
|
+
label: 'Invoices',
|
53
|
+
component: <PaidInvoiceTable customerExternalId="customer_123" />
|
54
|
+
},
|
55
|
+
{
|
56
|
+
id: 'activity-log',
|
57
|
+
label: 'Activity Log',
|
58
|
+
component: <PaidActivityLog customerExternalId="customer_123" />
|
59
|
+
}
|
60
|
+
]}
|
61
|
+
paidStyle={{
|
62
|
+
fontFamily: 'Inter',
|
63
|
+
primaryColor: '#1f2937',
|
64
|
+
containerBackgroundColor: '#f8fafc',
|
65
|
+
buttonBgColor: '#3b82f6'
|
66
|
+
}}
|
67
|
+
/>
|
32
68
|
```
|
33
69
|
|
34
|
-
|
70
|
+
### Individual Blocks
|
71
|
+
|
72
|
+
For more granular control, you can use individual blocks:
|
35
73
|
|
36
74
|
```tsx
|
37
|
-
|
38
|
-
|
75
|
+
import {
|
76
|
+
PaidPaymentsTable,
|
77
|
+
PaidInvoiceTable,
|
78
|
+
PaidActivityLog
|
79
|
+
} from '@agentpaid/paid-nextjs-client';
|
39
80
|
|
40
|
-
|
81
|
+
// Payments only
|
82
|
+
<PaidPaymentsTable customerExternalId="customer_123" />
|
41
83
|
|
42
|
-
|
84
|
+
// Invoices only
|
85
|
+
<PaidInvoiceTable customerExternalId="customer_123" />
|
86
|
+
|
87
|
+
// Activity log only
|
88
|
+
<PaidActivityLog customerExternalId="customer_123" />
|
89
|
+
```
|
43
90
|
|
44
|
-
|
91
|
+
---
|
45
92
|
|
46
|
-
|
93
|
+
## API Routes Setup
|
47
94
|
|
48
|
-
|
95
|
+
You need to create a single API route to handle all Paid.ai endpoints. **First, add your Paid.ai API key to `.env.local`:**
|
49
96
|
|
50
97
|
```env
|
51
98
|
PAID_API_KEY=your_paid_ai_api_key_here
|
52
99
|
```
|
53
100
|
|
54
|
-
|
101
|
+
### Single Unified API Route
|
102
|
+
|
103
|
+
Create one API route that handles all four endpoints:
|
55
104
|
|
56
105
|
```bash
|
57
|
-
mkdir -p "src/app/api/
|
106
|
+
mkdir -p "src/app/api/[paidEndpoint]/[...params]" && touch "src/app/api/[paidEndpoint]/[...params]/route.ts"
|
58
107
|
```
|
59
108
|
|
60
|
-
|
61
|
-
|
109
|
+
Add to `src/app/api/[paidEndpoint]/[...params]/route.ts`:
|
62
110
|
```ts
|
63
|
-
import {
|
111
|
+
import { handleBlocks } from '@agentpaid/paid-nextjs-client';
|
64
112
|
|
65
|
-
export const GET =
|
113
|
+
export const GET = handleBlocks();
|
66
114
|
```
|
67
115
|
|
68
|
-
This will securely proxy usage requests to Paid.ai using your API key from environment variables.
|
69
|
-
|
70
116
|
---
|
71
117
|
|
72
|
-
## Example
|
118
|
+
## Complete Example
|
73
119
|
|
74
120
|
```tsx
|
75
|
-
import {
|
76
|
-
|
77
|
-
|
121
|
+
import {
|
122
|
+
PaidContainer,
|
123
|
+
PaidActivityLog,
|
124
|
+
PaidInvoiceTable,
|
125
|
+
PaidPaymentsTable
|
126
|
+
} from '@agentpaid/paid-nextjs-client';
|
127
|
+
|
128
|
+
export default function CustomerDashboard() {
|
78
129
|
return (
|
79
130
|
<div style={{ padding: '2rem', fontFamily: 'sans-serif' }}>
|
80
|
-
<h1>
|
131
|
+
<h1>Customer Dashboard</h1>
|
81
132
|
|
82
133
|
<section style={{ marginBottom: '2rem' }}>
|
83
134
|
<p><strong>Welcome back!</strong></p>
|
84
|
-
<p>Here
|
135
|
+
<p>Here's a complete overview for customer <code>customer_123</code>.</p>
|
85
136
|
</section>
|
86
137
|
|
87
|
-
<
|
138
|
+
<PaidContainer
|
139
|
+
title="Customer Overview"
|
140
|
+
description="Complete breakdown of payments, invoices, and activity."
|
141
|
+
defaultActiveTab="payments"
|
142
|
+
tabs={[
|
143
|
+
{
|
144
|
+
id: 'payments',
|
145
|
+
label: 'Payments',
|
146
|
+
component: <PaidPaymentsTable customerExternalId="customer_123" />
|
147
|
+
},
|
148
|
+
{
|
149
|
+
id: 'invoices',
|
150
|
+
label: 'Invoices',
|
151
|
+
component: <PaidInvoiceTable customerExternalId="customer_123" />
|
152
|
+
},
|
153
|
+
{
|
154
|
+
id: 'activity-log',
|
155
|
+
label: 'Activity Log',
|
156
|
+
component: <PaidActivityLog customerExternalId="customer_123" />
|
157
|
+
}
|
158
|
+
]}
|
159
|
+
paidStyle={{
|
160
|
+
// Global styling
|
161
|
+
fontFamily: 'Inter, sans-serif',
|
162
|
+
primaryColor: '#1f2937',
|
163
|
+
secondaryColor: '#6b7280',
|
164
|
+
|
165
|
+
// Container & backgrounds
|
166
|
+
containerBackgroundColor: '#f8fafc',
|
167
|
+
tableBackgroundColor: '#ffffff',
|
168
|
+
tableHeaderBackgroundColor: '#f1f5f9',
|
169
|
+
|
170
|
+
// Tabs
|
171
|
+
tabBackgroundColor: '#e2e8f0',
|
172
|
+
tabActiveBackgroundColor: '#3b82f6',
|
173
|
+
tabHoverBackgroundColor: '#cbd5e1',
|
174
|
+
|
175
|
+
// Interactive elements
|
176
|
+
tableHoverColor: '#f1f5f9',
|
177
|
+
buttonBgColor: '#3b82f6'
|
178
|
+
}}
|
179
|
+
/>
|
88
180
|
|
89
181
|
<section style={{ marginTop: '2rem' }}>
|
90
182
|
<p>Need help? Visit our <a href="/support">support center</a>.</p>
|
@@ -96,58 +188,71 @@ export default function AgentDashboard() {
|
|
96
188
|
|
97
189
|
---
|
98
190
|
|
99
|
-
## Styling
|
191
|
+
## Styling System
|
192
|
+
|
193
|
+
The Paid.ai blocks use a simplified, universal styling system. All blocks accept a `paidStyle` prop with the following properties:
|
194
|
+
|
195
|
+
### Universal Style Properties
|
196
|
+
|
197
|
+
| Property | Description | Default |
|
198
|
+
|----------|-------------|---------|
|
199
|
+
| `fontFamily` | Global font family for all text | `'Roboto'` |
|
200
|
+
| `primaryColor` | Primary text color | `'#374151'` |
|
201
|
+
| `secondaryColor` | Secondary text color | `'#6b7280'` |
|
202
|
+
| `containerBackgroundColor` | Main container background | `'#f8f9fa'` |
|
203
|
+
| `tableBackgroundColor` | Table body background | `'#ffffff'` |
|
204
|
+
| `tableHeaderBackgroundColor` | Table header background | `'#f9fafb'` |
|
205
|
+
| `tabBackgroundColor` | Tab background (PaidContainer only) | `'#e2e8f0'` |
|
206
|
+
| `tabActiveBackgroundColor` | Active tab background | `'#3b82f6'` |
|
207
|
+
| `tabHoverBackgroundColor` | Tab hover background | `'#cbd5e1'` |
|
208
|
+
| `tableHoverColor` | Table row hover background | `'#f3f4f6'` |
|
209
|
+
| `buttonBgColor` | Background for buttons, status badges, and pagination | `'#ffffff'` |
|
100
210
|
|
101
|
-
|
211
|
+
### Styling Inheritance
|
102
212
|
|
103
|
-
|
213
|
+
- **PaidContainer**: Styles applied here automatically inherit to all child blocks
|
214
|
+
- **Individual Blocks**: Can override inherited styles or define their own when used standalone
|
215
|
+
- **Flexible**: Mix and match - style globally via PaidContainer or individually per block
|
104
216
|
|
105
|
-
|
217
|
+
### Example: Dark Theme
|
106
218
|
|
107
|
-
```
|
108
|
-
<
|
109
|
-
|
219
|
+
```tsx
|
220
|
+
<PaidContainer
|
221
|
+
title="Customer Overview"
|
222
|
+
description="Dark theme example"
|
223
|
+
defaultActiveTab="payments"
|
224
|
+
tabs={[
|
225
|
+
{
|
226
|
+
id: 'payments',
|
227
|
+
label: 'Payments',
|
228
|
+
component: <PaidPaymentsTable customerExternalId="customer_123" />
|
229
|
+
}
|
230
|
+
]}
|
110
231
|
paidStyle={{
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
232
|
+
fontFamily: 'Inter',
|
233
|
+
primaryColor: '#f9fafb',
|
234
|
+
secondaryColor: '#d1d5db',
|
235
|
+
containerBackgroundColor: '#1f2937',
|
236
|
+
tableBackgroundColor: '#374151',
|
237
|
+
tableHeaderBackgroundColor: '#4b5563',
|
238
|
+
tabBackgroundColor: '#4b5563',
|
239
|
+
tabActiveBackgroundColor: '#3b82f6',
|
240
|
+
tabHoverBackgroundColor: '#6b7280',
|
241
|
+
tableHoverColor: '#4b5563',
|
242
|
+
buttonBgColor: '#6b7280'
|
121
243
|
}}
|
122
244
|
/>
|
123
245
|
```
|
124
246
|
|
125
|
-
|
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 |
|
247
|
+
### Example: Individual Block Styling
|
153
248
|
|
249
|
+
```tsx
|
250
|
+
<PaidPaymentsTable
|
251
|
+
customerExternalId="customer_123"
|
252
|
+
paidStyle={{
|
253
|
+
primaryColor: '#dc2626',
|
254
|
+
buttonBgColor: '#fef2f2',
|
255
|
+
tableHoverColor: '#fee2e2'
|
256
|
+
}}
|
257
|
+
/>
|
258
|
+
```
|
@@ -0,0 +1,144 @@
|
|
1
|
+
type PaidEndpoint = 'invoices' | 'payments' | 'invoice-pdf' | 'usage';
|
2
|
+
|
3
|
+
interface Params {
|
4
|
+
paidEndpoint: string;
|
5
|
+
params: string[];
|
6
|
+
}
|
7
|
+
|
8
|
+
export function handleBlocks(apiBase?: string) {
|
9
|
+
return async function GET(
|
10
|
+
_request: Request,
|
11
|
+
{ params }: { params: Params }
|
12
|
+
) {
|
13
|
+
try {
|
14
|
+
const apiKey = process.env.PAID_API_KEY;
|
15
|
+
|
16
|
+
if (!apiKey) {
|
17
|
+
console.log('handlePaidUnified - No API key found in environment variables');
|
18
|
+
return new Response(
|
19
|
+
JSON.stringify({ error: 'API key not configured. Please set PAID_API_KEY environment variable.' }),
|
20
|
+
{
|
21
|
+
status: 500,
|
22
|
+
headers: { 'Content-Type': 'application/json' }
|
23
|
+
}
|
24
|
+
);
|
25
|
+
}
|
26
|
+
|
27
|
+
if (!apiBase) {
|
28
|
+
apiBase = 'https://api.agentpaid.io';
|
29
|
+
}
|
30
|
+
|
31
|
+
const paidEndpoint = params.paidEndpoint as PaidEndpoint;
|
32
|
+
const routeParams = params.params || [];
|
33
|
+
|
34
|
+
let customerExternalId: string | undefined;
|
35
|
+
let invoiceId: string | undefined;
|
36
|
+
|
37
|
+
if (paidEndpoint === 'invoice-pdf') {
|
38
|
+
invoiceId = routeParams[0];
|
39
|
+
} else {
|
40
|
+
customerExternalId = routeParams[0];
|
41
|
+
}
|
42
|
+
|
43
|
+
if ((paidEndpoint === 'invoices' || paidEndpoint === 'payments' || paidEndpoint === 'usage') && !customerExternalId) {
|
44
|
+
return new Response(
|
45
|
+
JSON.stringify({ error: 'customerExternalId is required for this endpoint' }),
|
46
|
+
{
|
47
|
+
status: 400,
|
48
|
+
headers: { 'Content-Type': 'application/json' }
|
49
|
+
}
|
50
|
+
);
|
51
|
+
}
|
52
|
+
|
53
|
+
if (paidEndpoint === 'invoice-pdf' && !invoiceId) {
|
54
|
+
return new Response(
|
55
|
+
JSON.stringify({ error: 'invoiceId is required for invoice PDF endpoint' }),
|
56
|
+
{
|
57
|
+
status: 400,
|
58
|
+
headers: { 'Content-Type': 'application/json' }
|
59
|
+
}
|
60
|
+
);
|
61
|
+
}
|
62
|
+
|
63
|
+
let url: string;
|
64
|
+
switch (paidEndpoint) {
|
65
|
+
case 'invoices':
|
66
|
+
url = `${apiBase}/api/organizations/org/customer/external/${customerExternalId}/invoices`;
|
67
|
+
break;
|
68
|
+
case 'payments':
|
69
|
+
url = `${apiBase}/api/organizations/org/customer/external/${customerExternalId}/payments`;
|
70
|
+
break;
|
71
|
+
case 'invoice-pdf':
|
72
|
+
url = `${apiBase}/api/organizations/org/invoices/${invoiceId}/pdf`;
|
73
|
+
break;
|
74
|
+
case 'usage':
|
75
|
+
url = `${apiBase}/api/organizations/org/customer/external/${customerExternalId}`;
|
76
|
+
break;
|
77
|
+
default:
|
78
|
+
return new Response(
|
79
|
+
JSON.stringify({ error: `Unknown endpoint: ${paidEndpoint}` }),
|
80
|
+
{
|
81
|
+
status: 400,
|
82
|
+
headers: { 'Content-Type': 'application/json' }
|
83
|
+
}
|
84
|
+
);
|
85
|
+
}
|
86
|
+
|
87
|
+
const response = await fetch(url, {
|
88
|
+
headers: {
|
89
|
+
'Authorization': `Bearer ${apiKey}`,
|
90
|
+
},
|
91
|
+
});
|
92
|
+
|
93
|
+
if (!response.ok) {
|
94
|
+
let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
|
95
|
+
try {
|
96
|
+
const errorData = await response.json();
|
97
|
+
errorMessage = errorData.error || errorData.message || errorMessage;
|
98
|
+
} catch (parseError) {
|
99
|
+
if (paidEndpoint === 'invoice-pdf') {
|
100
|
+
try {
|
101
|
+
const errorText = await response.text();
|
102
|
+
if (errorText) {
|
103
|
+
errorMessage = errorText;
|
104
|
+
}
|
105
|
+
} catch (textError) {
|
106
|
+
console.log(`handlePaidUnified - Could not parse error response for ${paidEndpoint}`);
|
107
|
+
}
|
108
|
+
} else {
|
109
|
+
console.log(`handlePaidUnified - Could not parse error response as JSON for ${paidEndpoint}`);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
return new Response(
|
114
|
+
JSON.stringify({ error: errorMessage }),
|
115
|
+
{
|
116
|
+
status: response.status,
|
117
|
+
headers: { 'Content-Type': 'application/json' }
|
118
|
+
}
|
119
|
+
);
|
120
|
+
}
|
121
|
+
|
122
|
+
const data = await response.json();
|
123
|
+
return new Response(
|
124
|
+
JSON.stringify(data),
|
125
|
+
{
|
126
|
+
status: 200,
|
127
|
+
headers: { 'Content-Type': 'application/json' }
|
128
|
+
}
|
129
|
+
);
|
130
|
+
} catch (error) {
|
131
|
+
console.error(`Error in handlePaidUnified for ${params.paidEndpoint}:`, error);
|
132
|
+
return new Response(
|
133
|
+
JSON.stringify({
|
134
|
+
error: `Failed to fetch ${params.paidEndpoint} data`,
|
135
|
+
details: error instanceof Error ? error.message : String(error)
|
136
|
+
}),
|
137
|
+
{
|
138
|
+
status: 500,
|
139
|
+
headers: { 'Content-Type': 'application/json' }
|
140
|
+
}
|
141
|
+
);
|
142
|
+
}
|
143
|
+
};
|
144
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"handleBlocks.d.ts","sourceRoot":"","sources":["../../src/api/handleBlocks.ts"],"names":[],"mappings":"AAEA,UAAU,MAAM;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,MAAM,cAE/B,OAAO;YACK,MAAM;wBAqI/B"}
|
@@ -0,0 +1,107 @@
|
|
1
|
+
export function handleBlocks(apiBase) {
|
2
|
+
return async function GET(_request, { params }) {
|
3
|
+
try {
|
4
|
+
const apiKey = process.env.PAID_API_KEY;
|
5
|
+
if (!apiKey) {
|
6
|
+
console.log('handlePaidUnified - No API key found in environment variables');
|
7
|
+
return new Response(JSON.stringify({ error: 'API key not configured. Please set PAID_API_KEY environment variable.' }), {
|
8
|
+
status: 500,
|
9
|
+
headers: { 'Content-Type': 'application/json' }
|
10
|
+
});
|
11
|
+
}
|
12
|
+
if (!apiBase) {
|
13
|
+
apiBase = 'https://api.agentpaid.io';
|
14
|
+
}
|
15
|
+
const paidEndpoint = params.paidEndpoint;
|
16
|
+
const routeParams = params.params || [];
|
17
|
+
let customerExternalId;
|
18
|
+
let invoiceId;
|
19
|
+
if (paidEndpoint === 'invoice-pdf') {
|
20
|
+
invoiceId = routeParams[0];
|
21
|
+
}
|
22
|
+
else {
|
23
|
+
customerExternalId = routeParams[0];
|
24
|
+
}
|
25
|
+
if ((paidEndpoint === 'invoices' || paidEndpoint === 'payments' || paidEndpoint === 'usage') && !customerExternalId) {
|
26
|
+
return new Response(JSON.stringify({ error: 'customerExternalId is required for this endpoint' }), {
|
27
|
+
status: 400,
|
28
|
+
headers: { 'Content-Type': 'application/json' }
|
29
|
+
});
|
30
|
+
}
|
31
|
+
if (paidEndpoint === 'invoice-pdf' && !invoiceId) {
|
32
|
+
return new Response(JSON.stringify({ error: 'invoiceId is required for invoice PDF endpoint' }), {
|
33
|
+
status: 400,
|
34
|
+
headers: { 'Content-Type': 'application/json' }
|
35
|
+
});
|
36
|
+
}
|
37
|
+
let url;
|
38
|
+
switch (paidEndpoint) {
|
39
|
+
case 'invoices':
|
40
|
+
url = `${apiBase}/api/organizations/org/customer/external/${customerExternalId}/invoices`;
|
41
|
+
break;
|
42
|
+
case 'payments':
|
43
|
+
url = `${apiBase}/api/organizations/org/customer/external/${customerExternalId}/payments`;
|
44
|
+
break;
|
45
|
+
case 'invoice-pdf':
|
46
|
+
url = `${apiBase}/api/organizations/org/invoices/${invoiceId}/pdf`;
|
47
|
+
break;
|
48
|
+
case 'usage':
|
49
|
+
url = `${apiBase}/api/organizations/org/customer/external/${customerExternalId}`;
|
50
|
+
break;
|
51
|
+
default:
|
52
|
+
return new Response(JSON.stringify({ error: `Unknown endpoint: ${paidEndpoint}` }), {
|
53
|
+
status: 400,
|
54
|
+
headers: { 'Content-Type': 'application/json' }
|
55
|
+
});
|
56
|
+
}
|
57
|
+
const response = await fetch(url, {
|
58
|
+
headers: {
|
59
|
+
'Authorization': `Bearer ${apiKey}`,
|
60
|
+
},
|
61
|
+
});
|
62
|
+
if (!response.ok) {
|
63
|
+
let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
|
64
|
+
try {
|
65
|
+
const errorData = await response.json();
|
66
|
+
errorMessage = errorData.error || errorData.message || errorMessage;
|
67
|
+
}
|
68
|
+
catch (parseError) {
|
69
|
+
if (paidEndpoint === 'invoice-pdf') {
|
70
|
+
try {
|
71
|
+
const errorText = await response.text();
|
72
|
+
if (errorText) {
|
73
|
+
errorMessage = errorText;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
catch (textError) {
|
77
|
+
console.log(`handlePaidUnified - Could not parse error response for ${paidEndpoint}`);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
else {
|
81
|
+
console.log(`handlePaidUnified - Could not parse error response as JSON for ${paidEndpoint}`);
|
82
|
+
}
|
83
|
+
}
|
84
|
+
return new Response(JSON.stringify({ error: errorMessage }), {
|
85
|
+
status: response.status,
|
86
|
+
headers: { 'Content-Type': 'application/json' }
|
87
|
+
});
|
88
|
+
}
|
89
|
+
const data = await response.json();
|
90
|
+
return new Response(JSON.stringify(data), {
|
91
|
+
status: 200,
|
92
|
+
headers: { 'Content-Type': 'application/json' }
|
93
|
+
});
|
94
|
+
}
|
95
|
+
catch (error) {
|
96
|
+
console.error(`Error in handlePaidUnified for ${params.paidEndpoint}:`, error);
|
97
|
+
return new Response(JSON.stringify({
|
98
|
+
error: `Failed to fetch ${params.paidEndpoint} data`,
|
99
|
+
details: error instanceof Error ? error.message : String(error)
|
100
|
+
}), {
|
101
|
+
status: 500,
|
102
|
+
headers: { 'Content-Type': 'application/json' }
|
103
|
+
});
|
104
|
+
}
|
105
|
+
};
|
106
|
+
}
|
107
|
+
//# sourceMappingURL=handleBlocks.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"handleBlocks.js","sourceRoot":"","sources":["../../src/api/handleBlocks.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,YAAY,CAAC,OAAgB;IAC3C,OAAO,KAAK,UAAU,GAAG,CACvB,QAAiB,EACjB,EAAE,MAAM,EAAsB;QAE9B,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;YAExC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO,CAAC,GAAG,CAAC,+DAA+D,CAAC,CAAC;gBAC7E,OAAO,IAAI,QAAQ,CACjB,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,uEAAuE,EAAE,CAAC,EAClG;oBACE,MAAM,EAAE,GAAG;oBACX,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;iBAChD,CACF,CAAC;YACJ,CAAC;YAED,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,OAAO,GAAG,0BAA0B,CAAC;YACvC,CAAC;YAED,MAAM,YAAY,GAAG,MAAM,CAAC,YAA4B,CAAC;YACzD,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;YAExC,IAAI,kBAAsC,CAAC;YAC3C,IAAI,SAA6B,CAAC;YAElC,IAAI,YAAY,KAAK,aAAa,EAAE,CAAC;gBACnC,SAAS,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;YAC7B,CAAC;iBAAM,CAAC;gBACN,kBAAkB,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;YACtC,CAAC;YAED,IAAI,CAAC,YAAY,KAAK,UAAU,I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MAAM,EAAE,GAAG;gBACX,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;aAChD,CACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,kCAAkC,MAAM,CAAC,YAAY,GAAG,EAAE,KAAK,CAAC,CAAC;YAC/E,OAAO,IAAI,QAAQ,CACjB,IAAI,CAAC,SAAS,CAAC;gBACb,KAAK,EAAE,mBAAmB,MAAM,CAAC,YAAY,OAAO;gBACpD,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAChE,CAAC,EACF;gBACE,MAAM,EAAE,GAAG;gBACX,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;aAChD,CACF,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
@@ -1,33 +1,20 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
import '../styles/activity-log
|
2
|
+
import '../styles/paid-activity-log.css';
|
3
3
|
interface PaidStyleProperties {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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;
|
4
|
+
fontFamily?: string;
|
5
|
+
primaryColor?: string;
|
6
|
+
secondaryColor?: string;
|
7
|
+
containerBackgroundColor?: string;
|
8
|
+
tableBackgroundColor?: string;
|
9
|
+
tableHeaderBackgroundColor?: string;
|
10
|
+
tabBackgroundColor?: string;
|
11
|
+
tabActiveBackgroundColor?: string;
|
12
|
+
tabHoverBackgroundColor?: string;
|
13
|
+
tableHoverColor?: string;
|
14
|
+
buttonBgColor?: string;
|
28
15
|
}
|
29
16
|
interface PaidActivityLogProps {
|
30
|
-
|
17
|
+
customerExternalId: string;
|
31
18
|
paidStyle?: PaidStyleProperties;
|
32
19
|
}
|
33
20
|
export declare const PaidActivityLog: React.FC<PaidActivityLogProps>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"PaidActivityLog.d.ts","sourceRoot":"","sources":["../../src/components/PaidActivityLog.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA8B,MAAM,OAAO,CAAC;
|
1
|
+
{"version":3,"file":"PaidActivityLog.d.ts","sourceRoot":"","sources":["../../src/components/PaidActivityLog.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAInD,OAAO,iCAAiC,CAAC;AAEzC,UAAU,mBAAmB;IAEzB,UAAU,CAAC,EAAE,MAAM,CAAC;IAGpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IAGxB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,0BAA0B,CAAC,EAAE,MAAM,CAAC;IAGpC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IAGjC,eAAe,CAAC,EAAE,MAAM,CAAC;IAGzB,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B;AA2BD,UAAU,oBAAoB;IAC1B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,mBAAmB,CAAC;CACnC;AAED,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CA+L1D,CAAC"}
|