{"id":13990887,"url":"https://github.com/AndrewBarba/apns2","last_synced_at":"2025-07-22T13:31:51.909Z","repository":{"id":9270557,"uuid":"61453313","full_name":"AndrewBarba/apns2","owner":"AndrewBarba","description":"Node client for connecting to Apple's Push Notification Service using the new HTTP/2 protocol with JSON web tokens","archived":false,"fork":false,"pushed_at":"2024-05-28T19:59:05.000Z","size":390,"stargazers_count":106,"open_issues_count":2,"forks_count":31,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-05-29T10:45:38.403Z","etag":null,"topics":["apns","apple","http2","ios","nodejs","promise","push-notifications"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AndrewBarba.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-18T21:29:01.000Z","updated_at":"2024-06-19T00:24:17.359Z","dependencies_parsed_at":"2023-02-19T02:50:17.566Z","dependency_job_id":"6a62c03c-32ce-456e-bc47-02ae476c4655","html_url":"https://github.com/AndrewBarba/apns2","commit_stats":{"total_commits":169,"total_committers":11,"mean_commits":"15.363636363636363","dds":0.2248520710059172,"last_synced_commit":"a69cdb34afb1cb03a4c59ac5d4b6c50f1d6bc597"},"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndrewBarba%2Fapns2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndrewBarba%2Fapns2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndrewBarba%2Fapns2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndrewBarba%2Fapns2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AndrewBarba","download_url":"https://codeload.github.com/AndrewBarba/apns2/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226867969,"owners_count":17694817,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apns","apple","http2","ios","nodejs","promise","push-notifications"],"created_at":"2024-08-09T13:03:27.962Z","updated_at":"2024-11-29T10:32:00.047Z","avatar_url":"https://github.com/AndrewBarba.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# apns2\n\n[![npm version](https://badge.fury.io/js/apns2.svg)](https://badge.fury.io/js/apns2)\n[![Twitter](https://img.shields.io/badge/twitter-@andrew_barba-blue.svg?style=flat)](http://twitter.com/andrew_barba)\n\nNode client for connecting to Apple's Push Notification Service using the new HTTP/2 protocol with JSON web tokens.\n\n---\n\n## Create Client\n\nCreate an APNS client using a signing key:\n\n```typescript\nimport { ApnsClient } from 'apns2'\n\nconst client = new ApnsClient({\n  team: `TFLP87PW54`,\n  keyId: `123ABC456`,\n  signingKey: fs.readFileSync(`${__dirname}/path/to/auth.p8`),\n  defaultTopic: `com.tablelist.Tablelist`,\n  requestTimeout: 0, // optional, Default: 0 (without timeout)\n  keepAlive: true, // optional, Default: 5000\n})\n```\n\n## Sending Notifications\n\n#### Basic\n\nSend a basic notification with message:\n\n```typescript\nimport { Notification } from 'apns2'\n\nconst bn = new Notification(deviceToken, { alert: 'Hello, World' })\n\ntry {\n  await client.send(bn)\n} catch (err) {\n  console.error(err.reason)\n}\n```\n\nSend a basic notification with message and options:\n\n```typescript\nimport { Notification } from 'apns2'\n\nconst bn = new Notification(deviceToken, {\n  alert: 'Hello, World',\n  badge: 4,\n  data: {\n    userId: user.getUserId\n  }\n})\n\ntry {\n  await client.send(bn)\n} catch (err) {\n  console.error(err.reason)\n}\n```\n\n#### Silent\n\nSend a silent notification using `content-available` key:\n\n```typescript\nimport { SilentNotification } from 'apns2'\n\nconst sn = new SilentNotification(deviceToken)\n\ntry {\n  await client.send(sn)\n} catch (err) {\n  console.error(err.reason)\n}\n```\n\nNote: [Apple recommends](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app#2980040) that no options other than the `content-available` flag be sent in order for a notification to truly be silent and wake up your app in the background. Therefore this class does not accept any additional options in the constructor.\n\n#### Many\n\nSend multiple notifications concurrently:\n\n```typescript\nimport { Notification } from 'apns2'\n\nconst notifications = [\n  new Notification(deviceToken1, { alert: 'Hello, World' }),\n  new Notification(deviceToken2, { alert: 'Hello, World' })\n]\n\ntry {\n  await client.sendMany(notifications)\n} catch (err) {\n  console.error(err.reason)\n}\n```\n\n#### Advanced\n\nFor complete control over the push notification packet use the base `Notification` class:\n\n```typescript\nimport { Notification } from 'apns2'\n\nconst notification = new Notification(deviceToken, {\n  aps: { ... }\n})\n\ntry {\n  await client.send(notification)\n} catch(err) {\n  console.error(err.reason)\n}\n```\n\nAvailable options can be found at [APNS Payload Options](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification#2943363)\n\n## Error Handling\n\nAll errors are defined in `./lib/errors.js` and come directly from [APNS Table 4](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/handling_notification_responses_from_apns#3394535)\n\nYou can easily listen for these errors by attaching an error handler to the APNS client:\n\n```typescript\nimport { Errors } from 'apns2'\n\n// Listen for a specific error\nclient.on(Errors.badDeviceToken, (err) =\u003e {\n  // Handle accordingly...\n  // Perhaps delete token from your database\n  console.error(err.reason, err.statusCode, err.notification.deviceToken)\n})\n\n// Listen for any error\nclient.on(Errors.error, (err) =\u003e {\n  console.error(err.reason, err.statusCode, err.notification.deviceToken)\n})\n```\n## Environments\n\nBy default the APNS client connects to the production push notification server. This is identical to passing in the options:\n\n```typescript\nconst client = new ApnsClient({\n  host: 'api.push.apple.com'\n  ...\n})\n```\n\nTo connect to the development push notification server, pass the options:\n\n```typescript\nconst client = new ApnsClient({\n  host: 'api.sandbox.push.apple.com'\n  ...\n})\n```\n\n## Requirements\n\n`apns2` requires Node.js v16 or later\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAndrewBarba%2Fapns2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAndrewBarba%2Fapns2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAndrewBarba%2Fapns2/lists"}