command_tower 0.4.0 → 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.
- checksums.yaml +4 -4
- data/README.md +102 -29
- data/app/auth/command_tower/auth/auth_context.rb +36 -0
- data/app/auth/command_tower/auth/password_recovery_session_context.rb +11 -0
- data/app/auth/command_tower/auth/signup_session_context.rb +11 -0
- data/app/controllers/command_tower/admin/messaging/announcements_controller.rb +34 -0
- data/app/controllers/command_tower/application_controller.rb +80 -14
- data/app/controllers/command_tower/auth/email/availability_controller.rb +35 -0
- data/app/controllers/command_tower/auth/email_verification/send_controller.rb +24 -0
- data/app/controllers/command_tower/auth/email_verification/verify_controller.rb +41 -0
- data/app/controllers/command_tower/auth/identity_policy_controller.rb +14 -0
- data/app/controllers/command_tower/auth/logout_controller.rb +14 -0
- data/app/controllers/command_tower/auth/password_recovery_session/create_controller.rb +17 -0
- data/app/controllers/command_tower/auth/password_reset/reset_controller.rb +35 -0
- data/app/controllers/command_tower/auth/password_reset/send_controller.rb +40 -0
- data/app/controllers/command_tower/auth/password_reset/validate_controller.rb +35 -0
- data/app/controllers/command_tower/auth/plain_text/login_controller.rb +22 -0
- data/app/controllers/command_tower/auth/register_controller.rb +33 -0
- data/app/controllers/command_tower/auth/session_controller.rb +21 -0
- data/app/controllers/command_tower/auth/signup_session/create_controller.rb +17 -0
- data/app/controllers/command_tower/auth/username/availability_controller.rb +35 -0
- data/app/controllers/command_tower/me/inbox_controller.rb +85 -0
- data/app/controllers/command_tower/me/name_controller.rb +37 -0
- data/app/controllers/command_tower/me/password_controller.rb +37 -0
- data/app/controllers/command_tower/me/phone_controller.rb +44 -0
- data/app/controllers/command_tower/me/phone_verification/verifications_controller.rb +23 -0
- data/app/controllers/command_tower/me/phone_verification/verify_controller.rb +34 -0
- data/app/controllers/command_tower/me/preferences_controller.rb +46 -0
- data/app/controllers/command_tower/me/pushover/verifications_controller.rb +23 -0
- data/app/controllers/command_tower/me/pushover_controller.rb +66 -0
- data/app/controllers/command_tower/me_controller.rb +19 -0
- data/app/controllers/command_tower/profile_controller.rb +19 -0
- data/app/controllers/concerns/command_tower/api/application_response_renderer.rb +82 -0
- data/app/controllers/concerns/command_tower/api/deserializer_failure_details.rb +22 -0
- data/app/controllers/concerns/command_tower/auth/authentication_boundary.rb +34 -0
- data/app/controllers/concerns/command_tower/auth/authorization_boundary.rb +26 -0
- data/app/controllers/concerns/command_tower/auth/invalid_credentials_deserializer_renderer.rb +23 -0
- data/app/controllers/concerns/command_tower/auth/password_recovery_session_boundary.rb +29 -0
- data/app/controllers/concerns/command_tower/auth/signup_session_boundary.rb +29 -0
- data/app/deserializers/command_tower/deserializers/admin/messaging/create_announcement_deserializer.rb +106 -0
- data/app/deserializers/command_tower/deserializers/application_deserializer.rb +148 -0
- data/app/deserializers/command_tower/deserializers/auth/email_availability_deserializer.rb +19 -0
- data/app/deserializers/command_tower/deserializers/auth/email_verification/verify_deserializer.rb +21 -0
- data/app/deserializers/command_tower/deserializers/auth/password_reset/reset_deserializer.rb +31 -0
- data/app/deserializers/command_tower/deserializers/auth/password_reset/send_deserializer.rb +21 -0
- data/app/deserializers/command_tower/deserializers/auth/password_reset/validate_deserializer.rb +23 -0
- data/app/deserializers/command_tower/deserializers/auth/plain_text/login_deserializer.rb +24 -0
- data/app/deserializers/command_tower/deserializers/auth/register_deserializer.rb +42 -0
- data/app/deserializers/command_tower/deserializers/auth/username_availability_deserializer.rb +19 -0
- data/app/deserializers/command_tower/deserializers/clients/errors.rb +45 -0
- data/app/deserializers/command_tower/deserializers/clients/missing.rb +10 -0
- data/app/deserializers/command_tower/deserializers/clients/payload.rb +21 -0
- data/app/deserializers/command_tower/deserializers/clients/result.rb +122 -0
- data/app/deserializers/command_tower/deserializers/clients/types.rb +192 -0
- data/app/deserializers/command_tower/deserializers/coercion_result.rb +35 -0
- data/app/deserializers/command_tower/deserializers/failure.rb +14 -0
- data/app/deserializers/command_tower/deserializers/me/change_password_deserializer.rb +41 -0
- data/app/deserializers/command_tower/deserializers/me/phone_verification/verify_deserializer.rb +29 -0
- data/app/deserializers/command_tower/deserializers/me/pushover/credentials_deserializer.rb +31 -0
- data/app/deserializers/command_tower/deserializers/me/update_name_deserializer.rb +22 -0
- data/app/deserializers/command_tower/deserializers/me/update_phone_deserializer.rb +22 -0
- data/app/deserializers/command_tower/deserializers/messaging/inbox.rb +77 -0
- data/app/deserializers/command_tower/deserializers/messaging/preferences/show_deserializer.rb +17 -0
- data/app/deserializers/command_tower/deserializers/messaging/preferences/update_deserializer.rb +97 -0
- data/app/errors/command_tower/errors/account/phone_already_verified_error.rb +17 -0
- data/app/errors/command_tower/errors/account/phone_missing_error.rb +17 -0
- data/app/errors/command_tower/errors/account/phone_verification_code_invalid_error.rb +17 -0
- data/app/errors/command_tower/errors/account/phone_verification_expired_error.rb +17 -0
- data/app/errors/command_tower/errors/account/phone_verification_send_failed_error.rb +25 -0
- data/app/errors/command_tower/errors/account/phone_verification_stale_error.rb +17 -0
- data/app/errors/command_tower/errors/account/phone_verification_throttled_error.rb +24 -0
- data/app/errors/command_tower/errors/account/pushover_already_configured_error.rb +21 -0
- data/app/errors/command_tower/errors/account/pushover_capability_unavailable_error.rb +21 -0
- data/app/errors/command_tower/errors/account/pushover_not_configured_error.rb +21 -0
- data/app/errors/command_tower/errors/account/pushover_provider_unavailable_error.rb +21 -0
- data/app/errors/command_tower/errors/account/pushover_verification_failed_error.rb +27 -0
- data/app/errors/command_tower/errors/account/sms_capability_unavailable_error.rb +21 -0
- data/app/errors/command_tower/errors/application_error.rb +27 -0
- data/app/errors/command_tower/errors/auth/csrf_mismatch_error.rb +17 -0
- data/app/errors/command_tower/errors/auth/csrf_missing_error.rb +17 -0
- data/app/errors/command_tower/errors/auth/email_already_registered_error.rb +17 -0
- data/app/errors/command_tower/errors/auth/email_verification_required_error.rb +21 -0
- data/app/errors/command_tower/errors/auth/invalid_credentials_error.rb +21 -0
- data/app/errors/command_tower/errors/auth/password_recovery_ip_rate_limit_error.rb +25 -0
- data/app/errors/command_tower/errors/auth/password_recovery_session_expired_error.rb +21 -0
- data/app/errors/command_tower/errors/auth/password_recovery_session_invalid_error.rb +21 -0
- data/app/errors/command_tower/errors/auth/password_recovery_session_missing_error.rb +21 -0
- data/app/errors/command_tower/errors/auth/password_recovery_session_rate_limit_error.rb +25 -0
- data/app/errors/command_tower/errors/auth/password_reset_invalid_token_error.rb +21 -0
- data/app/errors/command_tower/errors/auth/password_reset_unavailable_error.rb +21 -0
- data/app/errors/command_tower/errors/auth/signup_ip_rate_limit_error.rb +25 -0
- data/app/errors/command_tower/errors/auth/signup_session_expired_error.rb +17 -0
- data/app/errors/command_tower/errors/auth/signup_session_invalid_error.rb +17 -0
- data/app/errors/command_tower/errors/auth/signup_session_missing_error.rb +17 -0
- data/app/errors/command_tower/errors/auth/signup_session_rate_limit_error.rb +25 -0
- data/app/errors/command_tower/errors/auth/verification_code_invalid_error.rb +17 -0
- data/app/errors/command_tower/errors/auth/verification_send_failed_error.rb +25 -0
- data/app/errors/command_tower/errors/forbidden_error.rb +19 -0
- data/app/errors/command_tower/errors/internal_error.rb +19 -0
- data/app/errors/command_tower/errors/messaging/accept_rejected_error.rb +21 -0
- data/app/errors/command_tower/errors/messaging/idempotency_conflict_error.rb +21 -0
- data/app/errors/command_tower/errors/messaging/recipient_unresolved_error.rb +21 -0
- data/app/errors/command_tower/errors/not_found_error.rb +19 -0
- data/app/errors/command_tower/errors/unauthorized_error.rb +19 -0
- data/app/errors/command_tower/errors/validation_error.rb +15 -0
- data/app/jobs/command_tower/messaging/channel_delivery_execution_job.rb +18 -0
- data/app/jobs/command_tower/messaging/communications/produce_recipient_job.rb +24 -0
- data/app/jobs/command_tower/messaging/execution_recovery_job.rb +13 -0
- data/app/jobs/command_tower/messaging/handoff_job.rb +15 -0
- data/app/jobs/command_tower/messaging/handoff_recovery_job.rb +13 -0
- data/app/mailers/command_tower/email_verification_mailer.rb +5 -3
- data/app/mailers/command_tower/messaging/channel_mailer.rb +25 -0
- data/app/mailers/command_tower/password_reset_mailer.rb +18 -0
- data/app/models/command_tower/messaging/channel_delivery.rb +45 -0
- data/app/models/command_tower/messaging/communication.rb +60 -0
- data/app/models/command_tower/messaging/delivery_attempt.rb +28 -0
- data/app/models/command_tower/messaging/destination_plan.rb +17 -0
- data/app/models/command_tower/messaging/endpoint.rb +98 -0
- data/app/models/command_tower/messaging/endpoint_pushover_credential.rb +18 -0
- data/app/models/command_tower/messaging/inbox_item.rb +52 -0
- data/app/models/command_tower/messaging/notification_preference.rb +21 -0
- data/app/models/user.rb +4 -1
- data/app/serializers/command_tower/serializers/admin/messaging/announcement_response_serializer.rb +41 -0
- data/app/serializers/command_tower/serializers/application/envelope_serializer.rb +25 -0
- data/app/serializers/command_tower/serializers/application/error_entry_serializer.rb +18 -0
- data/app/serializers/command_tower/serializers/application_serializer.rb +26 -0
- data/app/serializers/command_tower/serializers/auth/email_availability_serializer.rb +17 -0
- data/app/serializers/command_tower/serializers/auth/email_verification/message_response_serializer.rb +15 -0
- data/app/serializers/command_tower/serializers/auth/identity_policy_serializer.rb +36 -0
- data/app/serializers/command_tower/serializers/auth/login_response_serializer.rb +17 -0
- data/app/serializers/command_tower/serializers/auth/logout_response_serializer.rb +13 -0
- data/app/serializers/command_tower/serializers/auth/password_recovery_session_response_serializer.rb +16 -0
- data/app/serializers/command_tower/serializers/auth/password_reset/message_response_serializer.rb +15 -0
- data/app/serializers/command_tower/serializers/auth/password_reset/validate_response_serializer.rb +22 -0
- data/app/serializers/command_tower/serializers/auth/register_response_serializer.rb +16 -0
- data/app/serializers/command_tower/serializers/auth/session_response_serializer.rb +16 -0
- data/app/serializers/command_tower/serializers/auth/signup_session_response_serializer.rb +16 -0
- data/app/serializers/command_tower/serializers/auth/user_serializer.rb +21 -0
- data/app/serializers/command_tower/serializers/auth/username_availability_serializer.rb +17 -0
- data/app/serializers/command_tower/serializers/me/account_serializer.rb +45 -0
- data/app/serializers/command_tower/serializers/me/change_password_response_serializer.rb +13 -0
- data/app/serializers/command_tower/serializers/me/pushover_serializer.rb +59 -0
- data/app/serializers/command_tower/serializers/messaging/inbox.rb +45 -0
- data/app/serializers/command_tower/serializers/messaging/preferences/catalog_serializer.rb +17 -0
- data/app/serializers/command_tower/serializers/messaging/preferences/category_serializer.rb +23 -0
- data/app/serializers/command_tower/serializers/messaging/preferences/notification_serializer.rb +30 -0
- data/app/serializers/command_tower/serializers/profile/profile_serializer.rb +13 -0
- data/app/services/command_tower/README.md +22 -6
- data/app/services/command_tower/auth/request_context.rb +21 -0
- data/app/services/command_tower/authorize/validate.rb +54 -18
- data/app/services/command_tower/clients/client_base.rb +183 -0
- data/app/services/command_tower/clients/client_result.rb +45 -0
- data/app/services/command_tower/clients/const_resolution.rb +32 -0
- data/app/services/command_tower/clients/decoded_response.rb +16 -0
- data/app/services/command_tower/clients/endpoint_base.rb +242 -0
- data/app/services/command_tower/clients/endpoint_input.rb +18 -0
- data/app/services/command_tower/clients/errors/authentication_error.rb +26 -0
- data/app/services/command_tower/clients/errors/configuration_error.rb +10 -0
- data/app/services/command_tower/clients/errors/deserialization_error.rb +26 -0
- data/app/services/command_tower/clients/errors/discovery_error.rb +10 -0
- data/app/services/command_tower/clients/errors/upstream_error.rb +26 -0
- data/app/services/command_tower/clients/invocation.rb +61 -0
- data/app/services/command_tower/clients/namespace_proxy.rb +75 -0
- data/app/services/command_tower/clients/scoped_client.rb +88 -0
- data/app/services/command_tower/clients/serialized_request.rb +17 -0
- data/app/services/command_tower/clients/transport/error.rb +18 -0
- data/app/services/command_tower/clients/transport/faraday_adapter.rb +129 -0
- data/app/services/command_tower/clients/transport/faraday_config.rb +45 -0
- data/app/services/command_tower/clients/transport/request.rb +50 -0
- data/app/services/command_tower/clients/transport/response.rb +22 -0
- data/app/services/command_tower/clients/url.rb +56 -0
- data/app/services/command_tower/identity/phone/normalizer.rb +41 -0
- data/app/services/command_tower/identity/phone_verification/sms_configuration.rb +58 -0
- data/app/services/command_tower/identity/phone_verification/sms_transport/adapters/fake_adapter.rb +35 -0
- data/app/services/command_tower/identity/phone_verification/sms_transport/adapters/log_adapter.rb +34 -0
- data/app/services/command_tower/identity/phone_verification/sms_transport/adapters/twilio_adapter.rb +60 -0
- data/app/services/command_tower/identity/phone_verification/sms_transport.rb +42 -0
- data/app/services/command_tower/jwt/authenticate_user.rb +61 -34
- data/app/services/command_tower/jwt/authentication_outcome.rb +36 -0
- data/app/services/command_tower/jwt/decode.rb +27 -8
- data/app/services/command_tower/jwt/encode.rb +4 -6
- data/app/services/command_tower/jwt/login_create.rb +6 -7
- data/app/services/command_tower/login_strategy/plain_text/email_verification/required.rb +11 -9
- data/app/services/command_tower/messaging/accept/channel_delivery_result.rb +13 -0
- data/app/services/command_tower/messaging/accept/coordinator.rb +166 -0
- data/app/services/command_tower/messaging/accept/error.rb +9 -0
- data/app/services/command_tower/messaging/accept/excluded_destination.rb +24 -0
- data/app/services/command_tower/messaging/accept/handoff_scheduler.rb +40 -0
- data/app/services/command_tower/messaging/accept/idempotency_conflict_error.rb +9 -0
- data/app/services/command_tower/messaging/accept/illegal_override_error.rb +9 -0
- data/app/services/command_tower/messaging/accept/impossible_mandatory_plan_error.rb +9 -0
- data/app/services/command_tower/messaging/accept/invalid_preference_error.rb +9 -0
- data/app/services/command_tower/messaging/accept/invariant_error.rb +9 -0
- data/app/services/command_tower/messaging/accept/operation_logger.rb +97 -0
- data/app/services/command_tower/messaging/accept/persistence_error.rb +9 -0
- data/app/services/command_tower/messaging/accept/persister.rb +90 -0
- data/app/services/command_tower/messaging/accept/request_normalizer.rb +100 -0
- data/app/services/command_tower/messaging/accept/result.rb +99 -0
- data/app/services/command_tower/messaging/accept/unknown_type_error.rb +9 -0
- data/app/services/command_tower/messaging/accept/validation_error.rb +9 -0
- data/app/services/command_tower/messaging/channel_detectors.rb +52 -0
- data/app/services/command_tower/messaging/channels/definition.rb +24 -0
- data/app/services/command_tower/messaging/channels/error.rb +9 -0
- data/app/services/command_tower/messaging/channels/unknown_channel_error.rb +9 -0
- data/app/services/command_tower/messaging/channels.rb +85 -0
- data/app/services/command_tower/messaging/contract/communications.rb +29 -0
- data/app/services/command_tower/messaging/contract/error.rb +9 -0
- data/app/services/command_tower/messaging/contract/internal/finder.rb +43 -0
- data/app/services/command_tower/messaging/contract/invariant_error.rb +9 -0
- data/app/services/command_tower/messaging/contract/mappers/channel_delivery_mapper.rb +53 -0
- data/app/services/command_tower/messaging/contract/mappers/communication_mapper.rb +61 -0
- data/app/services/command_tower/messaging/contract/mappers/delivery_attempt_mapper.rb +27 -0
- data/app/services/command_tower/messaging/contract/mappers/destination_plan_mapper.rb +17 -0
- data/app/services/command_tower/messaging/contract/mappers/inbox_item_mapper.rb +17 -0
- data/app/services/command_tower/messaging/contract/not_found_error.rb +9 -0
- data/app/services/command_tower/messaging/contract/observability/correlation.rb +17 -0
- data/app/services/command_tower/messaging/contract/observability/operation_logger.rb +101 -0
- data/app/services/command_tower/messaging/contract/observability/structured_logger.rb +56 -0
- data/app/services/command_tower/messaging/contract/requests/find_communication.rb +21 -0
- data/app/services/command_tower/messaging/contract/results/channel_delivery_result.rb +25 -0
- data/app/services/command_tower/messaging/contract/results/communication_result.rb +22 -0
- data/app/services/command_tower/messaging/contract/results/delivery_attempt_result.rb +21 -0
- data/app/services/command_tower/messaging/contract/results/destination_plan_result.rb +11 -0
- data/app/services/command_tower/messaging/contract/results/inbox_item_result.rb +11 -0
- data/app/services/command_tower/messaging/contract/validation_error.rb +9 -0
- data/app/services/command_tower/messaging/delivery_retry_policy.rb +30 -0
- data/app/services/command_tower/messaging/endpoints/begin_verification.rb +13 -0
- data/app/services/command_tower/messaging/endpoints/channel_gate.rb +39 -0
- data/app/services/command_tower/messaging/endpoints/conflict_error.rb +9 -0
- data/app/services/command_tower/messaging/endpoints/create.rb +181 -0
- data/app/services/command_tower/messaging/endpoints/error.rb +9 -0
- data/app/services/command_tower/messaging/endpoints/fingerprinter.rb +50 -0
- data/app/services/command_tower/messaging/endpoints/invalid_transition_error.rb +9 -0
- data/app/services/command_tower/messaging/endpoints/lifecycle.rb +37 -0
- data/app/services/command_tower/messaging/endpoints/mark_invalid.rb +32 -0
- data/app/services/command_tower/messaging/endpoints/mark_verification_failed.rb +13 -0
- data/app/services/command_tower/messaging/endpoints/mark_verified.rb +13 -0
- data/app/services/command_tower/messaging/endpoints/not_found_error.rb +9 -0
- data/app/services/command_tower/messaging/endpoints/persistence.rb +91 -0
- data/app/services/command_tower/messaging/endpoints/pushover/verify.rb +101 -0
- data/app/services/command_tower/messaging/endpoints/query.rb +28 -0
- data/app/services/command_tower/messaging/endpoints/replace.rb +181 -0
- data/app/services/command_tower/messaging/endpoints/reset_verification.rb +13 -0
- data/app/services/command_tower/messaging/endpoints/revoke.rb +40 -0
- data/app/services/command_tower/messaging/endpoints/safe_view.rb +50 -0
- data/app/services/command_tower/messaging/endpoints/secret_box.rb +86 -0
- data/app/services/command_tower/messaging/endpoints/secret_reader.rb +72 -0
- data/app/services/command_tower/messaging/endpoints/validation_error.rb +9 -0
- data/app/services/command_tower/messaging/endpoints/validators/push.rb +24 -0
- data/app/services/command_tower/messaging/endpoints/validators/pushover.rb +68 -0
- data/app/services/command_tower/messaging/endpoints/validators.rb +36 -0
- data/app/services/command_tower/messaging/endpoints/verification.rb +39 -0
- data/app/services/command_tower/messaging/endpoints/verification_failed_error.rb +18 -0
- data/app/services/command_tower/messaging/endpoints/verification_transition.rb +20 -0
- data/app/services/command_tower/messaging/endpoints.rb +55 -0
- data/app/services/command_tower/messaging/execution/adapter_request.rb +45 -0
- data/app/services/command_tower/messaging/execution/adapter_result.rb +81 -0
- data/app/services/command_tower/messaging/execution/adapters/email/adapter.rb +78 -0
- data/app/services/command_tower/messaging/execution/adapters/email/configuration.rb +55 -0
- data/app/services/command_tower/messaging/execution/adapters/fake_adapter.rb +34 -0
- data/app/services/command_tower/messaging/execution/adapters/pushover/adapter.rb +107 -0
- data/app/services/command_tower/messaging/execution/adapters/pushover/configuration.rb +30 -0
- data/app/services/command_tower/messaging/execution/adapters/sms/adapter.rb +90 -0
- data/app/services/command_tower/messaging/execution/adapters/sms/configuration.rb +58 -0
- data/app/services/command_tower/messaging/execution/adapters/sms/log_adapter.rb +34 -0
- data/app/services/command_tower/messaging/execution/adapters/sms/twilio_http_client.rb +70 -0
- data/app/services/command_tower/messaging/execution/adapters/unconfigured_adapter.rb +20 -0
- data/app/services/command_tower/messaging/execution/attempt_ledger.rb +146 -0
- data/app/services/command_tower/messaging/execution/claim.rb +35 -0
- data/app/services/command_tower/messaging/execution/invalid_adapter_contract_error.rb +9 -0
- data/app/services/command_tower/messaging/execution/operation_logger.rb +237 -0
- data/app/services/command_tower/messaging/execution/readiness_terminal_mapping.rb +37 -0
- data/app/services/command_tower/messaging/execution/recovery.rb +78 -0
- data/app/services/command_tower/messaging/execution/resolve_recipient_address.rb +58 -0
- data/app/services/command_tower/messaging/execution/revalidate_readiness.rb +73 -0
- data/app/services/command_tower/messaging/execution/scheduler.rb +38 -0
- data/app/services/command_tower/messaging/execution/select_adapter.rb +63 -0
- data/app/services/command_tower/messaging/handoff/advance_communication.rb +39 -0
- data/app/services/command_tower/messaging/handoff/operation_logger.rb +78 -0
- data/app/services/command_tower/messaging/handoff/recovery.rb +26 -0
- data/app/services/command_tower/messaging/inbox/bulk_result.rb +19 -0
- data/app/services/command_tower/messaging/inbox/error.rb +9 -0
- data/app/services/command_tower/messaging/inbox/invalid_bulk_items_error.rb +19 -0
- data/app/services/command_tower/messaging/inbox/invariant_error.rb +9 -0
- data/app/services/command_tower/messaging/inbox/item_result.rb +64 -0
- data/app/services/command_tower/messaging/inbox/list_result.rb +18 -0
- data/app/services/command_tower/messaging/inbox/mutator.rb +252 -0
- data/app/services/command_tower/messaging/inbox/not_found_error.rb +9 -0
- data/app/services/command_tower/messaging/inbox/operation_logger.rb +37 -0
- data/app/services/command_tower/messaging/inbox/reader.rb +117 -0
- data/app/services/command_tower/messaging/inbox/scope.rb +24 -0
- data/app/services/command_tower/messaging/inbox/unread_count_result.rb +16 -0
- data/app/services/command_tower/messaging/inbox/validation_error.rb +9 -0
- data/app/services/command_tower/messaging/inbox.rb +61 -0
- data/app/services/command_tower/messaging/notification_types/catalog_category.rb +19 -0
- data/app/services/command_tower/messaging/notification_types/declaration.rb +96 -0
- data/app/services/command_tower/messaging/notification_types/declaration_validator.rb +152 -0
- data/app/services/command_tower/messaging/notification_types/duplicate_type_error.rb +9 -0
- data/app/services/command_tower/messaging/notification_types/error.rb +9 -0
- data/app/services/command_tower/messaging/notification_types/invalid_declaration_error.rb +9 -0
- data/app/services/command_tower/messaging/notification_types/not_found_error.rb +9 -0
- data/app/services/command_tower/messaging/notification_types/registry.rb +103 -0
- data/app/services/command_tower/messaging/notification_types/sealed_registry_error.rb +9 -0
- data/app/services/command_tower/messaging/notification_types.rb +37 -0
- data/app/services/command_tower/messaging/planner/destination_plan.rb +41 -0
- data/app/services/command_tower/messaging/planner/error.rb +9 -0
- data/app/services/command_tower/messaging/planner/excluded_destination.rb +28 -0
- data/app/services/command_tower/messaging/planner/illegal_override_error.rb +9 -0
- data/app/services/command_tower/messaging/planner/impossible_mandatory_plan_error.rb +9 -0
- data/app/services/command_tower/messaging/planner/invalid_evaluation_error.rb +9 -0
- data/app/services/command_tower/messaging/planner/message_overrides.rb +33 -0
- data/app/services/command_tower/messaging/planner/operation_logger.rb +28 -0
- data/app/services/command_tower/messaging/planner/planner.rb +261 -0
- data/app/services/command_tower/messaging/planner/unknown_type_error.rb +9 -0
- data/app/services/command_tower/messaging/planner.rb +25 -0
- data/app/services/command_tower/messaging/preferences/catalog.rb +96 -0
- data/app/services/command_tower/messaging/preferences/catalog_category_result.rb +19 -0
- data/app/services/command_tower/messaging/preferences/catalog_notification_result.rb +55 -0
- data/app/services/command_tower/messaging/preferences/catalog_result.rb +13 -0
- data/app/services/command_tower/messaging/preferences/error.rb +9 -0
- data/app/services/command_tower/messaging/preferences/evaluation_result.rb +61 -0
- data/app/services/command_tower/messaging/preferences/evaluator.rb +194 -0
- data/app/services/command_tower/messaging/preferences/invalid_preference_state_error.rb +9 -0
- data/app/services/command_tower/messaging/preferences/invalid_preference_write_error.rb +10 -0
- data/app/services/command_tower/messaging/preferences/not_settings_visible_error.rb +10 -0
- data/app/services/command_tower/messaging/preferences/preference_state.rb +61 -0
- data/app/services/command_tower/messaging/preferences/reason_classes.rb +17 -0
- data/app/services/command_tower/messaging/preferences/resolve.rb +50 -0
- data/app/services/command_tower/messaging/preferences/store.rb +126 -0
- data/app/services/command_tower/messaging/preferences/store_error.rb +10 -0
- data/app/services/command_tower/messaging/preferences/suppressed_destination.rb +24 -0
- data/app/services/command_tower/messaging/preferences/unknown_type_error.rb +9 -0
- data/app/services/command_tower/messaging/preferences/update.rb +248 -0
- data/app/services/command_tower/messaging/preferences.rb +68 -0
- data/app/services/command_tower/messaging/pushover/adapters/disabled_adapter.rb +33 -0
- data/app/services/command_tower/messaging/pushover/adapters/fake_adapter.rb +90 -0
- data/app/services/command_tower/messaging/pushover/adapters/http_adapter.rb +145 -0
- data/app/services/command_tower/messaging/pushover/adapters/log_adapter.rb +52 -0
- data/app/services/command_tower/messaging/pushover/result.rb +34 -0
- data/app/services/command_tower/messaging/pushover/transport.rb +64 -0
- data/app/services/command_tower/messaging/recipient_readiness/channel_result.rb +55 -0
- data/app/services/command_tower/messaging/recipient_readiness/error.rb +9 -0
- data/app/services/command_tower/messaging/recipient_readiness/evaluate.rb +319 -0
- data/app/services/command_tower/messaging/recipient_readiness/identity_facts.rb +54 -0
- data/app/services/command_tower/messaging/recipient_readiness/reason_codes.rb +33 -0
- data/app/services/command_tower/messaging/recipient_readiness/recipient_not_found_error.rb +9 -0
- data/app/services/command_tower/messaging/recipient_readiness/recipient_result.rb +38 -0
- data/app/services/command_tower/messaging/recipient_readiness/unknown_channel_error.rb +9 -0
- data/app/services/command_tower/messaging/recipient_readiness.rb +26 -0
- data/app/services/command_tower/messaging/rendering/channel_renderer.rb +127 -0
- data/app/services/command_tower/messaging/rendering/render_error.rb +24 -0
- data/app/services/command_tower/messaging/rendering/rendered_payload.rb +44 -0
- data/app/services/command_tower/messaging/rendering/rendered_pushover_payload.rb +43 -0
- data/app/services/command_tower/messaging/rendering/rendered_sms_payload.rb +40 -0
- data/app/services/command_tower/messaging.rb +35 -0
- data/app/services/command_tower/secrets/cleanse.rb +19 -5
- data/app/services/command_tower/secrets/generate.rb +62 -27
- data/app/services/command_tower/secrets/verify.rb +46 -12
- data/app/services/command_tower/secrets.rb +2 -0
- data/app/services/command_tower/services/account/clear_phone.rb +25 -0
- data/app/services/command_tower/services/account/phone_verification/send.rb +114 -0
- data/app/services/command_tower/services/account/phone_verification/verify.rb +88 -0
- data/app/services/command_tower/services/account/pushover/create.rb +28 -0
- data/app/services/command_tower/services/account/pushover/ct_support.rb +70 -0
- data/app/services/command_tower/services/account/pushover/destroy.rb +30 -0
- data/app/services/command_tower/services/account/pushover/replace.rb +28 -0
- data/app/services/command_tower/services/account/pushover/show.rb +19 -0
- data/app/services/command_tower/services/account/pushover/verify.rb +30 -0
- data/app/services/command_tower/services/account/update_phone.rb +50 -0
- data/app/services/command_tower/services/application_service.rb +21 -0
- data/app/services/command_tower/services/auth/authenticate_session.rb +105 -0
- data/app/services/command_tower/services/auth/authorize_request.rb +34 -0
- data/app/services/command_tower/services/auth/client_ip_resolver.rb +13 -0
- data/app/services/command_tower/services/auth/email_availability.rb +42 -0
- data/app/services/command_tower/services/auth/email_verification/send.rb +65 -0
- data/app/services/command_tower/services/auth/email_verification/verify.rb +51 -0
- data/app/services/command_tower/services/auth/identity_policy.rb +60 -0
- data/app/services/command_tower/services/auth/password_recovery/rate_limits/check_send.rb +48 -0
- data/app/services/command_tower/services/auth/password_recovery/rate_limits/check_token_issue.rb +35 -0
- data/app/services/command_tower/services/auth/password_recovery/rate_limits/enforcement.rb +53 -0
- data/app/services/command_tower/services/auth/password_recovery_session/create.rb +26 -0
- data/app/services/command_tower/services/auth/password_recovery_session/decode.rb +29 -0
- data/app/services/command_tower/services/auth/password_recovery_session/encode.rb +31 -0
- data/app/services/command_tower/services/auth/password_recovery_session/validate.rb +58 -0
- data/app/services/command_tower/services/auth/password_reset/reset.rb +65 -0
- data/app/services/command_tower/services/auth/password_reset/send.rb +77 -0
- data/app/services/command_tower/services/auth/password_reset/token_verification.rb +68 -0
- data/app/services/command_tower/services/auth/password_reset/validate.rb +29 -0
- data/app/services/command_tower/services/auth/plain_text/login.rb +44 -0
- data/app/services/command_tower/services/auth/register.rb +77 -0
- data/app/services/command_tower/services/auth/signup_rate_limits/check_availability.rb +52 -0
- data/app/services/command_tower/services/auth/signup_rate_limits/check_register.rb +24 -0
- data/app/services/command_tower/services/auth/signup_rate_limits/check_token_issue.rb +33 -0
- data/app/services/command_tower/services/auth/signup_rate_limits/enforcement.rb +50 -0
- data/app/services/command_tower/services/auth/signup_session/create.rb +26 -0
- data/app/services/command_tower/services/auth/signup_session/decode.rb +29 -0
- data/app/services/command_tower/services/auth/signup_session/encode.rb +31 -0
- data/app/services/command_tower/services/auth/signup_session/validate.rb +58 -0
- data/app/services/command_tower/services/auth/username_availability.rb +28 -0
- data/app/services/command_tower/services/me/capabilities.rb +43 -0
- data/app/services/command_tower/services/me/change_password.rb +84 -0
- data/app/services/command_tower/services/me/pushover_product_gate.rb +18 -0
- data/app/services/command_tower/services/me/sms_product_gate.rb +19 -0
- data/app/services/command_tower/services/me/update_name.rb +58 -0
- data/app/services/command_tower/services/messaging/communications/produce.rb +68 -0
- data/app/services/command_tower/services/messaging/communications/produce_many.rb +154 -0
- data/app/services/command_tower/services/messaging/inbox.rb +129 -0
- data/app/services/command_tower/services/messaging/preferences/platform_enabled_channels.rb +20 -0
- data/app/services/command_tower/services/messaging/preferences/show.rb +36 -0
- data/app/services/command_tower/services/messaging/preferences/update.rb +43 -0
- data/app/services/command_tower/services/messaging/recipients.rb +20 -0
- data/app/services/command_tower/services/rate_limits/check.rb +31 -0
- data/app/services/command_tower/services/service_result.rb +73 -0
- data/app/services/command_tower/user_attributes/mutate.rb +154 -0
- data/app/services/command_tower/username/available.rb +24 -11
- data/app/views/command_tower/email_verification_mailer/verify_email.html.erb +70 -22
- data/app/views/command_tower/messaging/rendering/email.html.erb +28 -0
- data/app/views/command_tower/messaging/rendering/email.text.erb +7 -0
- data/app/views/command_tower/messaging/rendering/pushover.text.erb +1 -0
- data/app/views/command_tower/messaging/rendering/sms.text.erb +1 -0
- data/app/views/command_tower/password_reset_mailer/reset_password.html.erb +107 -0
- data/app/views/layouts/mailer.html.erb +13 -0
- data/app/views/layouts/mailer.text.erb +1 -0
- data/app/workflows/command_tower/workflows/admin/messaging/create_announcement_workflow.rb +62 -0
- data/app/workflows/command_tower/workflows/application_workflow.rb +68 -0
- data/app/workflows/command_tower/workflows/auth/authenticate_request_workflow.rb +40 -0
- data/app/workflows/command_tower/workflows/auth/authentication_response_effects.rb +21 -0
- data/app/workflows/command_tower/workflows/auth/authorize_request_workflow.rb +28 -0
- data/app/workflows/command_tower/workflows/auth/email_availability_workflow.rb +39 -0
- data/app/workflows/command_tower/workflows/auth/email_verification/send_workflow.rb +32 -0
- data/app/workflows/command_tower/workflows/auth/email_verification/verify_workflow.rb +35 -0
- data/app/workflows/command_tower/workflows/auth/identity_error_status.rb +36 -0
- data/app/workflows/command_tower/workflows/auth/identity_policy_workflow.rb +26 -0
- data/app/workflows/command_tower/workflows/auth/logout_workflow.rb +19 -0
- data/app/workflows/command_tower/workflows/auth/password_recovery_session/authenticate_workflow.rb +49 -0
- data/app/workflows/command_tower/workflows/auth/password_recovery_session/create_workflow.rb +39 -0
- data/app/workflows/command_tower/workflows/auth/password_reset/reset_workflow.rb +40 -0
- data/app/workflows/command_tower/workflows/auth/password_reset/send_workflow.rb +45 -0
- data/app/workflows/command_tower/workflows/auth/password_reset/validate_workflow.rb +40 -0
- data/app/workflows/command_tower/workflows/auth/plain_text/login_workflow.rb +46 -0
- data/app/workflows/command_tower/workflows/auth/register_workflow.rb +83 -0
- data/app/workflows/command_tower/workflows/auth/session/show_workflow.rb +44 -0
- data/app/workflows/command_tower/workflows/auth/session_error_status.rb +30 -0
- data/app/workflows/command_tower/workflows/auth/signup_error_status.rb +31 -0
- data/app/workflows/command_tower/workflows/auth/signup_session/authenticate_workflow.rb +49 -0
- data/app/workflows/command_tower/workflows/auth/signup_session/create_workflow.rb +37 -0
- data/app/workflows/command_tower/workflows/auth/username_availability_workflow.rb +39 -0
- data/app/workflows/command_tower/workflows/me/change_password_workflow.rb +34 -0
- data/app/workflows/command_tower/workflows/me/clear_phone_workflow.rb +52 -0
- data/app/workflows/command_tower/workflows/me/error_mapping.rb +46 -0
- data/app/workflows/command_tower/workflows/me/error_status.rb +28 -0
- data/app/workflows/command_tower/workflows/me/phone_verification/send_workflow.rb +65 -0
- data/app/workflows/command_tower/workflows/me/phone_verification/verify_workflow.rb +57 -0
- data/app/workflows/command_tower/workflows/me/pushover/create_workflow.rb +38 -0
- data/app/workflows/command_tower/workflows/me/pushover/destroy_workflow.rb +34 -0
- data/app/workflows/command_tower/workflows/me/pushover/replace_workflow.rb +38 -0
- data/app/workflows/command_tower/workflows/me/pushover/show_workflow.rb +34 -0
- data/app/workflows/command_tower/workflows/me/pushover/verify_workflow.rb +34 -0
- data/app/workflows/command_tower/workflows/me/pushover/workflow_support.rb +31 -0
- data/app/workflows/command_tower/workflows/me/show_workflow.rb +33 -0
- data/app/workflows/command_tower/workflows/me/update_name_workflow.rb +48 -0
- data/app/workflows/command_tower/workflows/me/update_phone_workflow.rb +55 -0
- data/app/workflows/command_tower/workflows/messaging/communications/produce_recipient_workflow.rb +60 -0
- data/app/workflows/command_tower/workflows/messaging/error_mapping.rb +26 -0
- data/app/workflows/command_tower/workflows/messaging/execution/deliver_workflow.rb +234 -0
- data/app/workflows/command_tower/workflows/messaging/handoff/process_workflow.rb +90 -0
- data/app/workflows/command_tower/workflows/messaging/inbox.rb +97 -0
- data/app/workflows/command_tower/workflows/messaging/preferences/show_workflow.rb +31 -0
- data/app/workflows/command_tower/workflows/messaging/preferences/update_workflow.rb +37 -0
- data/app/workflows/command_tower/workflows/profile/show_workflow.rb +27 -0
- data/app/workflows/command_tower/workflows/workflow_result.rb +34 -0
- data/config/routes.rb +85 -37
- data/db/migrate/{20241117043720_create_command_tower_users.rb → 20260805000001_create_command_tower_users.rb} +7 -9
- data/db/migrate/{20241204065708_create_command_tower_user_secrets.rb → 20260805000002_create_command_tower_user_secrets.rb} +3 -0
- data/db/migrate/20260805000003_create_command_tower_messaging_core.rb +90 -0
- data/db/migrate/20260805000004_create_messaging_notification_preferences.rb +17 -0
- data/db/migrate/20260805000005_create_messaging_endpoints_and_pushover_credentials.rb +72 -0
- data/docs/api_reference.md +438 -0
- data/docs/architecture.md +30 -0
- data/docs/authentication.md +37 -0
- data/docs/authentication_authorization_guide.md +150 -0
- data/docs/authorization.md +34 -0
- data/docs/change_password_workflow.md +67 -0
- data/docs/controllers.md +35 -0
- data/docs/cookie_authentication_guide.md +167 -0
- data/docs/email_verification_workflow.md +58 -0
- data/docs/extending.md +105 -0
- data/docs/host_integration_guide.md +158 -0
- data/docs/initializing.md +169 -0
- data/docs/messaging_integration_guide.md +87 -0
- data/docs/models.md +51 -0
- data/docs/pagination.md +47 -0
- data/docs/password_reset_workflow.md +82 -0
- data/docs/sensitive_routes.md +47 -0
- data/docs/testing.md +74 -0
- data/docs/upgrades/0.10.0.md +58 -0
- data/docs/upgrades/README.md +9 -0
- data/lib/command_tower/authorization/default.yml +5 -33
- data/lib/command_tower/configuration/application/config.rb +2 -2
- data/lib/command_tower/configuration/base.rb +0 -1
- data/lib/command_tower/configuration/config.rb +31 -1
- data/lib/command_tower/configuration/credentials/config.rb +33 -0
- data/lib/command_tower/configuration/credentials/smtp.rb +33 -0
- data/lib/command_tower/configuration/credentials/twilio.rb +33 -0
- data/lib/command_tower/configuration/email/config.rb +1 -18
- data/lib/command_tower/configuration/identity/config.rb +19 -0
- data/lib/command_tower/configuration/identity/phone_verification.rb +54 -0
- data/lib/command_tower/configuration/jwt/config.rb +7 -0
- data/lib/command_tower/configuration/jwt/cookie/config.rb +64 -0
- data/lib/command_tower/configuration/jwt/cookie/csrf/config.rb +72 -0
- data/lib/command_tower/configuration/login/strategy/plain_text/config.rb +6 -0
- data/lib/command_tower/configuration/login/strategy/plain_text/email_verify.rb +5 -0
- data/lib/command_tower/configuration/login/strategy/plain_text/password_reset.rb +49 -0
- data/lib/command_tower/configuration/messaging/config.rb +60 -0
- data/lib/command_tower/configuration/messaging/pushover.rb +42 -0
- data/lib/command_tower/configuration/messaging/sms.rb +32 -0
- data/lib/command_tower/configuration/password_recovery_session/config.rb +61 -0
- data/lib/command_tower/configuration/password_recovery_session/rate_limits.rb +33 -0
- data/lib/command_tower/configuration/signup_session/config.rb +67 -0
- data/lib/command_tower/configuration/signup_session/email_availability.rb +18 -0
- data/lib/command_tower/configuration/signup_session/rate_limits.rb +48 -0
- data/lib/command_tower/configuration/user/config.rb +6 -5
- data/lib/command_tower/credential_resolution/env_backend.rb +25 -0
- data/lib/command_tower/credential_resolution/smtp_action_mailer_bridge.rb +24 -0
- data/lib/command_tower/credential_resolution/smtp_credentials.rb +26 -0
- data/lib/command_tower/credential_resolution/twilio_credentials.rb +26 -0
- data/lib/command_tower/credential_resolution.rb +78 -0
- data/lib/command_tower/current.rb +7 -0
- data/lib/command_tower/engine.rb +4 -1
- data/lib/command_tower/install/baseline.rb +31 -0
- data/lib/command_tower/install/doctor.rb +227 -0
- data/lib/command_tower/jwt/authorization_helper.rb +136 -0
- data/lib/command_tower/jwt/csrf_helper.rb +138 -0
- data/lib/command_tower/password_recovery/authorization_helper.rb +25 -0
- data/lib/command_tower/redis_connection.rb +21 -0
- data/lib/command_tower/schema/error/email_validation_required.rb +15 -0
- data/lib/command_tower/schema/shared/user.rb +32 -0
- data/lib/command_tower/schema.rb +2 -25
- data/lib/command_tower/signup/authorization_helper.rb +25 -0
- data/lib/command_tower/spec_helper.rb +58 -1
- data/lib/command_tower/testing.rb +62 -0
- data/lib/command_tower/version.rb +1 -1
- data/lib/command_tower.rb +20 -0
- data/lib/generators/command_tower/configure/USAGE +14 -2
- data/lib/generators/command_tower/configure/configure_generator.rb +29 -2
- data/lib/tasks/auto_annotate_models.rake +23 -55
- data/lib/tasks/install.rake +81 -0
- data/lib/tasks/users.rake +119 -0
- data/spec/factories/entity.rb +37 -0
- data/spec/factories/messaging.rb +156 -0
- data/spec/factories/role.rb +29 -0
- data/spec/factories/user.rb +53 -0
- data/spec/factories/user_secret.rb +12 -0
- metadata +576 -55
- data/app/controllers/command_tower/admin_controller.rb +0 -110
- data/app/controllers/command_tower/auth/plain_text_controller.rb +0 -133
- data/app/controllers/command_tower/inbox/message_blast_controller.rb +0 -89
- data/app/controllers/command_tower/inbox/message_controller.rb +0 -81
- data/app/controllers/command_tower/user_controller.rb +0 -49
- data/app/controllers/command_tower/username_controller.rb +0 -26
- data/app/helpers/command_tower/pagination_helper.rb +0 -40
- data/app/helpers/command_tower/schema_helper.rb +0 -29
- data/app/models/message.rb +0 -30
- data/app/models/message_blast.rb +0 -27
- data/app/services/command_tower/admin_service/users.rb +0 -27
- data/app/services/command_tower/inbox_service/blast/delete.rb +0 -23
- data/app/services/command_tower/inbox_service/blast/metadata.rb +0 -26
- data/app/services/command_tower/inbox_service/blast/new_user_blaster.rb +0 -24
- data/app/services/command_tower/inbox_service/blast/retrieve.rb +0 -30
- data/app/services/command_tower/inbox_service/blast/upsert.rb +0 -67
- data/app/services/command_tower/inbox_service/message/metadata.rb +0 -41
- data/app/services/command_tower/inbox_service/message/modify.rb +0 -44
- data/app/services/command_tower/inbox_service/message/retrieve.rb +0 -36
- data/app/services/command_tower/inbox_service/message/send.rb +0 -33
- data/app/services/command_tower/jwt/time_delay_token.rb +0 -17
- data/app/services/command_tower/login_strategy/plain_text/create.rb +0 -43
- data/app/services/command_tower/login_strategy/plain_text/email_verification/generate.rb +0 -29
- data/app/services/command_tower/login_strategy/plain_text/email_verification/send.rb +0 -23
- data/app/services/command_tower/login_strategy/plain_text/email_verification/verify.rb +0 -24
- data/app/services/command_tower/login_strategy/plain_text/login.rb +0 -50
- data/app/services/command_tower/pagination_service_helper.rb +0 -88
- data/app/services/command_tower/user_attributes/modify.rb +0 -68
- data/app/services/command_tower/user_attributes/roles.rb +0 -27
- data/db/migrate/20250223023306_create_command_tower_messages.rb +0 -12
- data/db/migrate/20250223023313_create_command_tower_message_blasts.rb +0 -14
- data/lib/command_tower/schema/admin/users.rb +0 -16
- data/lib/command_tower/schema/inbox/blast_request.rb +0 -15
- data/lib/command_tower/schema/inbox/blast_response.rb +0 -16
- data/lib/command_tower/schema/inbox/message_blast_entity.rb +0 -16
- data/lib/command_tower/schema/inbox/message_blast_metadata.rb +0 -16
- data/lib/command_tower/schema/inbox/message_entity.rb +0 -14
- data/lib/command_tower/schema/inbox/metadata.rb +0 -18
- data/lib/command_tower/schema/inbox/modified.rb +0 -13
- data/lib/command_tower/schema/page.rb +0 -11
- data/lib/command_tower/schema/pagination.rb +0 -16
- data/lib/command_tower/schema/plain_text/create_user_request.rb +0 -18
- data/lib/command_tower/schema/plain_text/create_user_response.rb +0 -17
- data/lib/command_tower/schema/plain_text/email_verify_request.rb +0 -11
- data/lib/command_tower/schema/plain_text/email_verify_response.rb +0 -11
- data/lib/command_tower/schema/plain_text/email_verify_send_request.rb +0 -9
- data/lib/command_tower/schema/plain_text/email_verify_send_response.rb +0 -11
- data/lib/command_tower/schema/plain_text/login_request.rb +0 -15
- data/lib/command_tower/schema/plain_text/login_response.rb +0 -16
- data/lib/command_tower/schema/user.rb +0 -28
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CommandTower
|
|
4
|
+
module Messaging
|
|
5
|
+
# Safe owner-facing Endpoint Platform façade.
|
|
6
|
+
# Decrypt-at-use lives on Endpoints::SecretReader (internal).
|
|
7
|
+
module Endpoints
|
|
8
|
+
module_function
|
|
9
|
+
|
|
10
|
+
def create(owner_user_id:, channel_key:, address: nil, credentials: nil)
|
|
11
|
+
Create.call(owner_user_id:, channel_key:, address:, credentials:)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def replace(owner_user_id:, channel_key: nil, endpoint_id: nil, address: nil, credentials: nil)
|
|
15
|
+
Replace.call(owner_user_id:, channel_key:, endpoint_id:, address:, credentials:)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def revoke(owner_user_id:, endpoint_id:)
|
|
19
|
+
Revoke.call(owner_user_id:, endpoint_id:)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def list(owner_user_id:, channel_key: nil)
|
|
23
|
+
Query.list(owner_user_id:, channel_key:)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def show(owner_user_id:, endpoint_id:)
|
|
27
|
+
Query.show(owner_user_id:, endpoint_id:)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def mark_invalid(owner_user_id:, endpoint_id:)
|
|
31
|
+
MarkInvalid.call(owner_user_id:, endpoint_id:)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def begin_verification(owner_user_id:, endpoint_id:)
|
|
35
|
+
BeginVerification.call(owner_user_id:, endpoint_id:)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def mark_verified(owner_user_id:, endpoint_id:)
|
|
39
|
+
MarkVerified.call(owner_user_id:, endpoint_id:)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def mark_verification_failed(owner_user_id:, endpoint_id:)
|
|
43
|
+
MarkVerificationFailed.call(owner_user_id:, endpoint_id:)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def reset_verification(owner_user_id:, endpoint_id:)
|
|
47
|
+
ResetVerification.call(owner_user_id:, endpoint_id:)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def verify_pushover!(owner_user_id:, endpoint_id:)
|
|
51
|
+
Pushover::Verify.call(owner_user_id:, endpoint_id:)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CommandTower
|
|
4
|
+
module Messaging
|
|
5
|
+
module Execution
|
|
6
|
+
AdapterRequest = Data.define(
|
|
7
|
+
:channel_delivery_id,
|
|
8
|
+
:communication_id,
|
|
9
|
+
:channel_key,
|
|
10
|
+
:attempt_id,
|
|
11
|
+
:rendered,
|
|
12
|
+
) do
|
|
13
|
+
def self.build(channel_delivery_id:, communication_id:, channel_key:, attempt_id:, rendered:)
|
|
14
|
+
raise InvalidAdapterContractError, "arbitrary hashes are not accepted" if [channel_delivery_id, communication_id, channel_key, attempt_id].any? { |v| v.is_a?(Hash) }
|
|
15
|
+
raise InvalidAdapterContractError, "channel_delivery_id is required" if blank?(channel_delivery_id)
|
|
16
|
+
raise InvalidAdapterContractError, "communication_id is required" if blank?(communication_id)
|
|
17
|
+
raise InvalidAdapterContractError, "attempt_id is required" if blank?(attempt_id)
|
|
18
|
+
raise InvalidAdapterContractError, "channel_key is required" if blank?(channel_key)
|
|
19
|
+
raise InvalidAdapterContractError, "channel_key must be a String" unless channel_key.is_a?(String)
|
|
20
|
+
raise InvalidAdapterContractError, "rendered is required" if rendered.nil?
|
|
21
|
+
unless rendered.is_a?(Rendering::RenderedPayload) ||
|
|
22
|
+
rendered.is_a?(Rendering::RenderedSmsPayload) ||
|
|
23
|
+
rendered.is_a?(Rendering::RenderedPushoverPayload)
|
|
24
|
+
raise InvalidAdapterContractError,
|
|
25
|
+
"rendered must be a RenderedPayload, RenderedSmsPayload, or RenderedPushoverPayload"
|
|
26
|
+
end
|
|
27
|
+
raise InvalidAdapterContractError, "rendered must be frozen" unless rendered.frozen?
|
|
28
|
+
|
|
29
|
+
new(
|
|
30
|
+
channel_delivery_id:,
|
|
31
|
+
communication_id:,
|
|
32
|
+
channel_key:,
|
|
33
|
+
attempt_id:,
|
|
34
|
+
rendered:,
|
|
35
|
+
).freeze
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.blank?(value)
|
|
39
|
+
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
|
40
|
+
end
|
|
41
|
+
private_class_method :blank?
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CommandTower
|
|
4
|
+
module Messaging
|
|
5
|
+
module Execution
|
|
6
|
+
AdapterResult = Data.define(
|
|
7
|
+
:outcome,
|
|
8
|
+
:normalized_provider_status,
|
|
9
|
+
:provider_message_id,
|
|
10
|
+
:error_code,
|
|
11
|
+
) do
|
|
12
|
+
OUTCOMES = %i[success retryable_failure terminal_failure].freeze
|
|
13
|
+
|
|
14
|
+
def self.build(
|
|
15
|
+
outcome:,
|
|
16
|
+
normalized_provider_status: nil,
|
|
17
|
+
provider_message_id: nil,
|
|
18
|
+
error_code: nil
|
|
19
|
+
)
|
|
20
|
+
raise InvalidAdapterContractError, "arbitrary hashes are not accepted as outcome" if outcome.is_a?(Hash)
|
|
21
|
+
raise InvalidAdapterContractError, "raw exception objects are not accepted" if exception_like?(outcome) ||
|
|
22
|
+
exception_like?(normalized_provider_status) ||
|
|
23
|
+
exception_like?(provider_message_id) ||
|
|
24
|
+
exception_like?(error_code)
|
|
25
|
+
raise InvalidAdapterContractError, "raw exception messages are not accepted" if looks_like_exception_message?(error_code)
|
|
26
|
+
|
|
27
|
+
normalized_outcome = normalize_outcome!(outcome)
|
|
28
|
+
validate_optional_string!(normalized_provider_status, "normalized_provider_status")
|
|
29
|
+
validate_optional_string!(provider_message_id, "provider_message_id")
|
|
30
|
+
validate_optional_string!(error_code, "error_code")
|
|
31
|
+
|
|
32
|
+
new(
|
|
33
|
+
outcome: normalized_outcome,
|
|
34
|
+
normalized_provider_status:,
|
|
35
|
+
provider_message_id:,
|
|
36
|
+
error_code:,
|
|
37
|
+
).freeze
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.normalize_outcome!(outcome)
|
|
41
|
+
value = outcome.is_a?(String) ? outcome.to_sym : outcome
|
|
42
|
+
unless OUTCOMES.include?(value)
|
|
43
|
+
raise InvalidAdapterContractError, "unsupported outcome: #{outcome.inspect}"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
value
|
|
47
|
+
end
|
|
48
|
+
private_class_method :normalize_outcome!
|
|
49
|
+
|
|
50
|
+
def self.validate_optional_string!(value, field_name)
|
|
51
|
+
return if value.nil?
|
|
52
|
+
raise InvalidAdapterContractError, "#{field_name} must be a String" unless value.is_a?(String)
|
|
53
|
+
end
|
|
54
|
+
private_class_method :validate_optional_string!
|
|
55
|
+
|
|
56
|
+
def self.exception_like?(value)
|
|
57
|
+
value.is_a?(Exception)
|
|
58
|
+
end
|
|
59
|
+
private_class_method :exception_like?
|
|
60
|
+
|
|
61
|
+
def self.looks_like_exception_message?(value)
|
|
62
|
+
# Reject multi-line or stack-trace-like payloads masquerading as error_code.
|
|
63
|
+
value.is_a?(String) && (value.include?("\n") || value.match?(/\.rb:\d+:in/))
|
|
64
|
+
end
|
|
65
|
+
private_class_method :looks_like_exception_message?
|
|
66
|
+
|
|
67
|
+
def success?
|
|
68
|
+
outcome == :success
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def retryable_failure?
|
|
72
|
+
outcome == :retryable_failure
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def terminal_failure?
|
|
76
|
+
outcome == :terminal_failure
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "net/smtp"
|
|
4
|
+
require "socket"
|
|
5
|
+
require "timeout"
|
|
6
|
+
|
|
7
|
+
module CommandTower
|
|
8
|
+
module Messaging
|
|
9
|
+
module Execution
|
|
10
|
+
module Adapters
|
|
11
|
+
module Email
|
|
12
|
+
class Adapter
|
|
13
|
+
RETRYABLE_ERRORS = [
|
|
14
|
+
Timeout::Error,
|
|
15
|
+
Net::OpenTimeout,
|
|
16
|
+
Net::ReadTimeout,
|
|
17
|
+
Errno::ECONNREFUSED,
|
|
18
|
+
Errno::ECONNRESET,
|
|
19
|
+
Errno::EHOSTUNREACH,
|
|
20
|
+
Errno::ENETUNREACH,
|
|
21
|
+
SocketError,
|
|
22
|
+
].freeze
|
|
23
|
+
|
|
24
|
+
TERMINAL_SMTP_ERRORS = [
|
|
25
|
+
Net::SMTPAuthenticationError,
|
|
26
|
+
Net::SMTPFatalError,
|
|
27
|
+
Net::SMTPSyntaxError,
|
|
28
|
+
].freeze
|
|
29
|
+
|
|
30
|
+
def call(request:)
|
|
31
|
+
raise ArgumentError, "request must be an AdapterRequest" unless request.is_a?(AdapterRequest)
|
|
32
|
+
|
|
33
|
+
begin
|
|
34
|
+
message = Messaging::ChannelMailer.deliver_rendered(rendered: request.rendered).deliver
|
|
35
|
+
AdapterResult.build(
|
|
36
|
+
outcome: :success,
|
|
37
|
+
normalized_provider_status: "accepted",
|
|
38
|
+
provider_message_id: extract_message_id(message),
|
|
39
|
+
)
|
|
40
|
+
rescue ArgumentError
|
|
41
|
+
AdapterResult.build(
|
|
42
|
+
outcome: :terminal_failure,
|
|
43
|
+
error_code: "invalid_recipient",
|
|
44
|
+
)
|
|
45
|
+
rescue *TERMINAL_SMTP_ERRORS
|
|
46
|
+
AdapterResult.build(
|
|
47
|
+
outcome: :terminal_failure,
|
|
48
|
+
error_code: "smtp_rejected",
|
|
49
|
+
)
|
|
50
|
+
rescue *RETRYABLE_ERRORS
|
|
51
|
+
AdapterResult.build(
|
|
52
|
+
outcome: :retryable_failure,
|
|
53
|
+
error_code: "smtp_transient",
|
|
54
|
+
)
|
|
55
|
+
rescue StandardError
|
|
56
|
+
AdapterResult.build(
|
|
57
|
+
outcome: :retryable_failure,
|
|
58
|
+
error_code: "smtp_transient",
|
|
59
|
+
)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def extract_message_id(message)
|
|
66
|
+
return nil unless message.respond_to?(:message_id)
|
|
67
|
+
|
|
68
|
+
id = message.message_id
|
|
69
|
+
return nil if id.nil? || id.to_s.strip.empty?
|
|
70
|
+
|
|
71
|
+
id.to_s
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CommandTower
|
|
4
|
+
module Messaging
|
|
5
|
+
module Execution
|
|
6
|
+
module Adapters
|
|
7
|
+
module Email
|
|
8
|
+
class Configuration
|
|
9
|
+
SUPPORTED_DELIVERY_METHODS = %i[test smtp].freeze
|
|
10
|
+
SMTP_STRING_KEYS = %i[address user_name password authentication].freeze
|
|
11
|
+
|
|
12
|
+
def self.email_configured?
|
|
13
|
+
new.email_configured?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def email_configured?
|
|
17
|
+
method = CommandTower.config.email.delivery_method
|
|
18
|
+
method = method.to_sym if method.respond_to?(:to_sym)
|
|
19
|
+
|
|
20
|
+
case method
|
|
21
|
+
when :test
|
|
22
|
+
true
|
|
23
|
+
when :smtp
|
|
24
|
+
smtp_contract_complete?
|
|
25
|
+
else
|
|
26
|
+
false
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def smtp_contract_complete?
|
|
33
|
+
settings = Rails.configuration.action_mailer.smtp_settings
|
|
34
|
+
return false unless settings.is_a?(Hash)
|
|
35
|
+
|
|
36
|
+
SMTP_STRING_KEYS.each do |key|
|
|
37
|
+
value = settings[key] || settings[key.to_s]
|
|
38
|
+
return false if value.nil? || value.to_s.strip.empty?
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
port = settings[:port] || settings["port"]
|
|
42
|
+
return false unless port.is_a?(Integer)
|
|
43
|
+
|
|
44
|
+
tls = settings[:enable_starttls_auto]
|
|
45
|
+
tls = settings["enable_starttls_auto"] if tls.nil?
|
|
46
|
+
return false unless tls == true || tls == false
|
|
47
|
+
|
|
48
|
+
true
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CommandTower
|
|
4
|
+
module Messaging
|
|
5
|
+
module Execution
|
|
6
|
+
module Adapters
|
|
7
|
+
class FakeAdapter
|
|
8
|
+
attr_reader :last_request
|
|
9
|
+
|
|
10
|
+
def initialize(outcome: :success, normalized_provider_status: nil, provider_message_id: nil, error_code: nil)
|
|
11
|
+
@outcome = outcome
|
|
12
|
+
@normalized_provider_status = normalized_provider_status
|
|
13
|
+
@provider_message_id = provider_message_id
|
|
14
|
+
@error_code = error_code
|
|
15
|
+
@last_request = nil
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def call(request:)
|
|
19
|
+
raise ArgumentError, "request must be an AdapterRequest" unless request.is_a?(AdapterRequest)
|
|
20
|
+
|
|
21
|
+
@last_request = request
|
|
22
|
+
|
|
23
|
+
AdapterResult.build(
|
|
24
|
+
outcome: @outcome,
|
|
25
|
+
normalized_provider_status: @normalized_provider_status,
|
|
26
|
+
provider_message_id: @provider_message_id || "fake-#{request.attempt_id}",
|
|
27
|
+
error_code: @error_code,
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CommandTower
|
|
4
|
+
module Messaging
|
|
5
|
+
module Execution
|
|
6
|
+
module Adapters
|
|
7
|
+
module Pushover
|
|
8
|
+
# Execution adapter: decrypts credentials for the readiness-resolved
|
|
9
|
+
# endpoint and sends via Messaging::Pushover::Transport.
|
|
10
|
+
class Adapter
|
|
11
|
+
CREDENTIAL_REJECTION_CODES = %i[
|
|
12
|
+
invalid_user
|
|
13
|
+
invalid_token
|
|
14
|
+
invalid_credentials
|
|
15
|
+
].freeze
|
|
16
|
+
|
|
17
|
+
def initialize(configuration: nil, transport: nil, secret_reader: nil)
|
|
18
|
+
@configuration = configuration || Configuration.new
|
|
19
|
+
@transport = transport || Messaging::Pushover::Transport
|
|
20
|
+
@secret_reader = secret_reader || Endpoints::SecretReader
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def call(request:)
|
|
24
|
+
raise ArgumentError, "request must be an AdapterRequest" unless request.is_a?(AdapterRequest)
|
|
25
|
+
|
|
26
|
+
rendered = request.rendered
|
|
27
|
+
unless rendered.is_a?(Rendering::RenderedPushoverPayload)
|
|
28
|
+
return AdapterResult.build(outcome: :terminal_failure, error_code: "render_failed")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
unless @configuration.pushover_configured?
|
|
32
|
+
return AdapterResult.build(outcome: :terminal_failure, error_code: "adapter_unconfigured")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
endpoint_id = Integer(rendered.recipient_address, exception: false)
|
|
36
|
+
if endpoint_id.nil? || endpoint_id <= 0
|
|
37
|
+
return AdapterResult.build(outcome: :terminal_failure, error_code: "invalid_recipient")
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
delivery = Messaging::ChannelDelivery.includes(:communication).find_by(id: request.channel_delivery_id)
|
|
41
|
+
owner_user_id = delivery&.communication&.user_id
|
|
42
|
+
if owner_user_id.nil?
|
|
43
|
+
return AdapterResult.build(outcome: :terminal_failure, error_code: "recipient_missing")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
credentials = read_credentials(owner_user_id:, endpoint_id:)
|
|
47
|
+
return credentials if credentials.is_a?(AdapterResult)
|
|
48
|
+
|
|
49
|
+
result = @transport.send_message!(
|
|
50
|
+
user_key: credentials.fetch(:user_key),
|
|
51
|
+
application_token: credentials.fetch(:application_token),
|
|
52
|
+
title: rendered.title,
|
|
53
|
+
message: rendered.message,
|
|
54
|
+
)
|
|
55
|
+
map_result(result, owner_user_id:, endpoint_id:)
|
|
56
|
+
rescue StandardError
|
|
57
|
+
AdapterResult.build(outcome: :retryable_failure, error_code: "pushover_transient")
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
private
|
|
61
|
+
|
|
62
|
+
def read_credentials(owner_user_id:, endpoint_id:)
|
|
63
|
+
@secret_reader.read_pushover_credentials!(owner_user_id:, endpoint_id:)
|
|
64
|
+
rescue Endpoints::NotFoundError, Endpoints::ValidationError
|
|
65
|
+
AdapterResult.build(outcome: :terminal_failure, error_code: "recipient_missing")
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def map_result(result, owner_user_id:, endpoint_id:)
|
|
69
|
+
unless result.is_a?(Messaging::Pushover::Result)
|
|
70
|
+
return AdapterResult.build(outcome: :retryable_failure, error_code: "pushover_transient")
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
if result.success?
|
|
74
|
+
return AdapterResult.build(
|
|
75
|
+
outcome: :success,
|
|
76
|
+
normalized_provider_status: "accepted",
|
|
77
|
+
provider_message_id: result.provider_request_id,
|
|
78
|
+
)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
code = result.error_code.to_sym
|
|
82
|
+
if CREDENTIAL_REJECTION_CODES.include?(code)
|
|
83
|
+
mark_invalid_best_effort!(owner_user_id:, endpoint_id:)
|
|
84
|
+
return AdapterResult.build(outcome: :terminal_failure, error_code: "pushover_rejected")
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
case code
|
|
88
|
+
when :adapter_disabled
|
|
89
|
+
AdapterResult.build(outcome: :terminal_failure, error_code: "adapter_unconfigured")
|
|
90
|
+
when :timeout, :provider_unavailable, :rate_limited
|
|
91
|
+
AdapterResult.build(outcome: :retryable_failure, error_code: "pushover_transient")
|
|
92
|
+
else
|
|
93
|
+
AdapterResult.build(outcome: :retryable_failure, error_code: "pushover_transient")
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def mark_invalid_best_effort!(owner_user_id:, endpoint_id:)
|
|
98
|
+
Endpoints.mark_invalid(owner_user_id:, endpoint_id:)
|
|
99
|
+
rescue StandardError
|
|
100
|
+
nil
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CommandTower
|
|
4
|
+
module Messaging
|
|
5
|
+
module Execution
|
|
6
|
+
module Adapters
|
|
7
|
+
module Pushover
|
|
8
|
+
# Platform readiness detector for Pushover delivery.
|
|
9
|
+
# User-owned credentials (no host app token). Ready when transport adapter
|
|
10
|
+
# is fake, log, or http — disabled never counts as platform_configured.
|
|
11
|
+
class Configuration
|
|
12
|
+
CONFIGURED_ADAPTERS = %w[fake log http].freeze
|
|
13
|
+
|
|
14
|
+
def self.pushover_configured?
|
|
15
|
+
new.pushover_configured?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def pushover_configured?
|
|
19
|
+
CONFIGURED_ADAPTERS.include?(adapter_name)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def adapter_name
|
|
23
|
+
CommandTower.config.messaging.pushover.adapter.to_s
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "net/http"
|
|
4
|
+
require "socket"
|
|
5
|
+
require "timeout"
|
|
6
|
+
|
|
7
|
+
module CommandTower
|
|
8
|
+
module Messaging
|
|
9
|
+
module Execution
|
|
10
|
+
module Adapters
|
|
11
|
+
module Sms
|
|
12
|
+
class Adapter
|
|
13
|
+
E164 = /\A\+[1-9]\d{1,14}\z/
|
|
14
|
+
|
|
15
|
+
RETRYABLE_HTTP_STATUSES = [408, 429, 500, 502, 503, 504].freeze
|
|
16
|
+
AUTH_HTTP_STATUSES = [401, 403].freeze
|
|
17
|
+
|
|
18
|
+
def initialize(http_client: nil, configuration: nil)
|
|
19
|
+
@http_client = http_client
|
|
20
|
+
@configuration = configuration || Configuration.new
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def call(request:)
|
|
24
|
+
raise ArgumentError, "request must be an AdapterRequest" unless request.is_a?(AdapterRequest)
|
|
25
|
+
rendered = request.rendered
|
|
26
|
+
unless rendered.is_a?(Rendering::RenderedSmsPayload)
|
|
27
|
+
return AdapterResult.build(outcome: :terminal_failure, error_code: "render_failed")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
unless @configuration.sms_configured?
|
|
31
|
+
return AdapterResult.build(outcome: :terminal_failure, error_code: "adapter_unconfigured")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
to = rendered.recipient_address.to_s
|
|
35
|
+
unless to.match?(E164)
|
|
36
|
+
return AdapterResult.build(outcome: :terminal_failure, error_code: "invalid_recipient")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
begin
|
|
40
|
+
response = client.create_message(
|
|
41
|
+
to:,
|
|
42
|
+
body: rendered.body,
|
|
43
|
+
from: @configuration.use_messaging_service? ? nil : @configuration.from_number,
|
|
44
|
+
messaging_service_sid: @configuration.use_messaging_service? ? @configuration.messaging_service_sid : nil,
|
|
45
|
+
)
|
|
46
|
+
map_response(response)
|
|
47
|
+
rescue Timeout::Error, Net::OpenTimeout, Net::ReadTimeout
|
|
48
|
+
AdapterResult.build(outcome: :retryable_failure, error_code: "twilio_transient")
|
|
49
|
+
rescue Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH, Errno::ENETUNREACH, SocketError
|
|
50
|
+
AdapterResult.build(outcome: :retryable_failure, error_code: "twilio_transient")
|
|
51
|
+
rescue StandardError
|
|
52
|
+
AdapterResult.build(outcome: :retryable_failure, error_code: "twilio_transient")
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
def client
|
|
59
|
+
@http_client || TwilioHttpClient.new(
|
|
60
|
+
account_sid: @configuration.account_sid,
|
|
61
|
+
auth_token: @configuration.auth_token,
|
|
62
|
+
)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def map_response(response)
|
|
66
|
+
if response[:ok]
|
|
67
|
+
return AdapterResult.build(
|
|
68
|
+
outcome: :success,
|
|
69
|
+
normalized_provider_status: response[:provider_status] || "queued",
|
|
70
|
+
provider_message_id: response[:sid],
|
|
71
|
+
)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
status = response[:status_code].to_i
|
|
75
|
+
if AUTH_HTTP_STATUSES.include?(status)
|
|
76
|
+
return AdapterResult.build(outcome: :terminal_failure, error_code: "twilio_auth_failed")
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
if RETRYABLE_HTTP_STATUSES.include?(status)
|
|
80
|
+
return AdapterResult.build(outcome: :retryable_failure, error_code: "twilio_transient")
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
AdapterResult.build(outcome: :terminal_failure, error_code: "twilio_rejected")
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CommandTower
|
|
4
|
+
module Messaging
|
|
5
|
+
module Execution
|
|
6
|
+
module Adapters
|
|
7
|
+
module Sms
|
|
8
|
+
# Platform readiness detector for notification SMS.
|
|
9
|
+
# Ready only when adapter is twilio and credentials + sender are complete.
|
|
10
|
+
# disabled / fake / log never count as platform_configured.
|
|
11
|
+
class Configuration
|
|
12
|
+
def self.sms_configured?
|
|
13
|
+
new.sms_configured?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def sms_configured?
|
|
17
|
+
return false unless adapter_name == "twilio"
|
|
18
|
+
|
|
19
|
+
account_sid.present? && auth_token.present? && sender_identity_present?
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def adapter_name
|
|
23
|
+
CommandTower.config.messaging.sms.adapter.to_s
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def account_sid
|
|
27
|
+
CredentialResolution.resolve(:twilio).account_sid
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def auth_token
|
|
31
|
+
CredentialResolution.resolve(:twilio).auth_token
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Prefer Messaging Service SID when both sender mechanisms are set.
|
|
35
|
+
def messaging_service_sid
|
|
36
|
+
CommandTower.config.messaging.sms.messaging_service_sid.to_s.strip.presence
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def from_number
|
|
40
|
+
configured = CommandTower.config.messaging.sms.from_number.to_s.strip.presence
|
|
41
|
+
configured ||
|
|
42
|
+
ENV["TWILIO_FROM"].to_s.strip.presence ||
|
|
43
|
+
ENV["TWILIO_FROM_NUMBER"].to_s.strip.presence
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def sender_identity_present?
|
|
47
|
+
messaging_service_sid.present? || from_number.present?
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def use_messaging_service?
|
|
51
|
+
messaging_service_sid.present?
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CommandTower
|
|
4
|
+
module Messaging
|
|
5
|
+
module Execution
|
|
6
|
+
module Adapters
|
|
7
|
+
module Sms
|
|
8
|
+
# Dev-only log adapter. Does not mark platform_configured.
|
|
9
|
+
class LogAdapter
|
|
10
|
+
def call(request:)
|
|
11
|
+
raise ArgumentError, "request must be an AdapterRequest" unless request.is_a?(AdapterRequest)
|
|
12
|
+
|
|
13
|
+
Rails.logger.info(
|
|
14
|
+
{
|
|
15
|
+
component: "command_tower.messaging",
|
|
16
|
+
event: "messaging.sms.log_adapter",
|
|
17
|
+
channel_delivery_id: request.channel_delivery_id,
|
|
18
|
+
attempt_id: request.attempt_id,
|
|
19
|
+
channel_key: request.channel_key,
|
|
20
|
+
}.to_json,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
AdapterResult.build(
|
|
24
|
+
outcome: :success,
|
|
25
|
+
normalized_provider_status: "logged",
|
|
26
|
+
provider_message_id: "log-#{request.attempt_id}",
|
|
27
|
+
)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|