diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index 0207708b8b..36508a0817 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -1,6 +1,7 @@ groups(['api', 'messaging']) ->label('audits.event', 'provider.create') ->label('audits.resource', 'provider/{response.$id}') + ->label('event', 'providers.[providerId].create') ->label('scope', 'providers.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -47,9 +49,10 @@ App::post('/v1/messaging/providers/mailgun') ->param('domain', '', new Text(0), 'Mailgun Domain.') ->param('isEuRegion', false, new Boolean(), 'Set as EU region.') ->param('enabled', true, new Boolean(), 'Set as enabled.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, string $from, string $apiKey, string $domain, bool $isEuRegion, bool $enabled, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, string $from, string $apiKey, string $domain, bool $isEuRegion, bool $enabled, Event $queueForEvents, Database $dbForProject, Response $response) { $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = new Document([ @@ -85,6 +88,9 @@ App::post('/v1/messaging/providers/mailgun') throw new Exception(Exception::PROVIDER_ALREADY_EXISTS); } + $queueForEvents + ->setParam('providerId', $provider->getId()); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($provider, Response::MODEL_PROVIDER); @@ -95,6 +101,7 @@ App::post('/v1/messaging/providers/sendgrid') ->groups(['api', 'messaging']) ->label('audits.event', 'provider.create') ->label('audits.resource', 'provider/{response.$id}') + ->label('event', 'providers.[providerId].create') ->label('scope', 'providers.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -108,9 +115,10 @@ App::post('/v1/messaging/providers/sendgrid') ->param('from', '', new Text(256), 'Sender email address.') ->param('apiKey', '', new Text(0), 'Sendgrid API key.') ->param('enabled', true, new Boolean(), 'Set as enabled.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, string $from, string $apiKey, bool $enabled, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, string $from, string $apiKey, bool $enabled, Event $queueForEvents, Database $dbForProject, Response $response) { $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = new Document([ '$id' => $providerId, @@ -143,6 +151,9 @@ App::post('/v1/messaging/providers/sendgrid') throw new Exception(Exception::PROVIDER_ALREADY_EXISTS); } + $queueForEvents + ->setParam('providerId', $provider->getId()); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($provider, Response::MODEL_PROVIDER); @@ -154,6 +165,7 @@ App::post('/v1/messaging/providers/msg91') ->label('audits.event', 'provider.create') ->label('audits.resource', 'provider/{response.$id}') ->label('scope', 'providers.write') + ->label('event', 'providers.[providerId].create') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') ->label('sdk.method', 'createMsg91Provider') @@ -167,9 +179,10 @@ App::post('/v1/messaging/providers/msg91') ->param('senderId', '', new Text(0), 'Msg91 Sender ID.') ->param('authKey', '', new Text(0), 'Msg91 Auth Key.') ->param('enabled', true, new Boolean(), 'Set as enabled.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, string $from, string $senderId, string $authKey, bool $enabled, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, string $from, string $senderId, string $authKey, bool $enabled, Event $queueForEvents, Database $dbForProject, Response $response) { $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = new Document([ '$id' => $providerId, @@ -203,6 +216,9 @@ App::post('/v1/messaging/providers/msg91') throw new Exception(Exception::PROVIDER_ALREADY_EXISTS); } + $queueForEvents + ->setParam('providerId', $provider->getId()); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($provider, Response::MODEL_PROVIDER); @@ -213,6 +229,7 @@ App::post('/v1/messaging/providers/telesign') ->groups(['api', 'messaging']) ->label('audits.event', 'provider.create') ->label('audits.resource', 'provider/{response.$id}') + ->label('event', 'providers.[providerId].create') ->label('scope', 'providers.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -227,9 +244,10 @@ App::post('/v1/messaging/providers/telesign') ->param('username', '', new Text(0), 'Telesign username.') ->param('password', '', new Text(0), 'Telesign password.') ->param('enabled', true, new Boolean(), 'Set as enabled.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, string $from, string $username, string $password, bool $enabled, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, string $from, string $username, string $password, bool $enabled, Event $queueForEvents, Database $dbForProject, Response $response) { $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = new Document([ '$id' => $providerId, @@ -263,6 +281,9 @@ App::post('/v1/messaging/providers/telesign') throw new Exception(Exception::PROVIDER_ALREADY_EXISTS); } + $queueForEvents + ->setParam('providerId', $provider->getId()); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($provider, Response::MODEL_PROVIDER); @@ -273,6 +294,7 @@ App::post('/v1/messaging/providers/textmagic') ->groups(['api', 'messaging']) ->label('audits.event', 'provider.create') ->label('audits.resource', 'provider/{response.$id}') + ->label('event', 'providers.[providerId].create') ->label('scope', 'providers.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -287,9 +309,10 @@ App::post('/v1/messaging/providers/textmagic') ->param('username', '', new Text(0), 'Textmagic username.') ->param('apiKey', '', new Text(0), 'Textmagic apiKey.') ->param('enabled', true, new Boolean(), 'Set as enabled.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, string $from, string $username, string $apiKey, bool $enabled, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, string $from, string $username, string $apiKey, bool $enabled, Event $queueForEvents, Database $dbForProject, Response $response) { $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = new Document([ '$id' => $providerId, @@ -323,6 +346,9 @@ App::post('/v1/messaging/providers/textmagic') throw new Exception(Exception::PROVIDER_ALREADY_EXISTS); } + $queueForEvents + ->setParam('providerId', $provider->getId()); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($provider, Response::MODEL_PROVIDER); @@ -333,6 +359,7 @@ App::post('/v1/messaging/providers/twilio') ->groups(['api', 'messaging']) ->label('audits.event', 'provider.create') ->label('audits.resource', 'provider/{response.$id}') + ->label('event', 'providers.[providerId].create') ->label('scope', 'providers.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -347,9 +374,10 @@ App::post('/v1/messaging/providers/twilio') ->param('accountSid', '', new Text(0), 'Twilio account secret ID.') ->param('authToken', '', new Text(0), 'Twilio authentication token.') ->param('enabled', true, new Boolean(), 'Set as enabled.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, string $from, string $accountSid, string $authToken, bool $enabled, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, string $from, string $accountSid, string $authToken, bool $enabled, Event $queueForEvents, Database $dbForProject, Response $response) { $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = new Document([ '$id' => $providerId, @@ -383,6 +411,9 @@ App::post('/v1/messaging/providers/twilio') throw new Exception(Exception::PROVIDER_ALREADY_EXISTS); } + $queueForEvents + ->setParam('providerId', $provider->getId()); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($provider, Response::MODEL_PROVIDER); @@ -393,6 +424,7 @@ App::post('/v1/messaging/providers/vonage') ->groups(['api', 'messaging']) ->label('audits.event', 'provider.create') ->label('audits.resource', 'provider/{response.$id}') + ->label('event', 'providers.[providerId].create') ->label('scope', 'providers.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -407,9 +439,10 @@ App::post('/v1/messaging/providers/vonage') ->param('apiKey', '', new Text(0), 'Vonage API key.') ->param('apiSecret', '', new Text(0), 'Vonage API secret.') ->param('enabled', true, new Boolean(), 'Set as enabled.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, string $from, string $apiKey, string $apiSecret, bool $enabled, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, string $from, string $apiKey, string $apiSecret, bool $enabled, Event $queueForEvents, Database $dbForProject, Response $response) { $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = new Document([ '$id' => $providerId, @@ -443,6 +476,9 @@ App::post('/v1/messaging/providers/vonage') throw new Exception(Exception::PROVIDER_ALREADY_EXISTS); } + $queueForEvents + ->setParam('providerId', $provider->getId()); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($provider, Response::MODEL_PROVIDER); @@ -453,6 +489,7 @@ App::post('/v1/messaging/providers/fcm') ->groups(['api', 'messaging']) ->label('audits.event', 'provider.create') ->label('audits.resource', 'provider/{response.$id}') + ->label('event', 'providers.[providerId].create') ->label('scope', 'providers.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -465,9 +502,10 @@ App::post('/v1/messaging/providers/fcm') ->param('name', '', new Text(128), 'Provider name.') ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('serverKey', '', new Text(0), 'FCM server key.') + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, bool $enabled, string $serverKey, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, bool $enabled, string $serverKey, Event $queueForEvents, Database $dbForProject, Response $response) { $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = new Document([ '$id' => $providerId, @@ -497,6 +535,9 @@ App::post('/v1/messaging/providers/fcm') throw new Exception(Exception::PROVIDER_ALREADY_EXISTS); } + $queueForEvents + ->setParam('providerId', $provider->getId()); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($provider, Response::MODEL_PROVIDER); @@ -507,6 +548,7 @@ App::post('/v1/messaging/providers/apns') ->groups(['api', 'messaging']) ->label('audits.event', 'provider.create') ->label('audits.resource', 'provider/{response.$id}') + ->label('event', 'providers.[providerId].create') ->label('scope', 'providers.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -523,9 +565,10 @@ App::post('/v1/messaging/providers/apns') ->param('teamId', '', new Text(0), 'APNS team ID.') ->param('bundleId', '', new Text(0), 'APNS bundle ID.') ->param('endpoint', '', new Text(0), 'APNS endpoint.') + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, bool $enabled, string $authKey, string $authKeyId, string $teamId, string $bundleId, string $endpoint, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, bool $enabled, string $authKey, string $authKeyId, string $teamId, string $bundleId, string $endpoint, Event $queueForEvents, Database $dbForProject, Response $response) { $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = new Document([ '$id' => $providerId, @@ -559,6 +602,9 @@ App::post('/v1/messaging/providers/apns') throw new Exception(Exception::PROVIDER_ALREADY_EXISTS); } + $queueForEvents + ->setParam('providerId', $provider->getId()); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($provider, Response::MODEL_PROVIDER); @@ -636,6 +682,7 @@ App::patch('/v1/messaging/providers/mailgun/:providerId') ->groups(['api', 'messaging']) ->label('audits.event', 'provider.update') ->label('audits.resource', 'provider/{response.$id}') + ->label('event', 'providers.[providerId].update') ->label('scope', 'providers.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -652,9 +699,10 @@ App::patch('/v1/messaging/providers/mailgun/:providerId') ->param('from', '', new Text(256), 'Sender email address.', true) ->param('apiKey', '', new Text(0), 'Mailgun API Key.', true) ->param('domain', '', new Text(0), 'Mailgun Domain.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, ?bool $enabled, ?bool $internal, ?bool $isEuRegion, string $from, string $apiKey, string $domain, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, ?bool $enabled, ?bool $internal, ?bool $isEuRegion, string $from, string $apiKey, string $domain, Event $queueForEvents, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $providerId); if ($provider->isEmpty()) { @@ -712,6 +760,9 @@ App::patch('/v1/messaging/providers/mailgun/:providerId') $dbForProject->updateDocument('providers', $internalProvider->getId(), $internalProvider); } + $queueForEvents + ->setParam('providerId', $provider->getId()); + $response ->dynamic($provider, Response::MODEL_PROVIDER); }); @@ -721,6 +772,7 @@ App::patch('/v1/messaging/providers/sendgrid/:providerId') ->groups(['api', 'messaging']) ->label('audits.event', 'provider.update') ->label('audits.resource', 'provider/{response.$id}') + ->label('event', 'providers.[providerId].update') ->label('scope', 'providers.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -735,9 +787,10 @@ App::patch('/v1/messaging/providers/sendgrid/:providerId') ->param('internal', null, new Boolean(), 'Set as internal. Internal providers are used in services other than Messaging service such as Authentication service', true) ->param('apiKey', '', new Text(0), 'Sendgrid API key.', true) ->param('from', '', new Text(256), 'Sender email address.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, ?bool $enabled, ?bool $internal, string $apiKey, string $from, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, ?bool $enabled, ?bool $internal, string $apiKey, string $from, Event $queueForEvents, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $providerId); if ($provider->isEmpty()) { @@ -785,6 +838,9 @@ App::patch('/v1/messaging/providers/sendgrid/:providerId') $dbForProject->updateDocument('providers', $internalProvider->getId(), $internalProvider); } + $queueForEvents + ->setParam('providerId', $provider->getId()); + $response ->dynamic($provider, Response::MODEL_PROVIDER); }); @@ -794,6 +850,7 @@ App::patch('/v1/messaging/providers/msg91/:providerId') ->groups(['api', 'messaging']) ->label('audits.event', 'provider.update') ->label('audits.resource', 'provider/{response.$id}') + ->label('event', 'providers.[providerId].update') ->label('scope', 'providers.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -809,9 +866,10 @@ App::patch('/v1/messaging/providers/msg91/:providerId') ->param('senderId', '', new Text(0), 'Msg91 Sender ID.', true) ->param('authKey', '', new Text(0), 'Msg91 Auth Key.', true) ->param('from', '', new Text(256), 'Sender number.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, ?bool $enabled, ?bool $internal, string $senderId, string $authKey, string $from, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, ?bool $enabled, ?bool $internal, string $senderId, string $authKey, string $from, Event $queueForEvents, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $providerId); if ($provider->isEmpty()) { @@ -865,6 +923,9 @@ App::patch('/v1/messaging/providers/msg91/:providerId') $dbForProject->updateDocument('providers', $internalProvider->getId(), $internalProvider); } + $queueForEvents + ->setParam('providerId', $provider->getId()); + $response ->dynamic($provider, Response::MODEL_PROVIDER); }); @@ -874,6 +935,7 @@ App::patch('/v1/messaging/providers/telesign/:providerId') ->groups(['api', 'messaging']) ->label('audits.event', 'provider.update') ->label('audits.resource', 'provider/{response.$id}') + ->label('event', 'providers.[providerId].update') ->label('scope', 'providers.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -889,9 +951,10 @@ App::patch('/v1/messaging/providers/telesign/:providerId') ->param('username', '', new Text(0), 'Telesign username.', true) ->param('password', '', new Text(0), 'Telesign password.', true) ->param('from', '', new Text(256), 'Sender number.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, ?bool $enabled, ?bool $internal, string $username, string $password, string $from, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, ?bool $enabled, ?bool $internal, string $username, string $password, string $from, Event $queueForEvents, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $providerId); if ($provider->isEmpty()) { @@ -945,6 +1008,9 @@ App::patch('/v1/messaging/providers/telesign/:providerId') $dbForProject->updateDocument('providers', $internalProvider->getId(), $internalProvider); } + $queueForEvents + ->setParam('providerId', $provider->getId()); + $response ->dynamic($provider, Response::MODEL_PROVIDER); }); @@ -954,6 +1020,7 @@ App::patch('/v1/messaging/providers/textmagic/:providerId') ->groups(['api', 'messaging']) ->label('audits.event', 'provider.update') ->label('audits.resource', 'provider/{response.$id}') + ->label('event', 'providers.[providerId].update') ->label('scope', 'providers.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -969,9 +1036,10 @@ App::patch('/v1/messaging/providers/textmagic/:providerId') ->param('username', '', new Text(0), 'Textmagic username.', true) ->param('apiKey', '', new Text(0), 'Textmagic apiKey.', true) ->param('from', '', new Text(256), 'Sender number.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, ?bool $enabled, ?bool $internal, string $username, string $apiKey, string $from, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, ?bool $enabled, ?bool $internal, string $username, string $apiKey, string $from, Event $queueForEvents, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $providerId); if ($provider->isEmpty()) { @@ -1025,6 +1093,9 @@ App::patch('/v1/messaging/providers/textmagic/:providerId') $dbForProject->updateDocument('providers', $internalProvider->getId(), $internalProvider); } + $queueForEvents + ->setParam('providerId', $provider->getId()); + $response ->dynamic($provider, Response::MODEL_PROVIDER); }); @@ -1034,6 +1105,7 @@ App::patch('/v1/messaging/providers/twilio/:providerId') ->groups(['api', 'messaging']) ->label('audits.event', 'provider.update') ->label('audits.resource', 'provider/{response.$id}') + ->label('event', 'providers.[providerId].update') ->label('scope', 'providers.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -1049,9 +1121,10 @@ App::patch('/v1/messaging/providers/twilio/:providerId') ->param('accountSid', null, new Text(0), 'Twilio account secret ID.', true) ->param('authToken', null, new Text(0), 'Twilio authentication token.', true) ->param('from', '', new Text(256), 'Sender number.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, ?bool $enabled, ?bool $internal, string $accountSid, string $authToken, string $from, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, ?bool $enabled, ?bool $internal, string $accountSid, string $authToken, string $from, Event $queueForEvents, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $providerId); if ($provider->isEmpty()) { @@ -1105,6 +1178,9 @@ App::patch('/v1/messaging/providers/twilio/:providerId') $dbForProject->updateDocument('providers', $internalProvider->getId(), $internalProvider); } + $queueForEvents + ->setParam('providerId', $provider->getId()); + $response ->dynamic($provider, Response::MODEL_PROVIDER); }); @@ -1114,6 +1190,7 @@ App::patch('/v1/messaging/providers/vonage/:providerId') ->groups(['api', 'messaging']) ->label('audits.event', 'provider.update') ->label('audits.resource', 'provider/{response.$id}') + ->label('event', 'providers.[providerId].update') ->label('scope', 'providers.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -1129,9 +1206,10 @@ App::patch('/v1/messaging/providers/vonage/:providerId') ->param('apiKey', '', new Text(0), 'Vonage API key.', true) ->param('apiSecret', '', new Text(0), 'Vonage API secret.', true) ->param('from', '', new Text(256), 'Sender number.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, ?bool $enabled, ?bool $internal, string $apiKey, string $apiSecret, string $from, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, ?bool $enabled, ?bool $internal, string $apiKey, string $apiSecret, string $from, Event $queueForEvents, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $providerId); if ($provider->isEmpty()) { @@ -1185,6 +1263,9 @@ App::patch('/v1/messaging/providers/vonage/:providerId') $dbForProject->updateDocument('providers', $internalProvider->getId(), $internalProvider); } + $queueForEvents + ->setParam('providerId', $provider->getId()); + $response ->dynamic($provider, Response::MODEL_PROVIDER); }); @@ -1194,6 +1275,7 @@ App::patch('/v1/messaging/providers/fcm/:providerId') ->groups(['api', 'messaging']) ->label('audits.event', 'provider.update') ->label('audits.resource', 'provider/{response.$id}') + ->label('event', 'providers.[providerId].update') ->label('scope', 'providers.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -1207,9 +1289,10 @@ App::patch('/v1/messaging/providers/fcm/:providerId') ->param('enabled', null, new Boolean(), 'Set as enabled.', true) ->param('internal', null, new Boolean(), 'Set as internal. Internal providers are used in services other than Messaging service such as Authentication service', true) ->param('serverKey', '', new Text(0), 'FCM Server Key.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, ?bool $enabled, ?bool $internal, string $serverKey, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, ?bool $enabled, ?bool $internal, string $serverKey, Event $queueForEvents, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $providerId); if ($provider->isEmpty()) { @@ -1249,6 +1332,9 @@ App::patch('/v1/messaging/providers/fcm/:providerId') $dbForProject->updateDocument('providers', $internalProvider->getId(), $internalProvider); } + $queueForEvents + ->setParam('providerId', $provider->getId()); + $response ->dynamic($provider, Response::MODEL_PROVIDER); }); @@ -1259,6 +1345,7 @@ App::patch('/v1/messaging/providers/apns/:providerId') ->groups(['api', 'messaging']) ->label('audits.event', 'provider.update') ->label('audits.resource', 'provider/{response.$id}') + ->label('event', 'providers.[providerId].update') ->label('scope', 'providers.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -1276,9 +1363,10 @@ App::patch('/v1/messaging/providers/apns/:providerId') ->param('teamId', '', new Text(0), 'APNS team ID.', true) ->param('bundleId', '', new Text(0), 'APNS bundle ID.', true) ->param('endpoint', '', new Text(0), 'APNS endpoint.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, ?bool $enabled, ?bool $internal, string $authKey, string $authKeyId, string $teamId, string $bundleId, string $endpoint, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, ?bool $enabled, ?bool $internal, string $authKey, string $authKeyId, string $teamId, string $bundleId, string $endpoint, Event $queueForEvents, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $providerId); if ($provider->isEmpty()) { @@ -1338,6 +1426,9 @@ App::patch('/v1/messaging/providers/apns/:providerId') $dbForProject->updateDocument('providers', $internalProvider->getId(), $internalProvider); } + $queueForEvents + ->setParam('providerId', $provider->getId()); + $response ->dynamic($provider, Response::MODEL_PROVIDER); }); @@ -1347,6 +1438,7 @@ App::delete('/v1/messaging/providers/:providerId') ->groups(['api', 'messaging']) ->label('audits.event', 'provider.delete') ->label('audits.resource', 'provider/{request.id}') + ->label('event', 'providers.[providerId].delete') ->label('scope', 'providers.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -1356,9 +1448,10 @@ App::delete('/v1/messaging/providers/:providerId') ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_NONE) ->param('providerId', '', new UID(), 'Provider ID.') + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, Database $dbForProject, Response $response) { + ->action(function (string $providerId, Event $queueForEvents, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $providerId); if ($provider->isEmpty()) { @@ -1367,6 +1460,9 @@ App::delete('/v1/messaging/providers/:providerId') $dbForProject->deleteDocument('providers', $provider->getId()); + $queueForEvents + ->setParam('providerId', $provider->getId()); + $response ->setStatusCode(Response::STATUS_CODE_NOCONTENT) ->noContent(); @@ -1377,6 +1473,7 @@ App::post('/v1/messaging/topics') ->groups(['api', 'messaging']) ->label('audits.event', 'topic.create') ->label('audits.resource', 'topic/{response.$id}') + ->label('event', 'topics.[topicId].create') ->label('scope', 'topics.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -1388,9 +1485,10 @@ App::post('/v1/messaging/topics') ->param('topicId', '', new CustomId(), 'Topic ID. Choose a custom Topic ID or a new Topic ID.') ->param('name', '', new Text(128), 'Topic Name.') ->param('description', '', new Text(2048), 'Topic Description.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $topicId, string $name, string $description, Database $dbForProject, Response $response) { + ->action(function (string $topicId, string $name, string $description, Event $queueForEvents, Database $dbForProject, Response $response) { $topicId = $topicId == 'unique()' ? ID::unique() : $topicId; $topic = new Document([ @@ -1411,6 +1509,9 @@ App::post('/v1/messaging/topics') throw new Exception(Exception::TOPIC_ALREADY_EXISTS); } + $queueForEvents + ->setParam('topicId', $topic->getId()); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($topic, Response::MODEL_TOPIC); @@ -1491,6 +1592,7 @@ App::patch('/v1/messaging/topics/:topicId') ->groups(['api', 'messaging']) ->label('audits.event', 'topic.update') ->label('audits.resource', 'topic/{response.$id}') + ->label('event', 'topics.[topicId].update') ->label('scope', 'topics.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -1502,9 +1604,10 @@ App::patch('/v1/messaging/topics/:topicId') ->param('topicId', '', new UID(), 'Topic ID.') ->param('name', '', new Text(128), 'Topic Name.', true) ->param('description', '', new Text(2048), 'Topic Description.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $topicId, string $name, string $description, Database $dbForProject, Response $response) { + ->action(function (string $topicId, string $name, string $description, Event $queueForEvents, Database $dbForProject, Response $response) { $topic = $dbForProject->getDocument('topics', $topicId); if ($topic->isEmpty()) { @@ -1531,6 +1634,9 @@ App::patch('/v1/messaging/topics/:topicId') $topic = $dbForProject->updateDocument('topics', $topicId, $topic); + $queueForEvents + ->setParam('topicId', $topic->getId()); + $response ->dynamic($topic, Response::MODEL_TOPIC); }); @@ -1540,6 +1646,7 @@ App::delete('/v1/messaging/topics/:topicId') ->groups(['api', 'messaging']) ->label('audits.event', 'topic.delete') ->label('audits.resource', 'topic/{request.topicId}') + ->label('event', 'topics.[topicId].delete') ->label('scope', 'topics.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -1549,10 +1656,11 @@ App::delete('/v1/messaging/topics/:topicId') ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_NONE) ->param('topicId', '', new UID(), 'Topic ID.') + ->inject('queueForEvents') ->inject('dbForProject') ->inject('queueForDeletes') ->inject('response') - ->action(function (string $topicId, Database $dbForProject, Delete $queueForDeletes, Response $response) { + ->action(function (string $topicId, Event $queueForEvents, Database $dbForProject, Delete $queueForDeletes, Response $response) { $topic = $dbForProject->getDocument('topics', $topicId); if ($topic->isEmpty()) { @@ -1565,6 +1673,9 @@ App::delete('/v1/messaging/topics/:topicId') ->setType(DELETE_TYPE_TOPIC) ->setDocument($topic); + $queueForEvents + ->setParam('topicId', $topic->getId()); + $response ->setStatusCode(Response::STATUS_CODE_NOCONTENT) ->noContent(); @@ -1575,6 +1686,7 @@ App::post('/v1/messaging/topics/:topicId/subscribers') ->groups(['api', 'messaging']) ->label('audits.event', 'subscriber.create') ->label('audits.resource', 'subscriber/{response.$id}') + ->label('event', 'topics.[topicId].subscribers.[subscriberId].create') ->label('scope', 'subscribers.write') ->label('sdk.auth', [APP_AUTH_TYPE_JWT, APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -1586,9 +1698,10 @@ App::post('/v1/messaging/topics/:topicId/subscribers') ->param('subscriberId', '', new CustomId(), 'Subscriber ID. Choose a custom Topic ID or a new Topic ID.') ->param('topicId', '', new UID(), 'Topic ID.') ->param('targetId', '', new UID(), 'Target ID.') + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $subscriberId, string $topicId, string $targetId, Database $dbForProject, Response $response) { + ->action(function (string $subscriberId, string $topicId, string $targetId, Event $queueForEvents, Database $dbForProject, Response $response) { $subscriberId = $subscriberId == 'unique()' ? ID::unique() : $subscriberId; $topic = Authorization::skip(fn () => $dbForProject->getDocument('topics', $topicId)); @@ -1622,6 +1735,10 @@ App::post('/v1/messaging/topics/:topicId/subscribers') throw new Exception(Exception::SUBSCRIBER_ALREADY_EXISTS); } + $queueForEvents + ->setParam('topicId', $topic->getId()) + ->setParam('subscriberId', $subscriber->getId()); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($subscriber, Response::MODEL_SUBSCRIBER); @@ -1712,6 +1829,7 @@ App::delete('/v1/messaging/topics/:topicId/subscriber/:subscriberId') ->groups(['api', 'messaging']) ->label('audits.event', 'subscriber.delete') ->label('audits.resource', 'subscriber/{request.subscriberId}') + ->label('event', 'topics.[topicId].subscribers.[subscriberId].delete') ->label('scope', 'subscribers.write') ->label('sdk.auth', [APP_AUTH_TYPE_JWT, APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -1722,9 +1840,10 @@ App::delete('/v1/messaging/topics/:topicId/subscriber/:subscriberId') ->label('sdk.response.model', Response::MODEL_NONE) ->param('topicId', '', new UID(), 'Topic ID.') ->param('subscriberId', '', new UID(), 'Subscriber ID.') + ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $topicId, string $subscriberId, Database $dbForProject, Response $response) { + ->action(function (string $topicId, string $subscriberId, Event $queueForEvents, Database $dbForProject, Response $response) { $topic = Authorization::skip(fn () => $dbForProject->getDocument('topics', $topicId)); if ($topic->isEmpty()) { @@ -1737,9 +1856,13 @@ App::delete('/v1/messaging/topics/:topicId/subscriber/:subscriberId') throw new Exception(Exception::SUBSCRIBER_NOT_FOUND); } - $subscriber = $dbForProject->deleteDocument('subscribers', $subscriberId); + $dbForProject->deleteDocument('subscribers', $subscriberId); Authorization::skip(fn () => $dbForProject->decreaseDocumentAttribute('topics', $topicId, 'total', 1)); + $queueForEvents + ->setParam('topicId', $topic->getId()) + ->setParam('subscriberId', $subscriber->getId()); + $response ->setStatusCode(Response::STATUS_CODE_NOCONTENT) ->noContent(); @@ -1750,6 +1873,7 @@ App::post('/v1/messaging/messages/email') ->groups(['api', 'messaging']) ->label('audits.event', 'message.create') ->label('audits.resource', 'message/{response.$id}') + ->label('event', 'messages.[messageId].create') ->label('scope', 'messages.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -1768,11 +1892,12 @@ App::post('/v1/messaging/messages/email') ->param('status', 'processing', new WhiteList(['draft', 'processing']), 'Message Status. Value must be either draft or processing.', true) ->param('html', false, new Boolean(), 'Is content of type HTML', true) ->param('deliveryTime', null, new DatetimeValidator(requireDateInFuture: true), 'Delivery time for message in ISO 8601 format. DateTime value must be in future.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('project') ->inject('queueForMessaging') ->inject('response') - ->action(function (string $messageId, string $subject, string $content, array $topics, array $users, array $targets, string $description, string $status, bool $html, ?string $deliveryTime, Database $dbForProject, Document $project, Messaging $queueForMessaging, Response $response) { + ->action(function (string $messageId, string $subject, string $content, array $topics, array $users, array $targets, string $description, string $status, bool $html, ?string $deliveryTime, Event $queueForEvents, Database $dbForProject, Document $project, Messaging $queueForMessaging, Response $response) { $messageId = $messageId == 'unique()' ? ID::unique() : $messageId; if (\count($topics) === 0 && \count($users) === 0 && \count($targets) === 0) { @@ -1801,6 +1926,9 @@ App::post('/v1/messaging/messages/email') ->trigger(); } + $queueForEvents + ->setParam('messageId', $message->getId()); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($message, Response::MODEL_MESSAGE); @@ -1811,6 +1939,7 @@ App::post('/v1/messaging/messages/sms') ->groups(['api', 'messaging']) ->label('audits.event', 'message.create') ->label('audits.resource', 'message/{response.$id}') + ->label('event', 'messages.[messageId].create') ->label('scope', 'messages.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -1827,11 +1956,12 @@ App::post('/v1/messaging/messages/sms') ->param('description', '', new Text(256), 'Description for Message.', true) ->param('status', 'processing', new WhiteList(['draft', 'processing']), 'Message Status. Value must be either draft or processing.', true) ->param('deliveryTime', null, new DatetimeValidator(requireDateInFuture: true), 'Delivery time for message in ISO 8601 format. DateTime value must be in future.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('project') ->inject('queueForMessaging') ->inject('response') - ->action(function (string $messageId, string $content, array $topics, array $users, array $targets, string $description, string $status, ?string $deliveryTime, Database $dbForProject, Document $project, Messaging $queueForMessaging, Response $response) { + ->action(function (string $messageId, string $content, array $topics, array $users, array $targets, string $description, string $status, ?string $deliveryTime, Event $queueForEvents, Database $dbForProject, Document $project, Messaging $queueForMessaging, Response $response) { $messageId = $messageId == 'unique()' ? ID::unique() : $messageId; if (\count($topics) === 0 && \count($users) === 0 && \count($targets) === 0) { @@ -1858,6 +1988,9 @@ App::post('/v1/messaging/messages/sms') ->trigger(); } + $queueForEvents + ->setParam('messageId', $message->getId()); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($message, Response::MODEL_MESSAGE); @@ -1868,6 +2001,7 @@ App::post('/v1/messaging/messages/push') ->groups(['api', 'messaging']) ->label('audits.event', 'message.create') ->label('audits.resource', 'message/{response.$id}') + ->label('event', 'messages.[messageId].create') ->label('scope', 'messages.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -1892,11 +2026,12 @@ App::post('/v1/messaging/messages/push') ->param('badge', '', new Text(256), 'Badge for push notification. Available only for IOS Platform.', true) ->param('status', 'processing', new WhiteList(['draft', 'processing']), 'Message Status. Value must be either draft or processing.', true) ->param('deliveryTime', null, new DatetimeValidator(requireDateInFuture: true), 'Delivery time for message in ISO 8601 format. DateTime value must be in future.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('project') ->inject('queueForMessaging') ->inject('response') - ->action(function (string $messageId, string $title, string $body, array $topics, array $users, array $targets, string $description, ?array $data, string $action, string $icon, string $sound, string $color, string $tag, string $badge, string $status, ?string $deliveryTime, Database $dbForProject, Document $project, Messaging $queueForMessaging, Response $response) { + ->action(function (string $messageId, string $title, string $body, array $topics, array $users, array $targets, string $description, ?array $data, string $action, string $icon, string $sound, string $color, string $tag, string $badge, string $status, ?string $deliveryTime, Event $queueForEvents, Database $dbForProject, Document $project, Messaging $queueForMessaging, Response $response) { $messageId = $messageId == 'unique()' ? ID::unique() : $messageId; if (\count($topics) === 0 && \count($users) === 0 && \count($targets) === 0) { @@ -1955,6 +2090,9 @@ App::post('/v1/messaging/messages/push') ->trigger(); } + $queueForEvents + ->setParam('messageId', $message->getId()); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($message, Response::MODEL_MESSAGE); @@ -2032,6 +2170,7 @@ App::patch('/v1/messaging/messages/email/:messageId') ->groups(['api', 'messaging']) ->label('audits.event', 'message.update') ->label('audits.resource', 'message/{response.$id}') + ->label('event', 'messages.[messageId].update') ->label('scope', 'messages.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -2050,11 +2189,12 @@ App::patch('/v1/messaging/messages/email/:messageId') ->param('status', '', new WhiteList(['draft', 'processing']), 'Message Status. Value must be either draft or processing.', true) ->param('html', false, new Boolean(), 'Is content of type HTML', true) ->param('deliveryTime', null, new DatetimeValidator(requireDateInFuture: true), 'Delivery time for message in ISO 8601 format. DateTime value must be in future.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('project') ->inject('queueForMessaging') ->inject('response') - ->action(function (string $messageId, ?array $topics, ?array $users, ?array $targets, string $subject, string $description, string $content, string $status, bool $html, ?string $deliveryTime, Database $dbForProject, Document $project, Messaging $queueForMessaging, Response $response) { + ->action(function (string $messageId, ?array $topics, ?array $users, ?array $targets, string $subject, string $description, string $content, string $status, bool $html, ?string $deliveryTime, Event $queueForEvents, Database $dbForProject, Document $project, Messaging $queueForMessaging, Response $response) { $message = $dbForProject->getDocument('messages', $messageId); if ($message->isEmpty()) { @@ -2120,6 +2260,9 @@ App::patch('/v1/messaging/messages/email/:messageId') ->trigger(); } + $queueForEvents + ->setParam('messageId', $message->getId()); + $response ->dynamic($message, Response::MODEL_MESSAGE); }); @@ -2129,6 +2272,7 @@ App::patch('/v1/messaging/messages/sms/:messageId') ->groups(['api', 'messaging']) ->label('audits.event', 'message.update') ->label('audits.resource', 'message/{response.$id}') + ->label('event', 'messages.[messageId].update') ->label('scope', 'messages.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -2145,11 +2289,12 @@ App::patch('/v1/messaging/messages/sms/:messageId') ->param('content', '', new Text(64230), 'Email Content.', true) ->param('status', '', new WhiteList(['draft', 'processing']), 'Message Status. Value must be either draft or processing.', true) ->param('deliveryTime', null, new DatetimeValidator(requireDateInFuture: true), 'Delivery time for message in ISO 8601 format. DateTime value must be in future.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('project') ->inject('queueForMessaging') ->inject('response') - ->action(function (string $messageId, ?array $topics, ?array $users, ?array $targets, string $description, string $content, string $status, ?string $deliveryTime, Database $dbForProject, Document $project, Messaging $queueForMessaging, Response $response) { + ->action(function (string $messageId, ?array $topics, ?array $users, ?array $targets, string $description, string $content, string $status, ?string $deliveryTime, Event $queueForEvents, Database $dbForProject, Document $project, Messaging $queueForMessaging, Response $response) { $message = $dbForProject->getDocument('messages', $messageId); if ($message->isEmpty()) { @@ -2207,6 +2352,9 @@ App::patch('/v1/messaging/messages/sms/:messageId') ->trigger(); } + $queueForEvents + ->setParam('messageId', $message->getId()); + $response ->dynamic($message, Response::MODEL_MESSAGE); }); @@ -2216,6 +2364,7 @@ App::patch('/v1/messaging/messages/push/:messageId') ->groups(['api', 'messaging']) ->label('audits.event', 'message.update') ->label('audits.resource', 'message/{response.$id}') + ->label('event', 'messages.[messageId].update') ->label('scope', 'messages.write') ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'messaging') @@ -2239,11 +2388,12 @@ App::patch('/v1/messaging/messages/push/:messageId') ->param('tag', '', new Text(256), 'Tag for push notification. Available only for Android Platform.', true) ->param('badge', '', new Text(256), 'Badge for push notification. Available only for IOS Platform.', true) ->param('status', 'processing', new WhiteList(['draft', 'processing']), 'Message Status. Value must be either draft or processing.', true) ->param('deliveryTime', null, new DatetimeValidator(requireDateInFuture: true), 'Delivery time for message in ISO 8601 format. DateTime value must be in future.', true) + ->inject('queueForEvents') ->inject('dbForProject') ->inject('project') ->inject('queueForMessaging') ->inject('response') - ->action(function (string $messageId, ?array $topics, ?array $users, ?array $targets, string $description, string $title, string $body, ?array $data, string $action, string $icon, string $sound, string $color, string $tag, string $badge, string $status, ?string $deliveryTime, Database $dbForProject, Document $project, Messaging $queueForMessaging, Response $response) { + ->action(function (string $messageId, ?array $topics, ?array $users, ?array $targets, string $description, string $title, string $body, ?array $data, string $action, string $icon, string $sound, string $color, string $tag, string $badge, string $status, ?string $deliveryTime, Event $queueForEvents, Database $dbForProject, Document $project, Messaging $queueForMessaging, Response $response) { $message = $dbForProject->getDocument('messages', $messageId); if ($message->isEmpty()) { @@ -2333,6 +2483,9 @@ App::patch('/v1/messaging/messages/push/:messageId') ->trigger(); } + $queueForEvents + ->setParam('messageId', $message->getId()); + $response ->dynamic($message, Response::MODEL_MESSAGE); }); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 7c9253684e..023cef3641 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -384,6 +384,7 @@ App::post('/v1/users/:userId/targets') ->groups(['api', 'users']) ->label('audits.event', 'target.create') ->label('audits.resource', 'target/response.$id') + ->label('event', 'users.[userId].targets.[targetId].create') ->label('scope', 'targets.write') ->label('sdk.auth', [APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_ADMIN]) ->label('sdk.namespace', 'users') @@ -396,9 +397,10 @@ App::post('/v1/users/:userId/targets') ->param('targetId', '', new UID(), 'Target ID.') ->param('providerId', '', new UID(), 'Provider ID.') ->param('identifier', '', new Text(Database::LENGTH_KEY), 'The target identifier (token, email, phone etc.)') + ->inject('queueForEvents') ->inject('response') ->inject('dbForProject') - ->action(function (string $userId, string $targetId, string $providerId, string $identifier, Response $response, Database $dbForProject) { + ->action(function (string $userId, string $targetId, string $providerId, string $identifier, Event $queueForEvents, Response $response, Database $dbForProject) { $provider = $dbForProject->getDocument('providers', $providerId); if ($provider->isEmpty()) { @@ -431,6 +433,10 @@ App::post('/v1/users/:userId/targets') } $dbForProject->deleteCachedDocument('users', $user->getId()); + $queueForEvents + ->setParam('userId', $user->getId()) + ->setParam('targetId', $target->getId()); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($target, Response::MODEL_TARGET); @@ -1203,6 +1209,7 @@ App::patch('/v1/users/:userId/targets/:targetId/identifier') ->groups(['api', 'users']) ->label('audits.event', 'target.update') ->label('audits.resource', 'target/{response.$id}') + ->label('event', 'users.[userId].targets.[targetId].update') ->label('scope', 'targets.write') ->label('sdk.auth', [APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_ADMIN]) ->label('sdk.namespace', 'users') @@ -1214,9 +1221,10 @@ App::patch('/v1/users/:userId/targets/:targetId/identifier') ->param('userId', '', new UID(), 'User ID.') ->param('targetId', '', new UID(), 'Target ID.') ->param('identifier', '', new Text(Database::LENGTH_KEY), 'The target identifier (token, email, phone etc.)') + ->inject('queueForEvents') ->inject('response') ->inject('dbForProject') - ->action(function (string $userId, string $targetId, string $identifier, Response $response, Database $dbForProject) { + ->action(function (string $userId, string $targetId, string $identifier, Event $queueForEvents, Response $response, Database $dbForProject) { $user = $dbForProject->getDocument('users', $userId); @@ -1239,6 +1247,10 @@ App::patch('/v1/users/:userId/targets/:targetId/identifier') $target = $dbForProject->updateDocument('targets', $target->getId(), $target); $dbForProject->deleteCachedDocument('users', $user->getId()); + $queueForEvents + ->setParam('userId', $user->getId()) + ->setParam('targetId', $target->getId()); + $response ->dynamic($target, Response::MODEL_TARGET); }); @@ -1378,6 +1390,7 @@ App::delete('/v1/users/:userId/targets/:targetId') ->groups(['api', 'users']) ->label('audits.event', 'target.delete') ->label('audits.resource', 'target/{request.$targetId}') + ->label('event', 'users.[userId].targets.[targetId].delete') ->label('scope', 'targets.write') ->label('sdk.auth', [APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_ADMIN]) ->label('sdk.namespace', 'users') @@ -1388,9 +1401,10 @@ App::delete('/v1/users/:userId/targets/:targetId') ->label('sdk.response.model', Response::MODEL_NONE) ->param('userId', '', new UID(), 'User ID.') ->param('targetId', '', new UID(), 'Target ID.') + ->inject('queueForEvents') ->inject('response') ->inject('dbForProject') - ->action(function (string $userId, string $targetId, Response $response, Database $dbForProject) { + ->action(function (string $userId, string $targetId, Event $queueForEvents, Response $response, Database $dbForProject) { $user = $dbForProject->getDocument('users', $userId); @@ -1408,9 +1422,13 @@ App::delete('/v1/users/:userId/targets/:targetId') throw new Exception(Exception::USER_TARGET_NOT_FOUND); } - $target = $dbForProject->deleteDocument('targets', $target->getId()); + $dbForProject->deleteDocument('targets', $target->getId()); $dbForProject->deleteCachedDocument('users', $user->getId()); + $queueForEvents + ->setParam('userId', $user->getId()) + ->setParam('targetId', $target->getId()); + $response->noContent(); });