From c4c397458b9087746f5bd4a503e76e370ccebe3c Mon Sep 17 00:00:00 2001 From: umair Date: Thu, 12 Mar 2026 23:00:57 +0000 Subject: [PATCH 1/8] Add push notification commands for device management, channel subscriptions, publishing, and configuration --- README.md | 705 ++++++++++++++++-- docs/Project-Structure.md | 8 +- src/base-command.ts | 3 + src/commands/apps/set-apns-p12.ts | 6 + src/commands/push/batch-publish.ts | 179 +++++ src/commands/push/channels/index.ts | 15 + src/commands/push/channels/list-channels.ts | 77 ++ src/commands/push/channels/list.ts | 107 +++ src/commands/push/channels/remove-where.ts | 94 +++ src/commands/push/channels/remove.ts | 110 +++ src/commands/push/channels/save.ts | 85 +++ src/commands/push/config/clear-apns.ts | 121 +++ src/commands/push/config/clear-fcm.ts | 110 +++ src/commands/push/config/index.ts | 15 + src/commands/push/config/set-apns.ts | 172 +++++ src/commands/push/config/set-fcm.ts | 101 +++ src/commands/push/config/show.ts | 134 ++++ src/commands/push/devices/get.ts | 92 +++ src/commands/push/devices/index.ts | 14 + src/commands/push/devices/list.ts | 117 +++ src/commands/push/devices/remove-where.ts | 88 +++ src/commands/push/devices/remove.ts | 77 ++ src/commands/push/devices/save.ts | 238 ++++++ src/commands/push/index.ts | 15 + src/commands/push/publish.ts | 197 +++++ src/services/control-api.ts | 15 +- src/utils/output.ts | 18 + test/e2e/push/channels-e2e.test.ts | 177 +++++ test/e2e/push/devices-e2e.test.ts | 496 ++++++++++++ test/e2e/push/publish-e2e.test.ts | 316 ++++++++ test/e2e/push/push-config-e2e.test.ts | 446 +++++++++++ test/fixtures/push/test-apns-key.p8 | 5 + .../push/test-fcm-service-account.json | 10 + test/helpers/mock-ably-rest.ts | 6 + test/unit/commands/push/batch-publish.test.ts | 128 ++++ .../push/channels/list-channels.test.ts | 86 +++ test/unit/commands/push/channels/list.test.ts | 100 +++ .../push/channels/remove-where.test.ts | 85 +++ .../commands/push/channels/remove.test.ts | 102 +++ test/unit/commands/push/channels/save.test.ts | 122 +++ .../commands/push/config/clear-apns.test.ts | 160 ++++ .../commands/push/config/clear-fcm.test.ts | 160 ++++ .../commands/push/config/set-apns.test.ts | 248 ++++++ .../unit/commands/push/config/set-fcm.test.ts | 165 ++++ test/unit/commands/push/config/show.test.ts | 221 ++++++ test/unit/commands/push/devices/get.test.ts | 97 +++ test/unit/commands/push/devices/list.test.ts | 128 ++++ .../push/devices/remove-where.test.ts | 82 ++ .../unit/commands/push/devices/remove.test.ts | 69 ++ test/unit/commands/push/devices/save.test.ts | 252 +++++++ test/unit/commands/push/publish.test.ts | 136 ++++ 51 files changed, 6660 insertions(+), 50 deletions(-) create mode 100644 src/commands/push/batch-publish.ts create mode 100644 src/commands/push/channels/index.ts create mode 100644 src/commands/push/channels/list-channels.ts create mode 100644 src/commands/push/channels/list.ts create mode 100644 src/commands/push/channels/remove-where.ts create mode 100644 src/commands/push/channels/remove.ts create mode 100644 src/commands/push/channels/save.ts create mode 100644 src/commands/push/config/clear-apns.ts create mode 100644 src/commands/push/config/clear-fcm.ts create mode 100644 src/commands/push/config/index.ts create mode 100644 src/commands/push/config/set-apns.ts create mode 100644 src/commands/push/config/set-fcm.ts create mode 100644 src/commands/push/config/show.ts create mode 100644 src/commands/push/devices/get.ts create mode 100644 src/commands/push/devices/index.ts create mode 100644 src/commands/push/devices/list.ts create mode 100644 src/commands/push/devices/remove-where.ts create mode 100644 src/commands/push/devices/remove.ts create mode 100644 src/commands/push/devices/save.ts create mode 100644 src/commands/push/index.ts create mode 100644 src/commands/push/publish.ts create mode 100644 test/e2e/push/channels-e2e.test.ts create mode 100644 test/e2e/push/devices-e2e.test.ts create mode 100644 test/e2e/push/publish-e2e.test.ts create mode 100644 test/e2e/push/push-config-e2e.test.ts create mode 100644 test/fixtures/push/test-apns-key.p8 create mode 100644 test/fixtures/push/test-fcm-service-account.json create mode 100644 test/unit/commands/push/batch-publish.test.ts create mode 100644 test/unit/commands/push/channels/list-channels.test.ts create mode 100644 test/unit/commands/push/channels/list.test.ts create mode 100644 test/unit/commands/push/channels/remove-where.test.ts create mode 100644 test/unit/commands/push/channels/remove.test.ts create mode 100644 test/unit/commands/push/channels/save.test.ts create mode 100644 test/unit/commands/push/config/clear-apns.test.ts create mode 100644 test/unit/commands/push/config/clear-fcm.test.ts create mode 100644 test/unit/commands/push/config/set-apns.test.ts create mode 100644 test/unit/commands/push/config/set-fcm.test.ts create mode 100644 test/unit/commands/push/config/show.test.ts create mode 100644 test/unit/commands/push/devices/get.test.ts create mode 100644 test/unit/commands/push/devices/list.test.ts create mode 100644 test/unit/commands/push/devices/remove-where.test.ts create mode 100644 test/unit/commands/push/devices/remove.test.ts create mode 100644 test/unit/commands/push/devices/save.test.ts create mode 100644 test/unit/commands/push/publish.test.ts diff --git a/README.md b/README.md index 9c27fc82..a7c13a10 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,6 @@ $ ably-interactive * [`ably apps rules delete NAMEORID`](#ably-apps-rules-delete-nameorid) * [`ably apps rules list`](#ably-apps-rules-list) * [`ably apps rules update NAMEORID`](#ably-apps-rules-update-nameorid) -* [`ably apps set-apns-p12 ID`](#ably-apps-set-apns-p12-id) * [`ably apps switch [APPID]`](#ably-apps-switch-appid) * [`ably apps update ID`](#ably-apps-update-id) * [`ably auth`](#ably-auth) @@ -150,6 +149,27 @@ $ ably-interactive * [`ably logs push history`](#ably-logs-push-history) * [`ably logs push subscribe`](#ably-logs-push-subscribe) * [`ably logs subscribe`](#ably-logs-subscribe) +* [`ably push`](#ably-push) +* [`ably push batch-publish`](#ably-push-batch-publish) +* [`ably push channels`](#ably-push-channels) +* [`ably push channels list`](#ably-push-channels-list) +* [`ably push channels list-channels`](#ably-push-channels-list-channels) +* [`ably push channels remove`](#ably-push-channels-remove) +* [`ably push channels remove-where`](#ably-push-channels-remove-where) +* [`ably push channels save`](#ably-push-channels-save) +* [`ably push config`](#ably-push-config) +* [`ably push config clear-apns`](#ably-push-config-clear-apns) +* [`ably push config clear-fcm`](#ably-push-config-clear-fcm) +* [`ably push config set-apns`](#ably-push-config-set-apns) +* [`ably push config set-fcm`](#ably-push-config-set-fcm) +* [`ably push config show`](#ably-push-config-show) +* [`ably push devices`](#ably-push-devices) +* [`ably push devices get DEVICE-ID`](#ably-push-devices-get-device-id) +* [`ably push devices list`](#ably-push-devices-list) +* [`ably push devices remove DEVICE-ID`](#ably-push-devices-remove-device-id) +* [`ably push devices remove-where`](#ably-push-devices-remove-where) +* [`ably push devices save`](#ably-push-devices-save) +* [`ably push publish`](#ably-push-publish) * [`ably queues`](#ably-queues) * [`ably queues create`](#ably-queues-create) * [`ably queues delete QUEUEID`](#ably-queues-delete-queueid) @@ -409,14 +429,13 @@ EXAMPLES $ ably apps switch my-app COMMANDS - ably apps create Create a new app - ably apps current Show the currently selected app - ably apps delete Delete an app - ably apps list List all apps in the current account - ably apps rules Manage Ably channel rules (namespaces) - ably apps set-apns-p12 Upload Apple Push Notification Service P12 certificate for an app - ably apps switch Switch to a different Ably app - ably apps update Update an app + ably apps create Create a new app + ably apps current Show the currently selected app + ably apps delete Delete an app + ably apps list List all apps in the current account + ably apps rules Manage Ably channel rules (namespaces) + ably apps switch Switch to a different Ably app + ably apps update Update an app ``` _See code: [src/commands/apps/index.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/apps/index.ts)_ @@ -729,41 +748,6 @@ EXAMPLES _See code: [src/commands/apps/rules/update.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/apps/rules/update.ts)_ -## `ably apps set-apns-p12 ID` - -Upload Apple Push Notification Service P12 certificate for an app - -``` -USAGE - $ ably apps set-apns-p12 ID --certificate [-v] [--json | --pretty-json] [--password ] - [--use-for-sandbox] - -ARGUMENTS - ID App ID to set the APNS certificate for - -FLAGS - -v, --verbose Output verbose logs - --certificate= (required) Path to the P12 certificate file - --json Output in JSON format - --password= Password for the P12 certificate - --pretty-json Output in colorized JSON format - --use-for-sandbox Whether to use this certificate for the APNS sandbox environment - -DESCRIPTION - Upload Apple Push Notification Service P12 certificate for an app - -EXAMPLES - $ ably apps set-apns-p12 app-id --certificate /path/to/certificate.p12 - - $ ably apps set-apns-p12 app-id --certificate /path/to/certificate.p12 --password "YOUR_CERTIFICATE_PASSWORD" - - $ ably apps set-apns-p12 app-id --certificate /path/to/certificate.p12 --use-for-sandbox - - $ ably apps set-apns-p12 app-id --certificate /path/to/certificate.p12 --json -``` - -_See code: [src/commands/apps/set-apns-p12.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/apps/set-apns-p12.ts)_ - ## `ably apps switch [APPID]` Switch to a different Ably app @@ -2853,6 +2837,639 @@ EXAMPLES _See code: [src/commands/logs/subscribe.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/logs/subscribe.ts)_ +## `ably push` + +Manage push notifications + +``` +USAGE + $ ably push + +DESCRIPTION + Manage push notifications + +EXAMPLES + $ ably push publish --device-id device1 --title Hello --body World + + $ ably push devices list + + $ ably push channels list --channel my-channel + + $ ably push config show + +COMMANDS + ably push batch-publish Publish push notifications to multiple recipients in a batch + ably push channels Manage push notification channel subscriptions + ably push config Manage push notification configuration (APNs, FCM) + ably push devices Manage push notification device registrations + ably push publish Publish a push notification to a device or client +``` + +_See code: [src/commands/push/index.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/push/index.ts)_ + +## `ably push batch-publish` + +Publish push notifications to multiple recipients in a batch + +``` +USAGE + $ ably push batch-publish --payload [-v] [--json | --pretty-json] + +FLAGS + -v, --verbose Output verbose logs + --json Output in JSON format + --payload= (required) Batch payload as JSON array, @filepath, or - for stdin + --pretty-json Output in colorized JSON format + +DESCRIPTION + Publish push notifications to multiple recipients in a batch + +EXAMPLES + $ ably push batch-publish --payload '[{"recipient":{"deviceId":"dev1"},"notification":{"title":"Hello"}}]' + + $ ably push batch-publish --payload @batch.json + + cat batch.json | ably push batch-publish --payload - + + $ ably push batch-publish --payload @batch.json --json +``` + +_See code: [src/commands/push/batch-publish.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/push/batch-publish.ts)_ + +## `ably push channels` + +Manage push notification channel subscriptions + +``` +USAGE + $ ably push channels + +DESCRIPTION + Manage push notification channel subscriptions + +EXAMPLES + $ ably push channels list --channel my-channel + + $ ably push channels save --channel my-channel --device-id device-123 + + $ ably push channels list-channels +``` + +_See code: [src/commands/push/channels/index.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/push/channels/index.ts)_ + +## `ably push channels list` + +List push channel subscriptions + +``` +USAGE + $ ably push channels list --channel [-v] [--json | --pretty-json] [--device-id ] [--client-id ] + [--limit ] + +FLAGS + -v, --verbose Output verbose logs + --channel= (required) Channel name to list subscriptions for + --client-id= Filter by client ID + --device-id= Filter by device ID + --json Output in JSON format + --limit= [default: 100] Maximum number of results to return (default: 100) + --pretty-json Output in colorized JSON format + +DESCRIPTION + List push channel subscriptions + +EXAMPLES + $ ably push channels list --channel my-channel + + $ ably push channels list --channel my-channel --device-id device-123 + + $ ably push channels list --channel my-channel --json +``` + +_See code: [src/commands/push/channels/list.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/push/channels/list.ts)_ + +## `ably push channels list-channels` + +List channels with push subscriptions + +``` +USAGE + $ ably push channels list-channels [-v] [--json | --pretty-json] [--limit ] + +FLAGS + -v, --verbose Output verbose logs + --json Output in JSON format + --limit= [default: 100] Maximum number of results to return (default: 100) + --pretty-json Output in colorized JSON format + +DESCRIPTION + List channels with push subscriptions + +EXAMPLES + $ ably push channels list-channels + + $ ably push channels list-channels --limit 50 + + $ ably push channels list-channels --json +``` + +_See code: [src/commands/push/channels/list-channels.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/push/channels/list-channels.ts)_ + +## `ably push channels remove` + +Remove a push channel subscription + +``` +USAGE + $ ably push channels remove --channel [-v] [--json | --pretty-json] [--device-id | --client-id ] + [-f] + +FLAGS + -f, --force Skip confirmation prompt + -v, --verbose Output verbose logs + --channel= (required) Channel name to unsubscribe from + --client-id= Client ID to unsubscribe + --device-id= Device ID to unsubscribe + --json Output in JSON format + --pretty-json Output in colorized JSON format + +DESCRIPTION + Remove a push channel subscription + +EXAMPLES + $ ably push channels remove --channel my-channel --device-id device-123 + + $ ably push channels remove --channel my-channel --client-id client-1 --force + + $ ably push channels remove --channel my-channel --device-id device-123 --json +``` + +_See code: [src/commands/push/channels/remove.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/push/channels/remove.ts)_ + +## `ably push channels remove-where` + +Remove push channel subscriptions matching filter criteria + +``` +USAGE + $ ably push channels remove-where --channel [-v] [--json | --pretty-json] [--device-id ] [--client-id ] + [-f] + +FLAGS + -f, --force Skip confirmation prompt + -v, --verbose Output verbose logs + --channel= (required) Channel name to filter by + --client-id= Filter by client ID + --device-id= Filter by device ID + --json Output in JSON format + --pretty-json Output in colorized JSON format + +DESCRIPTION + Remove push channel subscriptions matching filter criteria + +EXAMPLES + $ ably push channels remove-where --channel my-channel + + $ ably push channels remove-where --channel my-channel --device-id device-123 --force + + $ ably push channels remove-where --channel my-channel --json +``` + +_See code: [src/commands/push/channels/remove-where.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/push/channels/remove-where.ts)_ + +## `ably push channels save` + +Subscribe a device or client to push notifications on a channel + +``` +USAGE + $ ably push channels save --channel [-v] [--json | --pretty-json] [--device-id | --client-id ] + +FLAGS + -v, --verbose Output verbose logs + --channel= (required) Channel name to subscribe to + --client-id= Client ID to subscribe + --device-id= Device ID to subscribe + --json Output in JSON format + --pretty-json Output in colorized JSON format + +DESCRIPTION + Subscribe a device or client to push notifications on a channel + +EXAMPLES + $ ably push channels save --channel my-channel --device-id device-123 + + $ ably push channels save --channel my-channel --client-id client-1 + + $ ably push channels save --channel my-channel --device-id device-123 --json +``` + +_See code: [src/commands/push/channels/save.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/push/channels/save.ts)_ + +## `ably push config` + +Manage push notification configuration (APNs, FCM) + +``` +USAGE + $ ably push config + +DESCRIPTION + Manage push notification configuration (APNs, FCM) + +EXAMPLES + $ ably push config show + + $ ably push config set-apns --certificate /path/to/cert.p12 + + $ ably push config set-fcm --service-account /path/to/service-account.json +``` + +_See code: [src/commands/push/config/index.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/push/config/index.ts)_ + +## `ably push config clear-apns` + +Clear APNs push notification configuration for an app + +``` +USAGE + $ ably push config clear-apns [-v] [--json | --pretty-json] [--app ] [-f] + +FLAGS + -f, --force Skip confirmation prompt + -v, --verbose Output verbose logs + --app= The app ID or name (defaults to current app) + --json Output in JSON format + --pretty-json Output in colorized JSON format + +DESCRIPTION + Clear APNs push notification configuration for an app + +EXAMPLES + $ ably push config clear-apns + + $ ably push config clear-apns --app my-app --force + + $ ably push config clear-apns --force --json +``` + +_See code: [src/commands/push/config/clear-apns.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/push/config/clear-apns.ts)_ + +## `ably push config clear-fcm` + +Clear FCM push notification configuration for an app + +``` +USAGE + $ ably push config clear-fcm [-v] [--json | --pretty-json] [--app ] [-f] + +FLAGS + -f, --force Skip confirmation prompt + -v, --verbose Output verbose logs + --app= The app ID or name (defaults to current app) + --json Output in JSON format + --pretty-json Output in colorized JSON format + +DESCRIPTION + Clear FCM push notification configuration for an app + +EXAMPLES + $ ably push config clear-fcm + + $ ably push config clear-fcm --app my-app --force + + $ ably push config clear-fcm --force --json +``` + +_See code: [src/commands/push/config/clear-fcm.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/push/config/clear-fcm.ts)_ + +## `ably push config set-apns` + +Configure APNs push notifications for an app + +``` +USAGE + $ ably push config set-apns [-v] [--json | --pretty-json] [--app ] [--certificate | --key-file ] + [--key-id ] [--password ] [--sandbox] [--team-id ] [--topic ] + +FLAGS + -v, --verbose Output verbose logs + --app= The app ID or name (defaults to current app) + --certificate= Path to the P12 certificate file + --json Output in JSON format + --key-file= Path to the P8 key file + --key-id= The APNs key ID (required for P8) + --password= Password for the P12 certificate + --pretty-json Output in colorized JSON format + --sandbox Use the APNs sandbox environment + --team-id= The Apple Developer Team ID (required for P8) + --topic= The APNs topic / bundle ID (required for P8) + +DESCRIPTION + Configure APNs push notifications for an app + +EXAMPLES + $ ably push config set-apns --certificate /path/to/cert.p12 + + $ ably push config set-apns --certificate /path/to/cert.p12 --password secret --sandbox + + $ ably push config set-apns --key-file /path/to/key.p8 --key-id ABC123 --team-id DEF456 --topic com.example.app + + $ ably push config set-apns --certificate /path/to/cert.p12 --json +``` + +_See code: [src/commands/push/config/set-apns.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/push/config/set-apns.ts)_ + +## `ably push config set-fcm` + +Configure FCM push notifications for an app + +``` +USAGE + $ ably push config set-fcm --service-account [-v] [--json | --pretty-json] [--app ] + +FLAGS + -v, --verbose Output verbose logs + --app= The app ID or name (defaults to current app) + --json Output in JSON format + --pretty-json Output in colorized JSON format + --service-account= (required) Path to the FCM service account JSON file + +DESCRIPTION + Configure FCM push notifications for an app + +EXAMPLES + $ ably push config set-fcm --service-account /path/to/service-account.json + + $ ably push config set-fcm --service-account /path/to/service-account.json --app my-app + + $ ably push config set-fcm --service-account /path/to/service-account.json --json +``` + +_See code: [src/commands/push/config/set-fcm.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/push/config/set-fcm.ts)_ + +## `ably push config show` + +Show push notification configuration for an app + +``` +USAGE + $ ably push config show [-v] [--json | --pretty-json] [--app ] + +FLAGS + -v, --verbose Output verbose logs + --app= The app ID or name (defaults to current app) + --json Output in JSON format + --pretty-json Output in colorized JSON format + +DESCRIPTION + Show push notification configuration for an app + +EXAMPLES + $ ably push config show + + $ ably push config show --app my-app + + $ ably push config show --json +``` + +_See code: [src/commands/push/config/show.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/push/config/show.ts)_ + +## `ably push devices` + +Manage push notification device registrations + +``` +USAGE + $ ably push devices + +DESCRIPTION + Manage push notification device registrations + +EXAMPLES + $ ably push devices list + + $ ably push devices get device-123 + + $ ably push devices save --id device-123 --platform ios --form-factor phone --transport-type apns --device-token token123 +``` + +_See code: [src/commands/push/devices/index.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/push/devices/index.ts)_ + +## `ably push devices get DEVICE-ID` + +Get details of a push device registration + +``` +USAGE + $ ably push devices get DEVICE-ID [-v] [--json | --pretty-json] + +ARGUMENTS + DEVICE-ID The device ID to retrieve + +FLAGS + -v, --verbose Output verbose logs + --json Output in JSON format + --pretty-json Output in colorized JSON format + +DESCRIPTION + Get details of a push device registration + +EXAMPLES + $ ably push devices get device-123 + + $ ably push devices get device-123 --json +``` + +_See code: [src/commands/push/devices/get.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/push/devices/get.ts)_ + +## `ably push devices list` + +List push device registrations + +``` +USAGE + $ ably push devices list [-v] [--json | --pretty-json] [--device-id ] [--client-id ] [--state + ACTIVE|FAILING|FAILED] [--limit ] + +FLAGS + -v, --verbose Output verbose logs + --client-id= Filter by client ID + --device-id= Filter by device ID + --json Output in JSON format + --limit= [default: 100] Maximum number of results to return (default: 100) + --pretty-json Output in colorized JSON format + --state=