summaryrefslogtreecommitdiff
path: root/api/controls.ts
diff options
context:
space:
mode:
Diffstat (limited to 'api/controls.ts')
-rw-r--r--api/controls.ts101
1 files changed, 101 insertions, 0 deletions
diff --git a/api/controls.ts b/api/controls.ts
new file mode 100644
index 0000000..53db7a1
--- /dev/null
+++ b/api/controls.ts
@@ -0,0 +1,101 @@
+import { apiClient } from "./client";
+import { ControlsData, SafetyControl } from "./types";
+
+export async function getControlsData(): Promise<ControlsData> {
+ const deviceId = apiClient.getSelectedDeviceId();
+
+ if (!deviceId) {
+ // Return default controls if no device selected
+ return {
+ safetyControls: getDefaultControls(),
+ };
+ }
+
+ try {
+ const response = await apiClient.get<{
+ success: boolean;
+ safetyControls: SafetyControl[];
+ }>(`/parent/controls/${deviceId}`);
+
+ return {
+ safetyControls: response.safetyControls,
+ };
+ } catch (e) {
+ console.error("Failed to fetch controls data", e);
+ return {
+ safetyControls: getDefaultControls(),
+ };
+ }
+}
+
+export async function updateSafetyControl(
+ key: string,
+ value: boolean
+): Promise<void> {
+ const deviceId = apiClient.getSelectedDeviceId();
+
+ if (!deviceId) {
+ console.warn("No device selected, cannot update control");
+ return;
+ }
+
+ try {
+ await apiClient.post(`/parent/controls/${deviceId}`, { key, value });
+ } catch (e) {
+ console.error(`Failed to update ${key}`, e);
+ throw e;
+ }
+}
+
+function getDefaultControls(): SafetyControl[] {
+ return [
+ {
+ key: "disable_buddy",
+ title: "Disable Buddy",
+ description: "Temporarily disable Buddy",
+ defaultValue: false,
+ },
+ {
+ key: "adult_sites",
+ title: "Adult sites",
+ description: "Block adult websites.",
+ defaultValue: true,
+ },
+ {
+ key: "family_link_anti_circumvention",
+ title: "Anti-Circumvention",
+ description: "Prevent disabling of Family Link protections.",
+ defaultValue: false,
+ },
+ {
+ key: "filtering",
+ title: "Content filtering",
+ description: "Block unsafe or adult content.",
+ defaultValue: true,
+ },
+ {
+ key: "new_people",
+ title: "New contact alerts",
+ description: "Get notified when your child chats with someone new.",
+ defaultValue: true,
+ },
+ {
+ key: "block_strangers",
+ title: "Block communications with strangers",
+ description: "Block or scan communications with strangers.",
+ defaultValue: false,
+ },
+ {
+ key: "notify_dangerous_messages",
+ title: "Dangerous messages notifications",
+ description: "Notify when messages are potentially dangerous.",
+ defaultValue: true,
+ },
+ {
+ key: "notify_new_contact_added",
+ title: "New contact added notifications",
+ description: "Notify when a new contact is added.",
+ defaultValue: true,
+ },
+ ];
+}