@open-mercato/channel-apns 0.9.1-develop.7574.1.837288eec1 → 0.10.0
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/AGENTS.md +2 -0
- package/dist/modules/channel_apns/__integration__/TC-CHANNEL-PUSH-006.spec.js +3 -1
- package/dist/modules/channel_apns/__integration__/TC-CHANNEL-PUSH-006.spec.js.map +2 -2
- package/dist/modules/channel_apns/lib/adapter.js +4 -0
- package/dist/modules/channel_apns/lib/adapter.js.map +2 -2
- package/jest.config.cjs +1 -1
- package/package.json +12 -9
- package/src/modules/channel_apns/__integration__/TC-CHANNEL-PUSH-006.spec.ts +3 -1
- package/src/modules/channel_apns/lib/__tests__/message-golden.test.ts +36 -0
- package/src/modules/channel_apns/lib/adapter.ts +4 -0
package/AGENTS.md
CHANGED
|
@@ -27,6 +27,8 @@ Do not remove the pin while this package depends on `@parse/node-apn`: dropping
|
|
|
27
27
|
|
|
28
28
|
Implements the shared push-adapter contract (see `channel-fcm` AGENTS.md). Permanent-token reasons mapped to the uniform `device_unregistered` sentinel: `Unregistered` (410), `BadDeviceToken` (400). One HTTP/2 `apn.Provider` is cached per credentials hash. The `ApnsSender` seam keeps the node-apn provider out of the control flow and out of unit tests.
|
|
29
29
|
|
|
30
|
+
A visible push with `pushOptions.image` sets `mutable-content: 1` and sends the URL as a top-level `imageUrl` key beside `aps` (it overrides a `data.imageUrl` key), so the app's Notification Service Extension can download and attach it. Silent pushes ignore `image`. Treat the `imageUrl` key name as a client contract.
|
|
31
|
+
|
|
30
32
|
## Credentials
|
|
31
33
|
|
|
32
34
|
Tenant-level credentials on `IntegrationCredentials` for provider `channel_apns`: `{ p8Key (PEM contents), keyId, teamId, bundleId (APNs topic), production }`. Connect via the existing `communication_channels` credentials-connect flow. Device tokens live in `devices.UserDevice.push_token`, never here.
|
|
@@ -37,7 +37,7 @@ test.describe("TC-CHANNEL-PUSH-006: real APNs adapter reaches sent with a correc
|
|
|
37
37
|
type: "admin.custom_message",
|
|
38
38
|
title: "Order shipped",
|
|
39
39
|
body: "Your order is on its way",
|
|
40
|
-
pushOptions: { badge: 5, sound: "chime.caf" }
|
|
40
|
+
pushOptions: { badge: 5, sound: "chime.caf", image: "https://example.com/tc-channel-push-006.png" }
|
|
41
41
|
});
|
|
42
42
|
await drainIntegrationQueue("events");
|
|
43
43
|
await drainIntegrationQueue("push-deliveries");
|
|
@@ -52,6 +52,8 @@ test.describe("TC-CHANNEL-PUSH-006: real APNs adapter reaches sent with a correc
|
|
|
52
52
|
sound: "chime.caf"
|
|
53
53
|
});
|
|
54
54
|
expect(native.payload.aps["content-available"]).toBeUndefined();
|
|
55
|
+
expect(native.payload.aps["mutable-content"]).toBe(1);
|
|
56
|
+
expect(native.payload.imageUrl).toBe("https://example.com/tc-channel-push-006.png");
|
|
55
57
|
} finally {
|
|
56
58
|
await deleteDeliveriesForDevice(userDeviceId);
|
|
57
59
|
await deleteFakePushDevice(request, adminToken, userDeviceId);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/channel_apns/__integration__/TC-CHANNEL-PUSH-006.spec.ts"],
|
|
4
|
-
"sourcesContent": ["import { expect, test } from '@playwright/test'\nimport { getAuthToken } from '@open-mercato/core/helpers/integration/api'\nimport { getTokenScope } from '@open-mercato/core/helpers/integration/generalFixtures'\nimport { createNotificationFixture } from '@open-mercato/core/helpers/integration/notificationsFixtures'\nimport { drainIntegrationQueue } from '@open-mercato/core/helpers/integration/queue'\nimport {\n connectFakePushChannel,\n deleteChannelIfExists,\n deleteDeliveriesForDevice,\n deleteFakePushDevice,\n expectNativeMessage,\n makeFakePushToken,\n readLatestDelivery,\n registerFakePushDevice,\n} from '@open-mercato/core/helpers/integration/pushFake'\n\n/**\n * TC-CHANNEL-PUSH-006 \u2014 the REAL APNs adapter, end-to-end, without live credentials.\n *\n * Only the network provider is faked (`OM_PUSH_FAKE_PROVIDERS`): the adapter's credential resolution and\n * `buildApnsNotification` run for real, against a real `apn.Notification`. The `.p8` key is never parsed\n * because parsing lives inside the sender factory the fake replaces \u2014 the connect route only\n * schema-validates it.\n *\n * The recorded message is therefore the WIRE form node-apn transmits: request `headers` (where\n * `apns-push-type` lives) and the compiled `aps` payload.\n */\nconst PROVIDER = 'apns'\n\ntype NativeApns = {\n headers: Record<string, unknown>\n payload: { aps: Record<string, unknown> } & Record<string, unknown>\n}\n\ntest.describe('TC-CHANNEL-PUSH-006: real APNs adapter reaches sent with a correct native notification', () => {\n test('maps pushOptions onto the aps payload for a visible notification', async ({ request }) => {\n // Budgeted explicitly rather than via `test.slow()` (which only triples the config's 20s budget).\n // NOTE: this does not fix the current CI failure \u2014 `POST /api/notifications` hangs >30s in the\n // channel-package shard, so the test dies on `apiRequest`'s own 30s timeout. See the spec changelog.\n test.setTimeout(120_000)\n const adminToken = await getAuthToken(request, 'admin')\n const { tenantId, userId } = getTokenScope(adminToken)\n const { pushToken, tokenTail } = makeFakePushToken(PROVIDER)\n const startedAt = new Date().toISOString()\n\n let channelId: string | null = null\n let userDeviceId: string | null = null\n try {\n channelId = await connectFakePushChannel(request, adminToken, PROVIDER, 'TC-CHANNEL-PUSH-006 APNs')\n userDeviceId = await registerFakePushDevice(\n request,\n adminToken,\n PROVIDER,\n pushToken,\n `qa-tc-channel-push-006-${Date.now()}`,\n )\n\n await createNotificationFixture(request, adminToken, {\n recipientUserId: userId,\n type: 'admin.custom_message',\n title: 'Order shipped',\n body: 'Your order is on its way',\n pushOptions: { badge: 5, sound: 'chime.caf' },\n })\n\n await drainIntegrationQueue('events')\n await drainIntegrationQueue('push-deliveries')\n\n await expect\n .poll(async () => (await readLatestDelivery(tenantId, userDeviceId as string))?.status ?? null, {\n timeout: 30_000,\n })\n .toBe('sent')\n\n const native = (await expectNativeMessage(PROVIDER, tokenTail, startedAt)) as unknown as NativeApns\n expect(native.headers['apns-topic']).toBe('com.openmercato.fake')\n expect(native.payload.aps).toMatchObject({\n alert: { title: 'Order shipped', body: 'Your order is on its way' },\n badge: 5,\n sound: 'chime.caf',\n })\n expect(native.payload.aps['content-available']).toBeUndefined()\n } finally {\n await deleteDeliveriesForDevice(userDeviceId)\n await deleteFakePushDevice(request, adminToken, userDeviceId)\n await deleteChannelIfExists(request, adminToken, channelId)\n }\n })\n\n test('a silent type produces a background content-available push with no user-facing copy', async ({ request }) => {\n // Budgeted explicitly rather than via `test.slow()` (which only triples the config's 20s budget).\n // NOTE: this does not fix the current CI failure \u2014 `POST /api/notifications` hangs >30s in the\n // channel-package shard, so the test dies on `apiRequest`'s own 30s timeout. See the spec changelog.\n test.setTimeout(120_000)\n const adminToken = await getAuthToken(request, 'admin')\n const { tenantId, userId } = getTokenScope(adminToken)\n const { pushToken, tokenTail } = makeFakePushToken(PROVIDER)\n const startedAt = new Date().toISOString()\n\n let channelId: string | null = null\n let userDeviceId: string | null = null\n try {\n channelId = await connectFakePushChannel(request, adminToken, PROVIDER, 'TC-CHANNEL-PUSH-006 APNs silent')\n userDeviceId = await registerFakePushDevice(\n request,\n adminToken,\n PROVIDER,\n pushToken,\n `qa-tc-channel-push-006-silent-${Date.now()}`,\n )\n\n // Silent-ness is a property of the registered type, never a per-call flag.\n await createNotificationFixture(request, adminToken, {\n recipientUserId: userId,\n type: 'admin.custom_silent',\n title: 'Should not be delivered as copy',\n body: 'Should not be delivered as copy',\n data: { sync: 'orders' },\n })\n\n await drainIntegrationQueue('events')\n await drainIntegrationQueue('push-deliveries')\n\n await expect\n .poll(async () => (await readLatestDelivery(tenantId, userDeviceId as string))?.status ?? null, {\n timeout: 30_000,\n })\n .toBe('sent')\n\n const row = await readLatestDelivery(tenantId, userDeviceId as string)\n expect(row?.silent).toBe(true)\n\n const native = (await expectNativeMessage(PROVIDER, tokenTail, startedAt)) as unknown as NativeApns\n // Apple requires both of these for a background push; sending an alert alongside them is invalid.\n expect(native.headers['apns-push-type']).toBe('background')\n expect(native.headers['apns-priority']).toBe(5)\n expect(native.payload.aps).toEqual({ 'content-available': 1 })\n expect(native.payload.sync).toBe('orders')\n } finally {\n await deleteDeliveriesForDevice(userDeviceId)\n await deleteFakePushDevice(request, adminToken, userDeviceId)\n await deleteChannelIfExists(request, adminToken, channelId)\n }\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,QAAQ,YAAY;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B;AACtC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAaP,MAAM,WAAW;AAOjB,KAAK,SAAS,0FAA0F,MAAM;AAC5G,OAAK,oEAAoE,OAAO,EAAE,QAAQ,MAAM;AAI9F,SAAK,WAAW,IAAO;AACvB,UAAM,aAAa,MAAM,aAAa,SAAS,OAAO;AACtD,UAAM,EAAE,UAAU,OAAO,IAAI,cAAc,UAAU;AACrD,UAAM,EAAE,WAAW,UAAU,IAAI,kBAAkB,QAAQ;AAC3D,UAAM,aAAY,oBAAI,KAAK,GAAE,YAAY;AAEzC,QAAI,YAA2B;AAC/B,QAAI,eAA8B;AAClC,QAAI;AACF,kBAAY,MAAM,uBAAuB,SAAS,YAAY,UAAU,0BAA0B;AAClG,qBAAe,MAAM;AAAA,QACnB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,0BAA0B,KAAK,IAAI,CAAC;AAAA,MACtC;AAEA,YAAM,0BAA0B,SAAS,YAAY;AAAA,QACjD,iBAAiB;AAAA,QACjB,MAAM;AAAA,QACN,OAAO;AAAA,QACP,MAAM;AAAA,QACN,aAAa,EAAE,OAAO,GAAG,OAAO,
|
|
4
|
+
"sourcesContent": ["import { expect, test } from '@playwright/test'\nimport { getAuthToken } from '@open-mercato/core/helpers/integration/api'\nimport { getTokenScope } from '@open-mercato/core/helpers/integration/generalFixtures'\nimport { createNotificationFixture } from '@open-mercato/core/helpers/integration/notificationsFixtures'\nimport { drainIntegrationQueue } from '@open-mercato/core/helpers/integration/queue'\nimport {\n connectFakePushChannel,\n deleteChannelIfExists,\n deleteDeliveriesForDevice,\n deleteFakePushDevice,\n expectNativeMessage,\n makeFakePushToken,\n readLatestDelivery,\n registerFakePushDevice,\n} from '@open-mercato/core/helpers/integration/pushFake'\n\n/**\n * TC-CHANNEL-PUSH-006 \u2014 the REAL APNs adapter, end-to-end, without live credentials.\n *\n * Only the network provider is faked (`OM_PUSH_FAKE_PROVIDERS`): the adapter's credential resolution and\n * `buildApnsNotification` run for real, against a real `apn.Notification`. The `.p8` key is never parsed\n * because parsing lives inside the sender factory the fake replaces \u2014 the connect route only\n * schema-validates it.\n *\n * The recorded message is therefore the WIRE form node-apn transmits: request `headers` (where\n * `apns-push-type` lives) and the compiled `aps` payload.\n */\nconst PROVIDER = 'apns'\n\ntype NativeApns = {\n headers: Record<string, unknown>\n payload: { aps: Record<string, unknown> } & Record<string, unknown>\n}\n\ntest.describe('TC-CHANNEL-PUSH-006: real APNs adapter reaches sent with a correct native notification', () => {\n test('maps pushOptions onto the aps payload for a visible notification', async ({ request }) => {\n // Budgeted explicitly rather than via `test.slow()` (which only triples the config's 20s budget).\n // NOTE: this does not fix the current CI failure \u2014 `POST /api/notifications` hangs >30s in the\n // channel-package shard, so the test dies on `apiRequest`'s own 30s timeout. See the spec changelog.\n test.setTimeout(120_000)\n const adminToken = await getAuthToken(request, 'admin')\n const { tenantId, userId } = getTokenScope(adminToken)\n const { pushToken, tokenTail } = makeFakePushToken(PROVIDER)\n const startedAt = new Date().toISOString()\n\n let channelId: string | null = null\n let userDeviceId: string | null = null\n try {\n channelId = await connectFakePushChannel(request, adminToken, PROVIDER, 'TC-CHANNEL-PUSH-006 APNs')\n userDeviceId = await registerFakePushDevice(\n request,\n adminToken,\n PROVIDER,\n pushToken,\n `qa-tc-channel-push-006-${Date.now()}`,\n )\n\n await createNotificationFixture(request, adminToken, {\n recipientUserId: userId,\n type: 'admin.custom_message',\n title: 'Order shipped',\n body: 'Your order is on its way',\n pushOptions: { badge: 5, sound: 'chime.caf', image: 'https://example.com/tc-channel-push-006.png' },\n })\n\n await drainIntegrationQueue('events')\n await drainIntegrationQueue('push-deliveries')\n\n await expect\n .poll(async () => (await readLatestDelivery(tenantId, userDeviceId as string))?.status ?? null, {\n timeout: 30_000,\n })\n .toBe('sent')\n\n const native = (await expectNativeMessage(PROVIDER, tokenTail, startedAt)) as unknown as NativeApns\n expect(native.headers['apns-topic']).toBe('com.openmercato.fake')\n expect(native.payload.aps).toMatchObject({\n alert: { title: 'Order shipped', body: 'Your order is on its way' },\n badge: 5,\n sound: 'chime.caf',\n })\n expect(native.payload.aps['content-available']).toBeUndefined()\n expect(native.payload.aps['mutable-content']).toBe(1)\n expect(native.payload.imageUrl).toBe('https://example.com/tc-channel-push-006.png')\n } finally {\n await deleteDeliveriesForDevice(userDeviceId)\n await deleteFakePushDevice(request, adminToken, userDeviceId)\n await deleteChannelIfExists(request, adminToken, channelId)\n }\n })\n\n test('a silent type produces a background content-available push with no user-facing copy', async ({ request }) => {\n // Budgeted explicitly rather than via `test.slow()` (which only triples the config's 20s budget).\n // NOTE: this does not fix the current CI failure \u2014 `POST /api/notifications` hangs >30s in the\n // channel-package shard, so the test dies on `apiRequest`'s own 30s timeout. See the spec changelog.\n test.setTimeout(120_000)\n const adminToken = await getAuthToken(request, 'admin')\n const { tenantId, userId } = getTokenScope(adminToken)\n const { pushToken, tokenTail } = makeFakePushToken(PROVIDER)\n const startedAt = new Date().toISOString()\n\n let channelId: string | null = null\n let userDeviceId: string | null = null\n try {\n channelId = await connectFakePushChannel(request, adminToken, PROVIDER, 'TC-CHANNEL-PUSH-006 APNs silent')\n userDeviceId = await registerFakePushDevice(\n request,\n adminToken,\n PROVIDER,\n pushToken,\n `qa-tc-channel-push-006-silent-${Date.now()}`,\n )\n\n // Silent-ness is a property of the registered type, never a per-call flag.\n await createNotificationFixture(request, adminToken, {\n recipientUserId: userId,\n type: 'admin.custom_silent',\n title: 'Should not be delivered as copy',\n body: 'Should not be delivered as copy',\n data: { sync: 'orders' },\n })\n\n await drainIntegrationQueue('events')\n await drainIntegrationQueue('push-deliveries')\n\n await expect\n .poll(async () => (await readLatestDelivery(tenantId, userDeviceId as string))?.status ?? null, {\n timeout: 30_000,\n })\n .toBe('sent')\n\n const row = await readLatestDelivery(tenantId, userDeviceId as string)\n expect(row?.silent).toBe(true)\n\n const native = (await expectNativeMessage(PROVIDER, tokenTail, startedAt)) as unknown as NativeApns\n // Apple requires both of these for a background push; sending an alert alongside them is invalid.\n expect(native.headers['apns-push-type']).toBe('background')\n expect(native.headers['apns-priority']).toBe(5)\n expect(native.payload.aps).toEqual({ 'content-available': 1 })\n expect(native.payload.sync).toBe('orders')\n } finally {\n await deleteDeliveriesForDevice(userDeviceId)\n await deleteFakePushDevice(request, adminToken, userDeviceId)\n await deleteChannelIfExists(request, adminToken, channelId)\n }\n })\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,QAAQ,YAAY;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B;AACtC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAaP,MAAM,WAAW;AAOjB,KAAK,SAAS,0FAA0F,MAAM;AAC5G,OAAK,oEAAoE,OAAO,EAAE,QAAQ,MAAM;AAI9F,SAAK,WAAW,IAAO;AACvB,UAAM,aAAa,MAAM,aAAa,SAAS,OAAO;AACtD,UAAM,EAAE,UAAU,OAAO,IAAI,cAAc,UAAU;AACrD,UAAM,EAAE,WAAW,UAAU,IAAI,kBAAkB,QAAQ;AAC3D,UAAM,aAAY,oBAAI,KAAK,GAAE,YAAY;AAEzC,QAAI,YAA2B;AAC/B,QAAI,eAA8B;AAClC,QAAI;AACF,kBAAY,MAAM,uBA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|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -51,6 +51,10 @@ function buildApnsNotification(note, payload) {
|
|
|
51
51
|
note.sound = options.sound ?? "default";
|
|
52
52
|
if (typeof options.badge === "number") note.badge = options.badge;
|
|
53
53
|
if (options.priority === "normal") note.priority = 5;
|
|
54
|
+
if (options.image) {
|
|
55
|
+
note.mutableContent = true;
|
|
56
|
+
note.payload = { ...payload.data, imageUrl: options.image };
|
|
57
|
+
}
|
|
54
58
|
}
|
|
55
59
|
return note;
|
|
56
60
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/channel_apns/lib/adapter.ts"],
|
|
4
|
-
"sourcesContent": ["import { createHash } from 'node:crypto'\nimport type {\n SendMessageInput,\n SendMessageResult,\n} from '@open-mercato/core/modules/communication_channels/lib/adapter'\nimport {\n BasePushChannelAdapter,\n deviceUnregisteredResult,\n MISSING_PUSH_TOKEN_RESULT,\n readPushToken,\n} from '@open-mercato/core/modules/communication_channels/lib/push-adapter'\nimport { createRefCountedClientCache } from '@open-mercato/core/modules/communication_channels/lib/refcounted-client-cache'\nimport { readPushEnvelope, resolvePushBody, type PushEnvelope } from '@open-mercato/core/modules/communication_channels/lib/push-envelope'\nimport {\n apnsCredentialsSchema,\n resolveApnsCredentials,\n type ApnsResolvedCredentials,\n} from './credentials'\n\n/**\n * The ONLY APNs signal that a device token is permanently dead: HTTP 410 with reason `Unregistered`\n * (the two always travel together \u2014 410 is Apple's irrecoverable \"remove this token\" status). A bare\n * `410` status whose reason node-apn could not parse means the same thing, so it is included. Both map\n * to the uniform `device_unregistered` sentinel so the push worker soft-deletes the device (identical\n * contract across fcm/apns/expo).\n *\n * `BadDeviceToken` is deliberately EXCLUDED. Apple returns it for a VALID token presented to the wrong\n * environment (a production token hitting the sandbox host, or vice-versa \u2014 and `production` defaults\n * to false), not only for a malformed token, and APNs gives no code to disambiguate the two. Treating\n * it as permanent would soft-delete every live iOS device in a tenant on a single environment\n * misconfiguration, with no recovery path. It \u2014 like the other non-410 reasons (`DeviceTokenNotForTopic`,\n * `TopicDisallowed`, `PayloadTooLarge`, `TooManyRequests`, `InternalServerError`, `ServiceUnavailable`,\n * `ExpiredProviderToken`) \u2014 is a transient/config failure: the delivery retries then expires, but the\n * device is KEPT so it recovers once the sender-side config is fixed.\n */\nconst PERMANENT_APNS_REASONS = new Set(['Unregistered', '410'])\n\nexport interface ApnsSendOutcome {\n ok: boolean\n /** Provider rejection reason (e.g. `Unregistered`, `BadDeviceToken`), or the stringified HTTP status\n * (e.g. `410`) when node-apn could not parse a reason from the response body. */\n reason?: string\n /** Transport-level error message (network/auth), distinct from a provider rejection. */\n error?: string\n}\n\n/**\n * A bound APNs sender for one tenant's credentials. The seam keeps `@parse/node-apn`\n * (and its HTTP/2 provider) entirely out of the adapter's control flow and tests.\n */\nexport type ApnsSender = (payload: PushEnvelope & { topic: string }, token: string) => Promise<ApnsSendOutcome>\n\nexport type ApnsSenderFactory = (credentials: ApnsResolvedCredentials) => ApnsSender\n\nlet senderFactory: ApnsSenderFactory | null = null\n\n/** Test-only seam to swap the APNs sender factory. */\nexport function setApnsSenderFactory(factory: ApnsSenderFactory | null): void {\n senderFactory = factory\n}\n\ntype ApnsProviderLike = {\n send(notification: unknown, token: string): Promise<{\n sent?: Array<{ device: string }>\n failed?: Array<{ device: string; status?: string | number; error?: Error; response?: { reason?: string } }>\n }>\n /** node-apn's Provider exposes `shutdown()` to close its HTTP/2 socket to Apple. */\n shutdown?(): void\n}\n\nfunction credentialsHash(credentials: ApnsResolvedCredentials): string {\n return createHash('sha256')\n .update(`${credentials.keyId}:${credentials.teamId}:${credentials.bundleId}:${credentials.production}:${credentials.p8Key}`)\n .digest('hex')\n .slice(0, 16)\n}\n\n/**\n * Bounds the number of live HTTP/2 providers cached at once. Each entry holds an\n * open socket to Apple, so an unbounded cache would leak a connection every time a\n * tenant rotates their `.p8` key or toggles `production` (the hash changes \u2192 a new\n * entry, while the stale provider never shuts down). LRU-evicting the least-recently\n * used provider and calling `shutdown()` keeps the connection count bounded. Disposal\n * is fenced on in-flight sends: an evicted provider is shut down only once its last\n * concurrent `send` releases (see refcounted-client-cache), so eviction never closes\n * the HTTP/2 socket out from under a send.\n */\nconst PROVIDER_CACHE_MAX = 32\nconst providerCache = createRefCountedClientCache<ApnsProviderLike>({\n max: PROVIDER_CACHE_MAX,\n dispose: (provider) => {\n try {\n provider.shutdown?.()\n } catch {\n // shutdown is best-effort; a throwing/absent shutdown must not break eviction.\n }\n },\n})\n\nasync function createProvider(credentials: ApnsResolvedCredentials): Promise<ApnsProviderLike> {\n const apnModule = await import('@parse/node-apn')\n const apn = (apnModule as { default?: unknown }).default ?? apnModule\n const Provider = (apn as { Provider: new (options: unknown) => ApnsProviderLike }).Provider\n return new Provider({\n token: { key: credentials.p8Key, keyId: credentials.keyId, teamId: credentials.teamId },\n production: credentials.production,\n })\n}\n\n/**\n * Populate an APNs `Notification` from the push envelope, branching on `silent` (background\n * content-available wake-up \u2014 no alert/sound) and applying the recognized push options. Mutates and\n * returns `note`. Extracted from the sender so it is unit-testable without `@parse/node-apn`.\n */\nexport function buildApnsNotification(\n note: Record<string, unknown>,\n payload: PushEnvelope & { topic: string },\n): Record<string, unknown> {\n const { options, silent } = payload\n note.topic = payload.topic\n note.payload = payload.data\n if (silent) {\n note.contentAvailable = 1\n note.pushType = 'background'\n note.priority = 5\n } else {\n note.alert = { title: payload.title, body: resolvePushBody(payload) }\n note.sound = options.sound ?? 'default'\n if (typeof options.badge === 'number') note.badge = options.badge\n if (options.priority === 'normal') note.priority = 5\n }\n return note\n}\n\nfunction defaultSenderFactory(credentials: ApnsResolvedCredentials): ApnsSender {\n return async (payload, token) => {\n const apnModule = await import('@parse/node-apn')\n const apn = (apnModule as { default?: unknown }).default ?? apnModule\n const Notification = (apn as { Notification: new () => Record<string, unknown> }).Notification\n const note = buildApnsNotification(new Notification(), payload)\n\n // Borrow a cached provider for the duration of the send; release() in finally keeps an evicted\n // provider's socket open until this send completes.\n const lease = await providerCache.acquire(credentialsHash(credentials), () => createProvider(credentials))\n try {\n const result = await lease.client.send(note, token)\n if (result.sent && result.sent.length > 0) return { ok: true }\n const failure = result.failed?.[0]\n if (!failure) return { ok: false, error: 'no_response' }\n if (failure.error) return { ok: false, error: failure.error.message }\n const reason = failure.response?.reason ?? (failure.status != null ? String(failure.status) : undefined)\n return { ok: false, reason }\n } finally {\n lease.release()\n }\n }\n}\n\nclass ApnsChannelAdapter extends BasePushChannelAdapter {\n readonly providerKey = 'apns'\n protected readonly credentialsSchema = apnsCredentialsSchema\n\n async sendMessage(input: SendMessageInput): Promise<SendMessageResult> {\n const token = readPushToken(input)\n if (!token) return MISSING_PUSH_TOKEN_RESULT\n\n const parsedCredentials = apnsCredentialsSchema.safeParse(input.credentials)\n if (!parsedCredentials.success) {\n return { externalMessageId: '', status: 'failed', error: 'invalid_apns_credentials' }\n }\n\n const credentials = resolveApnsCredentials(parsedCredentials.data)\n const envelope = readPushEnvelope(input.content)\n const sender = (senderFactory ?? defaultSenderFactory)(credentials)\n\n try {\n const outcome = await sender({ ...envelope, topic: credentials.bundleId }, token)\n if (outcome.ok) {\n // node-apn returns no provider message id. Return an empty id rather than any slice of the\n // push token \u2014 the worker persists externalMessageId into the admin-exposed provider_response,\n // and this module only ever surfaces the last-8 via token_snapshot, never raw token material.\n return { externalMessageId: '', status: 'sent' }\n }\n if (outcome.reason && PERMANENT_APNS_REASONS.has(outcome.reason)) {\n return deviceUnregisteredResult({ reason: outcome.reason })\n }\n return { externalMessageId: '', status: 'failed', error: outcome.error ?? outcome.reason ?? 'apns_send_failed' }\n } catch (err) {\n return { externalMessageId: '', status: 'failed', error: err instanceof Error ? err.message : String(err) }\n }\n }\n}\n\nlet cachedAdapter: ApnsChannelAdapter | null = null\n\nexport function getApnsChannelAdapter(): ApnsChannelAdapter {\n if (!cachedAdapter) cachedAdapter = new ApnsChannelAdapter()\n return cachedAdapter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OAAO,QAAQ,OAAO,MAAM,gBAAgB,OAAO,EAAE;AACpE,SAAK,QAAQ,QAAQ,SAAS;AAC9B,QAAI,OAAO,QAAQ,UAAU,SAAU,MAAK,QAAQ,QAAQ;AAC5D,QAAI,QAAQ,aAAa,SAAU,MAAK,WAAW;AAAA,
|
|
4
|
+
"sourcesContent": ["import { createHash } from 'node:crypto'\nimport type {\n SendMessageInput,\n SendMessageResult,\n} from '@open-mercato/core/modules/communication_channels/lib/adapter'\nimport {\n BasePushChannelAdapter,\n deviceUnregisteredResult,\n MISSING_PUSH_TOKEN_RESULT,\n readPushToken,\n} from '@open-mercato/core/modules/communication_channels/lib/push-adapter'\nimport { createRefCountedClientCache } from '@open-mercato/core/modules/communication_channels/lib/refcounted-client-cache'\nimport { readPushEnvelope, resolvePushBody, type PushEnvelope } from '@open-mercato/core/modules/communication_channels/lib/push-envelope'\nimport {\n apnsCredentialsSchema,\n resolveApnsCredentials,\n type ApnsResolvedCredentials,\n} from './credentials'\n\n/**\n * The ONLY APNs signal that a device token is permanently dead: HTTP 410 with reason `Unregistered`\n * (the two always travel together \u2014 410 is Apple's irrecoverable \"remove this token\" status). A bare\n * `410` status whose reason node-apn could not parse means the same thing, so it is included. Both map\n * to the uniform `device_unregistered` sentinel so the push worker soft-deletes the device (identical\n * contract across fcm/apns/expo).\n *\n * `BadDeviceToken` is deliberately EXCLUDED. Apple returns it for a VALID token presented to the wrong\n * environment (a production token hitting the sandbox host, or vice-versa \u2014 and `production` defaults\n * to false), not only for a malformed token, and APNs gives no code to disambiguate the two. Treating\n * it as permanent would soft-delete every live iOS device in a tenant on a single environment\n * misconfiguration, with no recovery path. It \u2014 like the other non-410 reasons (`DeviceTokenNotForTopic`,\n * `TopicDisallowed`, `PayloadTooLarge`, `TooManyRequests`, `InternalServerError`, `ServiceUnavailable`,\n * `ExpiredProviderToken`) \u2014 is a transient/config failure: the delivery retries then expires, but the\n * device is KEPT so it recovers once the sender-side config is fixed.\n */\nconst PERMANENT_APNS_REASONS = new Set(['Unregistered', '410'])\n\nexport interface ApnsSendOutcome {\n ok: boolean\n /** Provider rejection reason (e.g. `Unregistered`, `BadDeviceToken`), or the stringified HTTP status\n * (e.g. `410`) when node-apn could not parse a reason from the response body. */\n reason?: string\n /** Transport-level error message (network/auth), distinct from a provider rejection. */\n error?: string\n}\n\n/**\n * A bound APNs sender for one tenant's credentials. The seam keeps `@parse/node-apn`\n * (and its HTTP/2 provider) entirely out of the adapter's control flow and tests.\n */\nexport type ApnsSender = (payload: PushEnvelope & { topic: string }, token: string) => Promise<ApnsSendOutcome>\n\nexport type ApnsSenderFactory = (credentials: ApnsResolvedCredentials) => ApnsSender\n\nlet senderFactory: ApnsSenderFactory | null = null\n\n/** Test-only seam to swap the APNs sender factory. */\nexport function setApnsSenderFactory(factory: ApnsSenderFactory | null): void {\n senderFactory = factory\n}\n\ntype ApnsProviderLike = {\n send(notification: unknown, token: string): Promise<{\n sent?: Array<{ device: string }>\n failed?: Array<{ device: string; status?: string | number; error?: Error; response?: { reason?: string } }>\n }>\n /** node-apn's Provider exposes `shutdown()` to close its HTTP/2 socket to Apple. */\n shutdown?(): void\n}\n\nfunction credentialsHash(credentials: ApnsResolvedCredentials): string {\n return createHash('sha256')\n .update(`${credentials.keyId}:${credentials.teamId}:${credentials.bundleId}:${credentials.production}:${credentials.p8Key}`)\n .digest('hex')\n .slice(0, 16)\n}\n\n/**\n * Bounds the number of live HTTP/2 providers cached at once. Each entry holds an\n * open socket to Apple, so an unbounded cache would leak a connection every time a\n * tenant rotates their `.p8` key or toggles `production` (the hash changes \u2192 a new\n * entry, while the stale provider never shuts down). LRU-evicting the least-recently\n * used provider and calling `shutdown()` keeps the connection count bounded. Disposal\n * is fenced on in-flight sends: an evicted provider is shut down only once its last\n * concurrent `send` releases (see refcounted-client-cache), so eviction never closes\n * the HTTP/2 socket out from under a send.\n */\nconst PROVIDER_CACHE_MAX = 32\nconst providerCache = createRefCountedClientCache<ApnsProviderLike>({\n max: PROVIDER_CACHE_MAX,\n dispose: (provider) => {\n try {\n provider.shutdown?.()\n } catch {\n // shutdown is best-effort; a throwing/absent shutdown must not break eviction.\n }\n },\n})\n\nasync function createProvider(credentials: ApnsResolvedCredentials): Promise<ApnsProviderLike> {\n const apnModule = await import('@parse/node-apn')\n const apn = (apnModule as { default?: unknown }).default ?? apnModule\n const Provider = (apn as { Provider: new (options: unknown) => ApnsProviderLike }).Provider\n return new Provider({\n token: { key: credentials.p8Key, keyId: credentials.keyId, teamId: credentials.teamId },\n production: credentials.production,\n })\n}\n\n/**\n * Populate an APNs `Notification` from the push envelope, branching on `silent` (background\n * content-available wake-up \u2014 no alert/sound) and applying the recognized push options. Mutates and\n * returns `note`. Extracted from the sender so it is unit-testable without `@parse/node-apn`.\n */\nexport function buildApnsNotification(\n note: Record<string, unknown>,\n payload: PushEnvelope & { topic: string },\n): Record<string, unknown> {\n const { options, silent } = payload\n note.topic = payload.topic\n note.payload = payload.data\n if (silent) {\n note.contentAvailable = 1\n note.pushType = 'background'\n note.priority = 5\n } else {\n note.alert = { title: payload.title, body: resolvePushBody(payload) }\n note.sound = options.sound ?? 'default'\n if (typeof options.badge === 'number') note.badge = options.badge\n if (options.priority === 'normal') note.priority = 5\n if (options.image) {\n note.mutableContent = true\n note.payload = { ...payload.data, imageUrl: options.image }\n }\n }\n return note\n}\n\nfunction defaultSenderFactory(credentials: ApnsResolvedCredentials): ApnsSender {\n return async (payload, token) => {\n const apnModule = await import('@parse/node-apn')\n const apn = (apnModule as { default?: unknown }).default ?? apnModule\n const Notification = (apn as { Notification: new () => Record<string, unknown> }).Notification\n const note = buildApnsNotification(new Notification(), payload)\n\n // Borrow a cached provider for the duration of the send; release() in finally keeps an evicted\n // provider's socket open until this send completes.\n const lease = await providerCache.acquire(credentialsHash(credentials), () => createProvider(credentials))\n try {\n const result = await lease.client.send(note, token)\n if (result.sent && result.sent.length > 0) return { ok: true }\n const failure = result.failed?.[0]\n if (!failure) return { ok: false, error: 'no_response' }\n if (failure.error) return { ok: false, error: failure.error.message }\n const reason = failure.response?.reason ?? (failure.status != null ? String(failure.status) : undefined)\n return { ok: false, reason }\n } finally {\n lease.release()\n }\n }\n}\n\nclass ApnsChannelAdapter extends BasePushChannelAdapter {\n readonly providerKey = 'apns'\n protected readonly credentialsSchema = apnsCredentialsSchema\n\n async sendMessage(input: SendMessageInput): Promise<SendMessageResult> {\n const token = readPushToken(input)\n if (!token) return MISSING_PUSH_TOKEN_RESULT\n\n const parsedCredentials = apnsCredentialsSchema.safeParse(input.credentials)\n if (!parsedCredentials.success) {\n return { externalMessageId: '', status: 'failed', error: 'invalid_apns_credentials' }\n }\n\n const credentials = resolveApnsCredentials(parsedCredentials.data)\n const envelope = readPushEnvelope(input.content)\n const sender = (senderFactory ?? defaultSenderFactory)(credentials)\n\n try {\n const outcome = await sender({ ...envelope, topic: credentials.bundleId }, token)\n if (outcome.ok) {\n // node-apn returns no provider message id. Return an empty id rather than any slice of the\n // push token \u2014 the worker persists externalMessageId into the admin-exposed provider_response,\n // and this module only ever surfaces the last-8 via token_snapshot, never raw token material.\n return { externalMessageId: '', status: 'sent' }\n }\n if (outcome.reason && PERMANENT_APNS_REASONS.has(outcome.reason)) {\n return deviceUnregisteredResult({ reason: outcome.reason })\n }\n return { externalMessageId: '', status: 'failed', error: outcome.error ?? outcome.reason ?? 'apns_send_failed' }\n } catch (err) {\n return { externalMessageId: '', status: 'failed', error: err instanceof Error ? err.message : String(err) }\n }\n }\n}\n\nlet cachedAdapter: ApnsChannelAdapter | null = null\n\nexport function getApnsChannelAdapter(): ApnsChannelAdapter {\n if (!cachedAdapter) cachedAdapter = new ApnsChannelAdapter()\n return cachedAdapter\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,kBAAkB;AAK3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mCAAmC;AAC5C,SAAS,kBAAkB,uBAA0C;AACrE;AAAA,EACE;AAAA,EACA;AAAA,OAEK;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,OAAO,2BAA2B;AAAA,IACtF;AAEA,UAAM,cAAc,uBAAuB,kBAAkB,IAAI;AACjE,UAAM,WAAW,iBAAiB,MAAM,OAAO;AAC/C,UAAM,UAAU,iBAAiB,sBAAsB,WAAW;AAElE,QAAI;AACF,YAAM,UAAU,MAAM,OAAO,EAAE,GAAG,UAAU,OAAO,YAAY,SAAS,GAAG,KAAK;AAChF,UAAI,QAAQ,IAAI;AAId,eAAO,EAAE,mBAAmB,IAAI,QAAQ,OAAO;AAAA,MACjD;AACA,UAAI,QAAQ,UAAU,uBAAuB,IAAI,QAAQ,MAAM,GAAG;AAChE,eAAO,yBAAyB,EAAE,QAAQ,QAAQ,OAAO,CAAC;AAAA,MAC5D;AACA,aAAO,EAAE,mBAAmB,IAAI,QAAQ,UAAU,OAAO,QAAQ,SAAS,QAAQ,UAAU,mBAAmB;AAAA,IACjH,SAAS,KAAK;AACZ,aAAO,EAAE,mBAAmB,IAAI,QAAQ,UAAU,OAAO,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,EAAE;AAAA,IAC5G;AAAA,EACF;AACF;AAEA,IAAI,gBAA2C;AAExC,SAAS,wBAA4C;AAC1D,MAAI,CAAC,cAAe,iBAAgB,IAAI,mBAAmB;AAC3D,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/jest.config.cjs
CHANGED
|
@@ -27,7 +27,7 @@ module.exports = {
|
|
|
27
27
|
],
|
|
28
28
|
},
|
|
29
29
|
transformIgnorePatterns: [
|
|
30
|
-
'node_modules/(?!(
|
|
30
|
+
'node_modules/(?!(sanitize-html|htmlparser2|domhandler|domutils|dom-serializer|domelementtype|entities|@mikro-orm|kysely)/)',
|
|
31
31
|
],
|
|
32
32
|
testMatch: ['<rootDir>/src/**/__tests__/**/*.test.(ts|tsx)'],
|
|
33
33
|
passWithNoTests: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/channel-apns",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -62,26 +62,30 @@
|
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@open-mercato/core": "0.
|
|
66
|
-
"@open-mercato/ui": "0.
|
|
65
|
+
"@open-mercato/core": "0.10.0",
|
|
66
|
+
"@open-mercato/ui": "0.10.0",
|
|
67
67
|
"@parse/node-apn": "^6.0.1"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"@mikro-orm/postgresql": "^7.0.14",
|
|
71
|
-
"@open-mercato/
|
|
71
|
+
"@open-mercato/ai-assistant": "0.10.0",
|
|
72
|
+
"@open-mercato/shared": "0.10.0",
|
|
72
73
|
"react": "^19.0.0",
|
|
73
|
-
"react-dom": "^19.0.0"
|
|
74
|
+
"react-dom": "^19.0.0",
|
|
75
|
+
"react-is": ">=18.0.0"
|
|
74
76
|
},
|
|
75
77
|
"devDependencies": {
|
|
76
|
-
"@open-mercato/
|
|
78
|
+
"@open-mercato/ai-assistant": "0.10.0",
|
|
79
|
+
"@open-mercato/shared": "0.10.0",
|
|
77
80
|
"@types/jest": "^30.0.0",
|
|
78
81
|
"@types/react": "^19.2.18",
|
|
79
82
|
"@types/react-dom": "^19.2.5",
|
|
80
83
|
"esbuild": "^0.28.2",
|
|
81
|
-
"glob": "^
|
|
84
|
+
"glob": "^14.0.6",
|
|
82
85
|
"jest": "^30.4.2",
|
|
83
86
|
"react": "19.2.8",
|
|
84
87
|
"react-dom": "19.2.8",
|
|
88
|
+
"react-is": "^19.2.8",
|
|
85
89
|
"ts-jest": "^29.4.11"
|
|
86
90
|
},
|
|
87
91
|
"publishConfig": {
|
|
@@ -91,6 +95,5 @@
|
|
|
91
95
|
"type": "git",
|
|
92
96
|
"url": "https://github.com/open-mercato/open-mercato",
|
|
93
97
|
"directory": "packages/channel-apns"
|
|
94
|
-
}
|
|
95
|
-
"stableVersion": "0.9.0"
|
|
98
|
+
}
|
|
96
99
|
}
|
|
@@ -60,7 +60,7 @@ test.describe('TC-CHANNEL-PUSH-006: real APNs adapter reaches sent with a correc
|
|
|
60
60
|
type: 'admin.custom_message',
|
|
61
61
|
title: 'Order shipped',
|
|
62
62
|
body: 'Your order is on its way',
|
|
63
|
-
pushOptions: { badge: 5, sound: 'chime.caf' },
|
|
63
|
+
pushOptions: { badge: 5, sound: 'chime.caf', image: 'https://example.com/tc-channel-push-006.png' },
|
|
64
64
|
})
|
|
65
65
|
|
|
66
66
|
await drainIntegrationQueue('events')
|
|
@@ -80,6 +80,8 @@ test.describe('TC-CHANNEL-PUSH-006: real APNs adapter reaches sent with a correc
|
|
|
80
80
|
sound: 'chime.caf',
|
|
81
81
|
})
|
|
82
82
|
expect(native.payload.aps['content-available']).toBeUndefined()
|
|
83
|
+
expect(native.payload.aps['mutable-content']).toBe(1)
|
|
84
|
+
expect(native.payload.imageUrl).toBe('https://example.com/tc-channel-push-006.png')
|
|
83
85
|
} finally {
|
|
84
86
|
await deleteDeliveriesForDevice(userDeviceId)
|
|
85
87
|
await deleteFakePushDevice(request, adminToken, userDeviceId)
|
|
@@ -98,4 +98,40 @@ describe('buildApnsNotification — golden payloads', () => {
|
|
|
98
98
|
})
|
|
99
99
|
expect(headers).toEqual({ 'apns-priority': 5, 'apns-topic': TOPIC })
|
|
100
100
|
})
|
|
101
|
+
|
|
102
|
+
it('image option sets mutable-content and carries the image url beside aps', () => {
|
|
103
|
+
const envelope = payload({ options: { image: 'https://example.com/pic.png' } })
|
|
104
|
+
const { headers, aps } = build(envelope)
|
|
105
|
+
expect(aps).toEqual({
|
|
106
|
+
type: 'orders.shipped',
|
|
107
|
+
notificationId: 'n1',
|
|
108
|
+
imageUrl: 'https://example.com/pic.png',
|
|
109
|
+
aps: {
|
|
110
|
+
alert: { title: 'Order shipped', body: 'Your order #42 is on its way' },
|
|
111
|
+
sound: 'default',
|
|
112
|
+
'mutable-content': 1,
|
|
113
|
+
},
|
|
114
|
+
})
|
|
115
|
+
expect(headers).toEqual({ 'apns-priority': 10, 'apns-topic': TOPIC })
|
|
116
|
+
expect(envelope.data).toEqual({ type: 'orders.shipped', notificationId: 'n1' })
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
it('image option wins over a data key of the same name', () => {
|
|
120
|
+
const { aps } = build(
|
|
121
|
+
payload({
|
|
122
|
+
data: { type: 'orders.shipped', imageUrl: 'https://example.com/old.png' },
|
|
123
|
+
options: { image: 'https://example.com/pic.png' },
|
|
124
|
+
}),
|
|
125
|
+
)
|
|
126
|
+
expect(aps.imageUrl).toBe('https://example.com/pic.png')
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it('silent notification ignores the image option', () => {
|
|
130
|
+
const { aps } = build(payload({ silent: true, options: { image: 'https://example.com/pic.png' } }))
|
|
131
|
+
expect(aps).toEqual({
|
|
132
|
+
type: 'orders.shipped',
|
|
133
|
+
notificationId: 'n1',
|
|
134
|
+
aps: { 'content-available': 1 },
|
|
135
|
+
})
|
|
136
|
+
})
|
|
101
137
|
})
|
|
@@ -128,6 +128,10 @@ export function buildApnsNotification(
|
|
|
128
128
|
note.sound = options.sound ?? 'default'
|
|
129
129
|
if (typeof options.badge === 'number') note.badge = options.badge
|
|
130
130
|
if (options.priority === 'normal') note.priority = 5
|
|
131
|
+
if (options.image) {
|
|
132
|
+
note.mutableContent = true
|
|
133
|
+
note.payload = { ...payload.data, imageUrl: options.image }
|
|
134
|
+
}
|
|
131
135
|
}
|
|
132
136
|
return note
|
|
133
137
|
}
|