Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

registrationPayload.ts

46 lines1.8 KB

1import type { RelayDeviceRegistrationRequest } from "@t3tools/contracts/relay";
2​
3import type { Preferences } from "../../persistence/mobile-preferences";
4import { supportsAgentAwarenessPush } from "./capabilities";
5​
6// Development builds are Xcode-signed and receive sandbox APNs tokens;
7// preview and production builds are distribution-signed and use production
8// APNs. The relay routes each device's pushes accordingly.
9export function resolveApsEnvironment(appVariant: unknown): "sandbox" | "production" {
10 return appVariant === "development" ? "sandbox" : "production";
12​
13export function makeRelayDeviceRegistrationRequest(input: {
14 readonly deviceId: string;
15 readonly label: string;
16 readonly iosMajorVersion: number;
17 readonly appVersion?: string;
18 readonly bundleId?: string;
19 readonly apsEnvironment?: "sandbox" | "production";
20 readonly pushToken?: string;
21 readonly pushToStartToken?: string;
22 readonly notificationsEnabled: boolean;
23 readonly preferences: Preferences;
24}): RelayDeviceRegistrationRequest {
25 const pushAvailable = supportsAgentAwarenessPush();
26 const liveActivitiesEnabled = pushAvailable && input.preferences.liveActivitiesEnabled !== false;
27 return {
28 deviceId: input.deviceId,
29 label: input.label,
30 platform: "ios",
31 iosMajorVersion: input.iosMajorVersion,
32 appVersion: input.appVersion,
33 ...(input.bundleId ? { bundleId: input.bundleId } : {}),
34 ...(input.apsEnvironment ? { apsEnvironment: input.apsEnvironment } : {}),
35 ...(input.pushToken ? { pushToken: input.pushToken } : {}),
36 ...(input.pushToStartToken ? { pushToStartToken: input.pushToStartToken } : {}),
37 preferences: {
38 liveActivitiesEnabled,
39 notificationsEnabled: pushAvailable && input.notificationsEnabled,
40 notifyOnApproval: true,
41 notifyOnInput: true,
42 notifyOnCompletion: true,
43 notifyOnFailure: true,
44 },
45 };