|
| 1 | +# Copilot Instructions for AI Agents |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +This repository implements a Node.js module for sending push notifications across multiple platforms: Apple (APN), Google (GCM/FCM), Windows (WNS), Amazon (ADM), and Web-Push. The core logic is in `lib/` and `src/`, with each platform handled by a dedicated file (e.g., `sendAPN.js`, `sendFCM.js`). |
| 6 | + |
| 7 | +## Architecture & Data Flow |
| 8 | + |
| 9 | +- **Entry Point:** Use `PushNotifications` from `lib/index.js` or `src/index.js`. |
| 10 | +- **Settings:** Each platform's credentials/config are passed to the constructor. See the example in `README.md`. |
| 11 | +- **Sending:** The main method is `push.send(registrationIds, data, callback)` or as a Promise. It auto-detects device type and routes to the correct sender. |
| 12 | +- **Platform Senders:** Each sender (e.g., `sendAPN.js`, `sendFCM.js`) implements the logic for its platform. Shared utilities are in `lib/utils/` and `src/utils/`. |
| 13 | +- **RegId Detection:** Device type is inferred from the registration ID structure. See `PN.getPushMethodByRegId` for details. |
| 14 | + |
| 15 | +## Developer Workflows |
| 16 | + |
| 17 | +- **Install:** `npm install` |
| 18 | +- **Test:** Run all tests with `npm test`. Tests are in `test/` and cover basic flows and platform-specific cases. |
| 19 | +- **Debug:** Use the callback or Promise error/result from `push.send`. Each result object includes method, success/failure counts, and error details per device. |
| 20 | +- **Build:** No build step required for basic usage. ES6 is used, but compatible with ES5 via Babel if needed. |
| 21 | + |
| 22 | +## Conventions & Patterns |
| 23 | + |
| 24 | +- **Platform-specific files:** Each push service has its own file for isolation and clarity. |
| 25 | +- **Unified Data Model:** The `data` object for notifications is normalized across platforms. See `README.md` for all supported fields. |
| 26 | +- **Error Handling:** Errors are unified and returned in the result array from `push.send`. |
| 27 | +- **RegId Format:** Prefer object format for registration IDs (`{id, type}`), but string format is supported for legacy reasons. |
| 28 | +- **Chunking:** Android tokens are chunked in batches of 1,000 automatically. |
| 29 | +- **Constants:** Use constants from `constants.js` for platform types. |
| 30 | + |
| 31 | +## Integration Points |
| 32 | + |
| 33 | +- **External Libraries:** |
| 34 | + - APN: `node-apn` |
| 35 | + - FCM: `firebase-admin` |
| 36 | + - GCM: `node-gcm` |
| 37 | + - ADM: `node-adm` |
| 38 | + - WNS: `wns` |
| 39 | + - Web-Push: `web-push` |
| 40 | +- **Credentials:** Place service account keys and certificates in appropriate locations (see `README.md` for examples). |
| 41 | + |
| 42 | +## Key Files & Directories |
| 43 | + |
| 44 | +- `lib/` and `src/`: Main implementation (mirrored structure) |
| 45 | +- `test/`: Test cases and sample credentials |
| 46 | +- `README.md`: Usage, configuration, and data model reference |
| 47 | + |
| 48 | +## Example Usage |
| 49 | + |
| 50 | +See `README.md` for a full example of settings, registration ID formats, and sending notifications. |
| 51 | + |
| 52 | +--- |
| 53 | + |
| 54 | +For unclear or incomplete sections, please provide feedback or specify which workflows, patterns, or integrations need further documentation. |
0 commit comments