@codaijs/keel 0.2.3 → 0.2.4
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/dist/__tests__/sail-installer.test.js +25 -25
- package/dist/sail-installer.js +174 -174
- package/dist/scaffold.js +68 -68
- package/package.json +58 -58
- package/sails/_template/addon.json +20 -20
- package/sails/_template/install.ts +402 -402
- package/sails/admin-dashboard/README.md +117 -117
- package/sails/admin-dashboard/addon.json +28 -28
- package/sails/admin-dashboard/files/backend/middleware/admin.ts +34 -34
- package/sails/admin-dashboard/files/backend/routes/admin.ts +243 -243
- package/sails/admin-dashboard/files/frontend/components/admin/StatsCard.tsx +40 -40
- package/sails/admin-dashboard/files/frontend/components/admin/UsersTable.tsx +240 -240
- package/sails/admin-dashboard/files/frontend/hooks/useAdmin.ts +149 -149
- package/sails/admin-dashboard/files/frontend/pages/admin/Dashboard.tsx +173 -173
- package/sails/admin-dashboard/files/frontend/pages/admin/UserDetail.tsx +203 -203
- package/sails/admin-dashboard/install.ts +305 -305
- package/sails/analytics/README.md +178 -178
- package/sails/analytics/addon.json +27 -27
- package/sails/analytics/files/frontend/components/AnalyticsProvider.tsx +58 -58
- package/sails/analytics/files/frontend/hooks/useAnalytics.ts +64 -64
- package/sails/analytics/files/frontend/lib/analytics.ts +103 -103
- package/sails/analytics/install.ts +297 -297
- package/sails/file-uploads/addon.json +30 -30
- package/sails/file-uploads/files/backend/routes/files.ts +198 -198
- package/sails/file-uploads/files/backend/schema/files.ts +36 -36
- package/sails/file-uploads/files/backend/services/file-storage.ts +128 -128
- package/sails/file-uploads/files/frontend/components/FileList.tsx +248 -248
- package/sails/file-uploads/files/frontend/components/FileUploadButton.tsx +147 -147
- package/sails/file-uploads/files/frontend/hooks/useFileUpload.ts +106 -106
- package/sails/file-uploads/files/frontend/hooks/useFiles.ts +118 -118
- package/sails/file-uploads/files/frontend/pages/Files.tsx +37 -37
- package/sails/file-uploads/install.ts +466 -466
- package/sails/gdpr/README.md +174 -174
- package/sails/gdpr/addon.json +27 -27
- package/sails/gdpr/files/backend/routes/gdpr.ts +140 -140
- package/sails/gdpr/files/backend/services/gdpr.ts +293 -293
- package/sails/gdpr/files/frontend/components/auth/ConsentCheckboxes.tsx +97 -97
- package/sails/gdpr/files/frontend/components/gdpr/AccountDeletionRequest.tsx +192 -192
- package/sails/gdpr/files/frontend/components/gdpr/DataExportButton.tsx +75 -75
- package/sails/gdpr/files/frontend/pages/PrivacyPolicy.tsx +186 -186
- package/sails/gdpr/install.ts +756 -756
- package/sails/google-oauth/README.md +121 -121
- package/sails/google-oauth/addon.json +22 -22
- package/sails/google-oauth/files/GoogleButton.tsx +50 -50
- package/sails/google-oauth/install.ts +252 -252
- package/sails/i18n/README.md +193 -193
- package/sails/i18n/addon.json +30 -30
- package/sails/i18n/files/frontend/components/LanguageSwitcher.tsx +108 -108
- package/sails/i18n/files/frontend/hooks/useLanguage.ts +31 -31
- package/sails/i18n/files/frontend/lib/i18n.ts +32 -32
- package/sails/i18n/files/frontend/locales/de/common.json +44 -44
- package/sails/i18n/files/frontend/locales/en/common.json +44 -44
- package/sails/i18n/install.ts +407 -407
- package/sails/push-notifications/README.md +163 -163
- package/sails/push-notifications/addon.json +31 -31
- package/sails/push-notifications/files/backend/routes/notifications.ts +153 -153
- package/sails/push-notifications/files/backend/schema/notifications.ts +31 -31
- package/sails/push-notifications/files/backend/services/notifications.ts +117 -117
- package/sails/push-notifications/files/frontend/components/PushNotificationInit.tsx +12 -12
- package/sails/push-notifications/files/frontend/hooks/usePushNotifications.ts +154 -154
- package/sails/push-notifications/install.ts +384 -384
- package/sails/r2-storage/addon.json +29 -29
- package/sails/r2-storage/files/backend/services/storage.ts +71 -71
- package/sails/r2-storage/files/frontend/components/ProfilePictureUpload.tsx +167 -167
- package/sails/r2-storage/install.ts +412 -412
- package/sails/rate-limiting/addon.json +20 -20
- package/sails/rate-limiting/files/backend/middleware/rate-limit-store.ts +104 -104
- package/sails/rate-limiting/files/backend/middleware/rate-limit.ts +137 -137
- package/sails/rate-limiting/install.ts +300 -300
- package/sails/registry.json +107 -107
- package/sails/stripe/README.md +214 -214
- package/sails/stripe/addon.json +24 -24
- package/sails/stripe/files/backend/routes/stripe.ts +154 -154
- package/sails/stripe/files/backend/schema/stripe.ts +74 -74
- package/sails/stripe/files/backend/services/stripe.ts +224 -224
- package/sails/stripe/files/frontend/components/SubscriptionStatus.tsx +135 -135
- package/sails/stripe/files/frontend/hooks/useSubscription.ts +86 -86
- package/sails/stripe/files/frontend/pages/Checkout.tsx +116 -116
- package/sails/stripe/files/frontend/pages/Pricing.tsx +226 -226
- package/sails/stripe/install.ts +378 -378
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
import { useState, useEffect, useCallback, useRef } from "react";
|
|
2
|
-
import { useNavigate } from "react-router";
|
|
3
|
-
import { PushNotifications } from "@capacitor/push-notifications";
|
|
4
|
-
import { isNative, platform } from "@/lib/capacitor.js";
|
|
5
|
-
import { useAuth } from "@/hooks/useAuth.js";
|
|
6
|
-
|
|
7
|
-
type PermissionStatus = "prompt" | "granted" | "denied" | "unknown";
|
|
8
|
-
|
|
9
|
-
interface UsePushNotificationsResult {
|
|
10
|
-
isRegistered: boolean;
|
|
11
|
-
permissionStatus: PermissionStatus;
|
|
12
|
-
register: () => Promise<void>;
|
|
13
|
-
unregister: () => Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Hook to manage push notification registration and handling.
|
|
18
|
-
*
|
|
19
|
-
* On mount (if running on a native platform), requests push permission,
|
|
20
|
-
* registers the device token with the backend, and sets up listeners for
|
|
21
|
-
* incoming notifications and token refreshes.
|
|
22
|
-
*
|
|
23
|
-
* On notification tap, navigates to the route specified in the notification
|
|
24
|
-
* data payload (data.route).
|
|
25
|
-
*/
|
|
26
|
-
export function usePushNotifications(): UsePushNotificationsResult {
|
|
27
|
-
const [isRegistered, setIsRegistered] = useState(false);
|
|
28
|
-
const [permissionStatus, setPermissionStatus] = useState<PermissionStatus>("unknown");
|
|
29
|
-
const currentTokenRef = useRef<string | null>(null);
|
|
30
|
-
const navigate = useNavigate();
|
|
31
|
-
const { user } = useAuth();
|
|
32
|
-
|
|
33
|
-
// Register token with backend
|
|
34
|
-
const registerTokenWithBackend = useCallback(
|
|
35
|
-
async (token: string) => {
|
|
36
|
-
try {
|
|
37
|
-
const response = await fetch("/api/notifications/register", {
|
|
38
|
-
method: "POST",
|
|
39
|
-
headers: { "Content-Type": "application/json" },
|
|
40
|
-
credentials: "include",
|
|
41
|
-
body: JSON.stringify({
|
|
42
|
-
token,
|
|
43
|
-
platform: platform,
|
|
44
|
-
}),
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
if (response.ok) {
|
|
48
|
-
currentTokenRef.current = token;
|
|
49
|
-
setIsRegistered(true);
|
|
50
|
-
}
|
|
51
|
-
} catch (error) {
|
|
52
|
-
console.error("Failed to register push token with backend:", error);
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
[],
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
// Unregister token from backend
|
|
59
|
-
const unregisterTokenFromBackend = useCallback(async () => {
|
|
60
|
-
if (!currentTokenRef.current) return;
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
await fetch("/api/notifications/unregister", {
|
|
64
|
-
method: "DELETE",
|
|
65
|
-
headers: { "Content-Type": "application/json" },
|
|
66
|
-
credentials: "include",
|
|
67
|
-
body: JSON.stringify({ token: currentTokenRef.current }),
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
currentTokenRef.current = null;
|
|
71
|
-
setIsRegistered(false);
|
|
72
|
-
} catch (error) {
|
|
73
|
-
console.error("Failed to unregister push token:", error);
|
|
74
|
-
}
|
|
75
|
-
}, []);
|
|
76
|
-
|
|
77
|
-
// Request permission and register
|
|
78
|
-
const register = useCallback(async () => {
|
|
79
|
-
if (!isNative) return;
|
|
80
|
-
|
|
81
|
-
const permResult = await PushNotifications.requestPermissions();
|
|
82
|
-
setPermissionStatus(permResult.receive as PermissionStatus);
|
|
83
|
-
|
|
84
|
-
if (permResult.receive === "granted") {
|
|
85
|
-
await PushNotifications.register();
|
|
86
|
-
}
|
|
87
|
-
}, []);
|
|
88
|
-
|
|
89
|
-
// Unregister
|
|
90
|
-
const unregister = useCallback(async () => {
|
|
91
|
-
await unregisterTokenFromBackend();
|
|
92
|
-
}, [unregisterTokenFromBackend]);
|
|
93
|
-
|
|
94
|
-
useEffect(() => {
|
|
95
|
-
if (!isNative || !user) return;
|
|
96
|
-
|
|
97
|
-
// Check current permission status
|
|
98
|
-
PushNotifications.checkPermissions().then((result) => {
|
|
99
|
-
setPermissionStatus(result.receive as PermissionStatus);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// Listen for successful registration (we receive the FCM token)
|
|
103
|
-
const registrationListener = PushNotifications.addListener(
|
|
104
|
-
"registration",
|
|
105
|
-
(token) => {
|
|
106
|
-
registerTokenWithBackend(token.value);
|
|
107
|
-
},
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
// Listen for registration errors
|
|
111
|
-
const registrationErrorListener = PushNotifications.addListener(
|
|
112
|
-
"registrationError",
|
|
113
|
-
(error) => {
|
|
114
|
-
console.error("Push notification registration error:", error);
|
|
115
|
-
},
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
// Listen for incoming push notifications (app in foreground)
|
|
119
|
-
const pushReceivedListener = PushNotifications.addListener(
|
|
120
|
-
"pushNotificationReceived",
|
|
121
|
-
(notification) => {
|
|
122
|
-
console.log("Push notification received in foreground:", notification);
|
|
123
|
-
},
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
// Listen for notification taps (app opened from notification)
|
|
127
|
-
const pushActionListener = PushNotifications.addListener(
|
|
128
|
-
"pushNotificationActionPerformed",
|
|
129
|
-
(action) => {
|
|
130
|
-
const data = action.notification.data;
|
|
131
|
-
if (data?.route && typeof data.route === "string") {
|
|
132
|
-
navigate(data.route);
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
// Request permissions and register on mount
|
|
138
|
-
register();
|
|
139
|
-
|
|
140
|
-
return () => {
|
|
141
|
-
registrationListener.then((l) => l.remove());
|
|
142
|
-
registrationErrorListener.then((l) => l.remove());
|
|
143
|
-
pushReceivedListener.then((l) => l.remove());
|
|
144
|
-
pushActionListener.then((l) => l.remove());
|
|
145
|
-
};
|
|
146
|
-
}, [user, register, registerTokenWithBackend, navigate]);
|
|
147
|
-
|
|
148
|
-
return {
|
|
149
|
-
isRegistered,
|
|
150
|
-
permissionStatus,
|
|
151
|
-
register,
|
|
152
|
-
unregister,
|
|
153
|
-
};
|
|
154
|
-
}
|
|
1
|
+
import { useState, useEffect, useCallback, useRef } from "react";
|
|
2
|
+
import { useNavigate } from "react-router";
|
|
3
|
+
import { PushNotifications } from "@capacitor/push-notifications";
|
|
4
|
+
import { isNative, platform } from "@/lib/capacitor.js";
|
|
5
|
+
import { useAuth } from "@/hooks/useAuth.js";
|
|
6
|
+
|
|
7
|
+
type PermissionStatus = "prompt" | "granted" | "denied" | "unknown";
|
|
8
|
+
|
|
9
|
+
interface UsePushNotificationsResult {
|
|
10
|
+
isRegistered: boolean;
|
|
11
|
+
permissionStatus: PermissionStatus;
|
|
12
|
+
register: () => Promise<void>;
|
|
13
|
+
unregister: () => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Hook to manage push notification registration and handling.
|
|
18
|
+
*
|
|
19
|
+
* On mount (if running on a native platform), requests push permission,
|
|
20
|
+
* registers the device token with the backend, and sets up listeners for
|
|
21
|
+
* incoming notifications and token refreshes.
|
|
22
|
+
*
|
|
23
|
+
* On notification tap, navigates to the route specified in the notification
|
|
24
|
+
* data payload (data.route).
|
|
25
|
+
*/
|
|
26
|
+
export function usePushNotifications(): UsePushNotificationsResult {
|
|
27
|
+
const [isRegistered, setIsRegistered] = useState(false);
|
|
28
|
+
const [permissionStatus, setPermissionStatus] = useState<PermissionStatus>("unknown");
|
|
29
|
+
const currentTokenRef = useRef<string | null>(null);
|
|
30
|
+
const navigate = useNavigate();
|
|
31
|
+
const { user } = useAuth();
|
|
32
|
+
|
|
33
|
+
// Register token with backend
|
|
34
|
+
const registerTokenWithBackend = useCallback(
|
|
35
|
+
async (token: string) => {
|
|
36
|
+
try {
|
|
37
|
+
const response = await fetch("/api/notifications/register", {
|
|
38
|
+
method: "POST",
|
|
39
|
+
headers: { "Content-Type": "application/json" },
|
|
40
|
+
credentials: "include",
|
|
41
|
+
body: JSON.stringify({
|
|
42
|
+
token,
|
|
43
|
+
platform: platform,
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (response.ok) {
|
|
48
|
+
currentTokenRef.current = token;
|
|
49
|
+
setIsRegistered(true);
|
|
50
|
+
}
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error("Failed to register push token with backend:", error);
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
[],
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// Unregister token from backend
|
|
59
|
+
const unregisterTokenFromBackend = useCallback(async () => {
|
|
60
|
+
if (!currentTokenRef.current) return;
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
await fetch("/api/notifications/unregister", {
|
|
64
|
+
method: "DELETE",
|
|
65
|
+
headers: { "Content-Type": "application/json" },
|
|
66
|
+
credentials: "include",
|
|
67
|
+
body: JSON.stringify({ token: currentTokenRef.current }),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
currentTokenRef.current = null;
|
|
71
|
+
setIsRegistered(false);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error("Failed to unregister push token:", error);
|
|
74
|
+
}
|
|
75
|
+
}, []);
|
|
76
|
+
|
|
77
|
+
// Request permission and register
|
|
78
|
+
const register = useCallback(async () => {
|
|
79
|
+
if (!isNative) return;
|
|
80
|
+
|
|
81
|
+
const permResult = await PushNotifications.requestPermissions();
|
|
82
|
+
setPermissionStatus(permResult.receive as PermissionStatus);
|
|
83
|
+
|
|
84
|
+
if (permResult.receive === "granted") {
|
|
85
|
+
await PushNotifications.register();
|
|
86
|
+
}
|
|
87
|
+
}, []);
|
|
88
|
+
|
|
89
|
+
// Unregister
|
|
90
|
+
const unregister = useCallback(async () => {
|
|
91
|
+
await unregisterTokenFromBackend();
|
|
92
|
+
}, [unregisterTokenFromBackend]);
|
|
93
|
+
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (!isNative || !user) return;
|
|
96
|
+
|
|
97
|
+
// Check current permission status
|
|
98
|
+
PushNotifications.checkPermissions().then((result) => {
|
|
99
|
+
setPermissionStatus(result.receive as PermissionStatus);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Listen for successful registration (we receive the FCM token)
|
|
103
|
+
const registrationListener = PushNotifications.addListener(
|
|
104
|
+
"registration",
|
|
105
|
+
(token) => {
|
|
106
|
+
registerTokenWithBackend(token.value);
|
|
107
|
+
},
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
// Listen for registration errors
|
|
111
|
+
const registrationErrorListener = PushNotifications.addListener(
|
|
112
|
+
"registrationError",
|
|
113
|
+
(error) => {
|
|
114
|
+
console.error("Push notification registration error:", error);
|
|
115
|
+
},
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
// Listen for incoming push notifications (app in foreground)
|
|
119
|
+
const pushReceivedListener = PushNotifications.addListener(
|
|
120
|
+
"pushNotificationReceived",
|
|
121
|
+
(notification) => {
|
|
122
|
+
console.log("Push notification received in foreground:", notification);
|
|
123
|
+
},
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
// Listen for notification taps (app opened from notification)
|
|
127
|
+
const pushActionListener = PushNotifications.addListener(
|
|
128
|
+
"pushNotificationActionPerformed",
|
|
129
|
+
(action) => {
|
|
130
|
+
const data = action.notification.data;
|
|
131
|
+
if (data?.route && typeof data.route === "string") {
|
|
132
|
+
navigate(data.route);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
// Request permissions and register on mount
|
|
138
|
+
register();
|
|
139
|
+
|
|
140
|
+
return () => {
|
|
141
|
+
registrationListener.then((l) => l.remove());
|
|
142
|
+
registrationErrorListener.then((l) => l.remove());
|
|
143
|
+
pushReceivedListener.then((l) => l.remove());
|
|
144
|
+
pushActionListener.then((l) => l.remove());
|
|
145
|
+
};
|
|
146
|
+
}, [user, register, registerTokenWithBackend, navigate]);
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
isRegistered,
|
|
150
|
+
permissionStatus,
|
|
151
|
+
register,
|
|
152
|
+
unregister,
|
|
153
|
+
};
|
|
154
|
+
}
|