@djangocfg/nextjs 2.1.138 → 2.1.140
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 +1 -138
- package/dist/config/index.mjs +4 -18
- package/dist/config/index.mjs.map +1 -1
- package/dist/i18n/routing.d.mts +4 -4
- package/dist/index.mjs +4 -18
- package/dist/index.mjs.map +1 -1
- package/dist/pwa/index.d.mts +1 -80
- package/dist/pwa/index.mjs +0 -91
- package/dist/pwa/index.mjs.map +1 -1
- package/dist/pwa/worker/index.d.mts +0 -13
- package/dist/pwa/worker/index.mjs +1 -57
- package/dist/pwa/worker/index.mjs.map +1 -1
- package/package.json +11 -25
- package/src/pwa/index.ts +0 -1
- package/src/pwa/worker/index.ts +0 -81
- package/dist/pwa/cli.d.mts +0 -1
- package/dist/pwa/cli.mjs +0 -140
- package/dist/pwa/cli.mjs.map +0 -1
- package/dist/pwa/server/index.d.mts +0 -86
- package/dist/pwa/server/index.mjs +0 -175
- package/dist/pwa/server/index.mjs.map +0 -1
- package/dist/pwa/server/routes.d.mts +0 -2
- package/dist/pwa/server/routes.mjs +0 -149
- package/dist/pwa/server/routes.mjs.map +0 -1
- package/dist/routes-DXA29sS_.d.mts +0 -68
- package/src/pwa/cli.ts +0 -171
- package/src/pwa/notifications.ts +0 -192
- package/src/pwa/server/index.ts +0 -23
- package/src/pwa/server/push.ts +0 -166
- package/src/pwa/server/routes.ts +0 -138
package/src/pwa/server/routes.ts
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ready-to-use Push Notification Route Handlers
|
|
3
|
-
*
|
|
4
|
-
* Import these in your app/api/push/ routes
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
8
|
-
|
|
9
|
-
import { configureVapid, sendPushNotification, validateSubscription } from './push';
|
|
10
|
-
|
|
11
|
-
// In-memory storage для demo (в production используй БД)
|
|
12
|
-
const subscriptions = new Set<string>();
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* POST /api/push/subscribe
|
|
16
|
-
* Save push subscription
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* // app/api/push/subscribe/route.ts
|
|
21
|
-
* export { POST } from '@djangocfg/nextjs/pwa/server/routes';
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export async function handleSubscribe(request: NextRequest) {
|
|
25
|
-
try {
|
|
26
|
-
const subscription = await request.json();
|
|
27
|
-
|
|
28
|
-
if (!validateSubscription(subscription)) {
|
|
29
|
-
return NextResponse.json(
|
|
30
|
-
{ error: 'Invalid subscription format' },
|
|
31
|
-
{ status: 400 }
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Сохраняем subscription (в demo просто в памяти)
|
|
36
|
-
subscriptions.add(JSON.stringify(subscription));
|
|
37
|
-
|
|
38
|
-
console.log('✅ Push subscription saved:', {
|
|
39
|
-
endpoint: subscription.endpoint.substring(0, 50) + '...',
|
|
40
|
-
total: subscriptions.size,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
return NextResponse.json({
|
|
44
|
-
success: true,
|
|
45
|
-
message: 'Subscription saved',
|
|
46
|
-
totalSubscriptions: subscriptions.size,
|
|
47
|
-
});
|
|
48
|
-
} catch (error: any) {
|
|
49
|
-
console.error('Subscription error:', error);
|
|
50
|
-
|
|
51
|
-
return NextResponse.json(
|
|
52
|
-
{
|
|
53
|
-
error: 'Failed to save subscription',
|
|
54
|
-
details: error.message,
|
|
55
|
-
},
|
|
56
|
-
{ status: 500 }
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* GET /api/push/subscribe
|
|
63
|
-
* Get all subscriptions (for testing)
|
|
64
|
-
*/
|
|
65
|
-
export async function handleGetSubscriptions() {
|
|
66
|
-
return NextResponse.json({
|
|
67
|
-
totalSubscriptions: subscriptions.size,
|
|
68
|
-
subscriptions: Array.from(subscriptions).map((sub) => {
|
|
69
|
-
const parsed = JSON.parse(sub);
|
|
70
|
-
return {
|
|
71
|
-
endpoint: parsed.endpoint.substring(0, 50) + '...',
|
|
72
|
-
};
|
|
73
|
-
}),
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* POST /api/push/send
|
|
79
|
-
* Send push notification
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```typescript
|
|
83
|
-
* // app/api/push/send/route.ts
|
|
84
|
-
* export { POST as handleSend as POST } from '@djangocfg/nextjs/pwa/server/routes';
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
export async function handleSend(request: NextRequest) {
|
|
88
|
-
try {
|
|
89
|
-
const { subscription, notification } = await request.json();
|
|
90
|
-
|
|
91
|
-
if (!subscription) {
|
|
92
|
-
return NextResponse.json(
|
|
93
|
-
{ error: 'Subscription is required' },
|
|
94
|
-
{ status: 400 }
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (!validateSubscription(subscription)) {
|
|
99
|
-
return NextResponse.json(
|
|
100
|
-
{ error: 'Invalid subscription format' },
|
|
101
|
-
{ status: 400 }
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Configure VAPID if not already configured
|
|
106
|
-
configureVapid();
|
|
107
|
-
|
|
108
|
-
await sendPushNotification(subscription, {
|
|
109
|
-
title: notification?.title || 'Test Notification',
|
|
110
|
-
body: notification?.body || 'This is a test push notification',
|
|
111
|
-
icon: notification?.icon,
|
|
112
|
-
badge: notification?.badge,
|
|
113
|
-
data: notification?.data,
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
return NextResponse.json({
|
|
117
|
-
success: true,
|
|
118
|
-
message: 'Push notification sent',
|
|
119
|
-
});
|
|
120
|
-
} catch (error: any) {
|
|
121
|
-
console.error('Push notification error:', error);
|
|
122
|
-
|
|
123
|
-
return NextResponse.json(
|
|
124
|
-
{
|
|
125
|
-
error: 'Failed to send push notification',
|
|
126
|
-
details: error.message,
|
|
127
|
-
},
|
|
128
|
-
{ status: 500 }
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Combined route handlers
|
|
135
|
-
* Use like: export { POST, GET } from '@djangocfg/nextjs/pwa/server/routes'
|
|
136
|
-
*/
|
|
137
|
-
export const POST = handleSubscribe;
|
|
138
|
-
export const GET = handleGetSubscriptions;
|