Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions infra/relay/src/agentActivity/ApnsClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ import * as HttpClientResponse from "effect/http/HttpClientResponse";

import type { ApnsCredentials } from "../Config.ts";
import * as ApnsClient from "./ApnsClient.ts";
import { sanitizeApnsNotificationPayload } from "./agentActivityPayloads.ts";
import * as ApnsProviderTokens from "./ApnsProviderTokens.ts";

const encodePayloadJson = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));

const isApnsJwtSigningError = Schema.is(ApnsClient.ApnsJwtSigningError);
const isApnsHttpRequestError = Schema.is(ApnsClient.ApnsHttpRequestError);

Expand Down Expand Up @@ -179,6 +182,13 @@ describe("ApnsClient", () => {
},
});

// Expo iOS NotificationRecords.serializedNotificationData uses userInfo.body for remote pushes.
const expoData = (request.payload as { body?: unknown }).body;
expect(expoData).toEqual({
environmentId: "env",
threadId: "thread",
deepLink: "/threads/env/thread",
});
expect(request.priority).toBe("10");
expect(request.payload).toMatchObject({
aps: {
Expand All @@ -189,9 +199,31 @@ describe("ApnsClient", () => {
sound: "default",
"thread-id": "env/thread",
},
environmentId: "env",
threadId: "thread",
deepLink: "/threads/env/thread",
});
}).pipe(Effect.provide(layerTest)),
);

it.effect("keeps long notification routing metadata within the APNs payload limit", () =>
Effect.gen(function* () {
const apns = yield* ApnsClient.ApnsClient;
const environmentId = "é".repeat(191);
const threadId = "t".repeat(512);
const notification = sanitizeApnsNotificationPayload({
title: "界".repeat(120),
body: "界".repeat(120),
environmentId,
threadId,
deepLink: `/threads/${encodeURIComponent(environmentId)}/${threadId}`,
});
const request = apns.makePushNotificationRequest({ token: "push-token", notification });
const json = yield* encodePayloadJson(request.payload);
expect(new TextEncoder().encode(json).byteLength).toBeLessThanOrEqual(4096);
expect(request.payload).toMatchObject({
body: {
environmentId,
threadId,
deepLink: notification.deepLink,
},
});
}).pipe(Effect.provide(layerTest)),
);
Expand Down
9 changes: 6 additions & 3 deletions infra/relay/src/agentActivity/ApnsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,12 @@ function makePushNotificationRequest(input: {
// not bury the others; a grouped alert for several threads stays alone.
"thread-id": notificationThreadId(input.notification),
},
environmentId: input.notification.environmentId,
threadId: input.notification.threadId,
deepLink: input.notification.deepLink,
// Expo iOS exposes userInfo.body as notification.content.data for remote pushes.
body: {
environmentId: input.notification.environmentId,
threadId: input.notification.threadId,
deepLink: input.notification.deepLink,
},
},
};
}
Expand Down
Loading