@paykit-sdk/polar 1.1.99 → 1.2.0
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 +38 -10
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +337 -4307
- package/dist/index.mjs +338 -4308
- package/dist/polar-provider.d.mts +14 -9
- package/dist/polar-provider.d.ts +14 -9
- package/dist/polar-provider.js +336 -4306
- package/dist/polar-provider.mjs +337 -4307
- package/package.json +11 -9
package/README.md
CHANGED
|
@@ -33,11 +33,15 @@ export async function POST(
|
|
|
33
33
|
) {
|
|
34
34
|
try {
|
|
35
35
|
// Construct the endpoint path with full type safety
|
|
36
|
-
const endpoint = ('/' +
|
|
36
|
+
const endpoint = ('/' +
|
|
37
|
+
params.endpoint.join('/')) as EndpointPath;
|
|
37
38
|
const handler = endpoints[endpoint];
|
|
38
39
|
|
|
39
40
|
if (!handler) {
|
|
40
|
-
return NextResponse.json(
|
|
41
|
+
return NextResponse.json(
|
|
42
|
+
{ message: 'Endpoint not found' },
|
|
43
|
+
{ status: 404 },
|
|
44
|
+
);
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
// Parse request body
|
|
@@ -50,7 +54,12 @@ export async function POST(
|
|
|
50
54
|
} catch (error) {
|
|
51
55
|
console.error('PayKit API Error:', error);
|
|
52
56
|
return NextResponse.json(
|
|
53
|
-
{
|
|
57
|
+
{
|
|
58
|
+
message:
|
|
59
|
+
error instanceof Error
|
|
60
|
+
? error.message
|
|
61
|
+
: 'Internal server error',
|
|
62
|
+
},
|
|
54
63
|
{ status: 500 },
|
|
55
64
|
);
|
|
56
65
|
}
|
|
@@ -67,7 +76,10 @@ export async function POST(request: NextRequest) {
|
|
|
67
76
|
const webhookSecret = process.env.POLAR_WEBHOOK_SECRET;
|
|
68
77
|
|
|
69
78
|
if (!webhookSecret) {
|
|
70
|
-
return NextResponse.json(
|
|
79
|
+
return NextResponse.json(
|
|
80
|
+
{ error: 'Webhook secret not configured' },
|
|
81
|
+
{ status: 500 },
|
|
82
|
+
);
|
|
71
83
|
}
|
|
72
84
|
|
|
73
85
|
const webhook = paykit.webhooks
|
|
@@ -114,7 +126,9 @@ app.post(
|
|
|
114
126
|
const webhookSecret = process.env.POLAR_WEBHOOK_SECRET;
|
|
115
127
|
|
|
116
128
|
if (!webhookSecret) {
|
|
117
|
-
return res
|
|
129
|
+
return res
|
|
130
|
+
.status(500)
|
|
131
|
+
.json({ error: 'Webhook secret not configured' });
|
|
118
132
|
}
|
|
119
133
|
|
|
120
134
|
const webhook = paykit.webhooks
|
|
@@ -132,8 +146,13 @@ app.post(
|
|
|
132
146
|
console.log('Refund created:', event.data);
|
|
133
147
|
});
|
|
134
148
|
|
|
135
|
-
const body =
|
|
136
|
-
|
|
149
|
+
const body =
|
|
150
|
+
typeof req.body === 'string'
|
|
151
|
+
? req.body
|
|
152
|
+
: JSON.stringify(req.body);
|
|
153
|
+
const headers = new Headers(
|
|
154
|
+
Object.entries(req.headers) as [string, string][],
|
|
155
|
+
);
|
|
137
156
|
const fullUrl = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
|
|
138
157
|
|
|
139
158
|
await webhook.handle({ body, headers, fullUrl });
|
|
@@ -142,7 +161,10 @@ app.post(
|
|
|
142
161
|
} catch (error) {
|
|
143
162
|
console.error('Webhook error:', error);
|
|
144
163
|
res.status(500).json({
|
|
145
|
-
message:
|
|
164
|
+
message:
|
|
165
|
+
error instanceof Error
|
|
166
|
+
? error.message
|
|
167
|
+
: 'Webhook processing failed',
|
|
146
168
|
});
|
|
147
169
|
}
|
|
148
170
|
},
|
|
@@ -153,7 +175,10 @@ app.use(express.json());
|
|
|
153
175
|
|
|
154
176
|
app.post('/api/paykit/*', async (req, res) => {
|
|
155
177
|
try {
|
|
156
|
-
const endpoint = req.path.replace(
|
|
178
|
+
const endpoint = req.path.replace(
|
|
179
|
+
'/api/paykit',
|
|
180
|
+
'',
|
|
181
|
+
) as EndpointPath;
|
|
157
182
|
const handler = endpoints[endpoint];
|
|
158
183
|
|
|
159
184
|
if (!handler) {
|
|
@@ -166,7 +191,10 @@ app.post('/api/paykit/*', async (req, res) => {
|
|
|
166
191
|
res.json({ result });
|
|
167
192
|
} catch (error) {
|
|
168
193
|
res.status(500).json({
|
|
169
|
-
message:
|
|
194
|
+
message:
|
|
195
|
+
error instanceof Error
|
|
196
|
+
? error.message
|
|
197
|
+
: 'Internal server error',
|
|
170
198
|
});
|
|
171
199
|
}
|
|
172
200
|
});
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PolarOptions, PolarProvider } from './polar-provider.mjs';
|
|
2
2
|
import '@paykit-sdk/core';
|
|
3
3
|
import '@polar-sh/sdk';
|
|
4
|
+
import '@polar-sh/sdk/webhooks';
|
|
4
5
|
|
|
5
6
|
declare const createPolar: (config: PolarOptions) => PolarProvider;
|
|
6
7
|
declare const polar: () => PolarProvider;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PolarOptions, PolarProvider } from './polar-provider.js';
|
|
2
2
|
import '@paykit-sdk/core';
|
|
3
3
|
import '@polar-sh/sdk';
|
|
4
|
+
import '@polar-sh/sdk/webhooks';
|
|
4
5
|
|
|
5
6
|
declare const createPolar: (config: PolarOptions) => PolarProvider;
|
|
6
7
|
declare const polar: () => PolarProvider;
|