diff --git a/CHANGES.md b/CHANGES.md index fc2eed61d7..3c0dc29723 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ - Only logged in users can execute functions (for guests, use anonymous login) - Only the user who has triggered the execution get access to the relevant execution logs +- Function execution env `APPWRITE_FUNCTION_EVENT_PAYLOAD` renamed to `APPWRITE_FUNCTION_EVENT_DATA` # Version 0.7.2 diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index b2f382c895..8ff3e6970e 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1148,7 +1148,7 @@ App::delete('/v1/account') ; $events - ->setParam('payload', $response->output($user, Response::MODEL_USER)) + ->setParam('eventData', $response->output($user, Response::MODEL_USER)) ; if (!Config::getParam('domainVerification')) { @@ -1230,7 +1230,7 @@ App::delete('/v1/account/sessions/:sessionId') } $events - ->setParam('payload', $response->output($session, Response::MODEL_SESSION)) + ->setParam('eventData', $response->output($session, Response::MODEL_SESSION)) ; return $response->noContent(); @@ -1300,7 +1300,7 @@ App::delete('/v1/account/sessions') } $events - ->setParam('payload', $response->output(new Document([ + ->setParam('eventData', $response->output(new Document([ 'sum' => count($sessions), 'sessions' => $sessions ]), Response::MODEL_SESSION_LIST)) @@ -1425,7 +1425,7 @@ App::post('/v1/account/recovery') ; $events - ->setParam('payload', + ->setParam('eventData', $response->output($recovery->setAttribute('secret', $secret), Response::MODEL_TOKEN )) @@ -1628,7 +1628,7 @@ App::post('/v1/account/verification') ; $events - ->setParam('payload', + ->setParam('eventData', $response->output($verification->setAttribute('secret', $verificationSecret), Response::MODEL_TOKEN )) diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index 2c32ae981e..e86812e7e3 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -271,7 +271,7 @@ App::delete('/v1/database/collections/:collectionId') ; $events - ->setParam('payload', $response->output($collection, Response::MODEL_COLLECTION)) + ->setParam('eventData', $response->output($collection, Response::MODEL_COLLECTION)) ; $audits @@ -614,7 +614,7 @@ App::delete('/v1/database/collections/:collectionId/documents/:documentId') } $events - ->setParam('payload', $response->output($document, Response::MODEL_ANY)) + ->setParam('eventData', $response->output($document, Response::MODEL_ANY)) ; $audits diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index f0ce2e4050..50570cb504 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -581,7 +581,7 @@ App::delete('/v1/storage/files/:fileId') ; $events - ->setParam('payload', $response->output($file, Response::MODEL_FILE)) + ->setParam('eventData', $response->output($file, Response::MODEL_FILE)) ; $response->noContent(); diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index f75f072e76..eb6d691dba 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -243,7 +243,7 @@ App::delete('/v1/teams/:teamId') } $events - ->setParam('payload', $response->output($team, Response::MODEL_TEAM)) + ->setParam('eventData', $response->output($team, Response::MODEL_TEAM)) ; $response->noContent(); @@ -713,7 +713,7 @@ App::delete('/v1/teams/:teamId/memberships/:inviteId') ; $events - ->setParam('payload', $response->output($membership, Response::MODEL_MEMBERSHIP)) + ->setParam('eventData', $response->output($membership, Response::MODEL_MEMBERSHIP)) ; $response->noContent(); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 63a218b264..3f6a82d9c0 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -442,7 +442,7 @@ App::delete('/v1/users/:userId/sessions/:sessionId') } $events - ->setParam('payload', $response->output($user, Response::MODEL_USER)) + ->setParam('eventData', $response->output($user, Response::MODEL_USER)) ; } } @@ -488,7 +488,7 @@ App::delete('/v1/users/:userId/sessions') } $events - ->setParam('payload', $response->output($user, Response::MODEL_USER)) + ->setParam('eventData', $response->output($user, Response::MODEL_USER)) ; // TODO : Response filter implementation @@ -548,7 +548,7 @@ App::delete('/v1/users/:userId') ; $events - ->setParam('payload', $response->output($user, Response::MODEL_USER)) + ->setParam('eventData', $response->output($user, Response::MODEL_USER)) ; // TODO : Response filter implementation diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 8dc0c097c7..ffb5198c0d 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -78,7 +78,7 @@ App::init(function ($utopia, $request, $response, $project, $user, $register, $e ->setParam('projectId', $project->getId()) ->setParam('userId', $user->getId()) ->setParam('event', $route->getLabel('event', '')) - ->setParam('payload', []) + ->setParam('eventData', []) ->setParam('functionId', null) ->setParam('executionId', null) ->setParam('trigger', 'event') @@ -123,8 +123,8 @@ App::shutdown(function ($utopia, $request, $response, $project, $events, $audits /** @var bool $mode */ if (!empty($events->getParam('event'))) { - if(empty($events->getParam('payload'))) { - $events->setParam('payload', $response->getPayload()); + if(empty($events->getParam('eventData'))) { + $events->setParam('eventData', $response->getPayload()); } $webhooks = clone $events; diff --git a/app/workers/functions.php b/app/workers/functions.php index b359639a4b..4a8244f37c 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -147,7 +147,7 @@ class FunctionsV1 $trigger = $this->args['trigger'] ?? ''; $event = $this->args['event'] ?? ''; $scheduleOriginal = $this->args['scheduleOriginal'] ?? ''; - $payload = (!empty($this->args['payload'])) ? json_encode($this->args['payload']) : ''; + $eventData = (!empty($this->args['eventData'])) ? json_encode($this->args['eventData']) : ''; $data = $this->args['data'] ?? ''; $userId = $this->args['userId'] ?? ''; $jwt = $this->args['jwt'] ?? ''; @@ -198,7 +198,7 @@ class FunctionsV1 Console::success('Triggered function: '.$event); - $this->execute('event', $projectId, '', $database, $function, $event, $payload, $data, $userId, $jwt); + $this->execute('event', $projectId, '', $database, $function, $event, $eventData, $data, $userId, $jwt); } } break; @@ -254,7 +254,7 @@ class FunctionsV1 'scheduleOriginal' => $function->getAttribute('schedule', ''), ]); // Async task rescheduale - $this->execute($trigger, $projectId, $executionId, $database, $function, /*$event*/'', /*$payload*/'', $data, $userId, $jwt); + $this->execute($trigger, $projectId, $executionId, $database, $function, /*$event*/'', /*$eventData*/'', $data, $userId, $jwt); break; case 'http': @@ -266,7 +266,7 @@ class FunctionsV1 throw new Exception('Function not found ('.$functionId.')'); } - $this->execute($trigger, $projectId, $executionId, $database, $function, /*$event*/'', /*$payload*/'', $data, $userId, $jwt); + $this->execute($trigger, $projectId, $executionId, $database, $function, /*$event*/'', /*$eventData*/'', $data, $userId, $jwt); break; default: @@ -284,12 +284,12 @@ class FunctionsV1 * @param Database $database * @param Database $function * @param string $event - * @param string $payload + * @param string $eventData * @param string $data * * @return void */ - public function execute(string $trigger, string $projectId, string $executionId, Database $database, Document $function, string $event = '', string $payload = '', string $data = '', string $userId = '', string $jwt = ''): void + public function execute(string $trigger, string $projectId, string $executionId, Database $database, Document $function, string $event = '', string $eventData = '', string $data = '', string $userId = '', string $jwt = ''): void { global $list; @@ -343,7 +343,7 @@ class FunctionsV1 'APPWRITE_FUNCTION_ENV_NAME' => $environment['name'], 'APPWRITE_FUNCTION_ENV_VERSION' => $environment['version'], 'APPWRITE_FUNCTION_EVENT' => $event, - 'APPWRITE_FUNCTION_EVENT_PAYLOAD' => $payload, + 'APPWRITE_FUNCTION_EVENT_DATA' => $eventData, 'APPWRITE_FUNCTION_DATA' => $data, 'APPWRITE_FUNCTION_USER_ID' => $userId, 'APPWRITE_FUNCTION_JWT' => $jwt, @@ -482,7 +482,7 @@ class FunctionsV1 ->setParam('projectId', $projectId) ->setParam('userId', $userId) ->setParam('event', 'functions.executions.update') - ->setParam('payload', [ + ->setParam('eventData', [ '$id' => $execution['$id'], 'functionId' => $execution['functionId'], 'dateCreated' => $execution['dateCreated'], diff --git a/app/workers/webhooks.php b/app/workers/webhooks.php index 21e88e6b43..75cc54bf57 100644 --- a/app/workers/webhooks.php +++ b/app/workers/webhooks.php @@ -37,7 +37,7 @@ class WebhooksV1 $projectId = $this->args['projectId'] ?? ''; $userId = $this->args['userId'] ?? ''; $event = $this->args['event'] ?? ''; - $payload = \json_encode($this->args['payload']); + $eventData = \json_encode($this->args['eventData']); // Webhook @@ -67,7 +67,7 @@ class WebhooksV1 $ch = \curl_init($url); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); - \curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); + \curl_setopt($ch, CURLOPT_POSTFIELDS, $eventData); \curl_setopt($ch, CURLOPT_HEADER, 0); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($ch, CURLOPT_USERAGENT, \sprintf(APP_USERAGENT, @@ -79,7 +79,7 @@ class WebhooksV1 CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', - 'Content-Length: '.\strlen($payload), + 'Content-Length: '.\strlen($eventData), 'X-'.APP_NAME.'-Webhook-Id: '.$id, 'X-'.APP_NAME.'-Webhook-Event: '.$event, 'X-'.APP_NAME.'-Webhook-Name: '.$name, diff --git a/tests/resources/functions/dart.tar.gz b/tests/resources/functions/dart.tar.gz index d444518a92..3f1bc41544 100644 Binary files a/tests/resources/functions/dart.tar.gz and b/tests/resources/functions/dart.tar.gz differ diff --git a/tests/resources/functions/dart/main.dart b/tests/resources/functions/dart/main.dart index 8dbe1aa708..33c184d7bd 100644 --- a/tests/resources/functions/dart/main.dart +++ b/tests/resources/functions/dart/main.dart @@ -22,5 +22,5 @@ void main() { // Init SDK print(Platform.environment["APPWRITE_FUNCTION_ENV_VERSION"]); // print(result['$id']); print(Platform.environment["APPWRITE_FUNCTION_EVENT"]); - print(Platform.environment["APPWRITE_FUNCTION_EVENT_PAYLOAD"]); + print(Platform.environment["APPWRITE_FUNCTION_EVENT_DATA"]); } \ No newline at end of file diff --git a/tests/resources/functions/deno.tar.gz b/tests/resources/functions/deno.tar.gz index 47f04a14ed..5e57e3cfed 100644 Binary files a/tests/resources/functions/deno.tar.gz and b/tests/resources/functions/deno.tar.gz differ diff --git a/tests/resources/functions/deno/index.ts b/tests/resources/functions/deno/index.ts index 228842756b..ce043dc33a 100644 --- a/tests/resources/functions/deno/index.ts +++ b/tests/resources/functions/deno/index.ts @@ -20,4 +20,4 @@ console.log(Deno.env.get("APPWRITE_FUNCTION_ENV_NAME") || ''); console.log(Deno.env.get("APPWRITE_FUNCTION_ENV_VERSION") || ''); // console.log(result['$id']")); console.log(Deno.env.get("APPWRITE_FUNCTION_EVENT") || ''); -console.log(Deno.env.get("APPWRITE_FUNCTION_EVENT_PAYLOAD") || ''); \ No newline at end of file +console.log(Deno.env.get("APPWRITE_FUNCTION_EVENT_DATA") || ''); \ No newline at end of file diff --git a/tests/resources/functions/dotnet-3.1.tar.gz b/tests/resources/functions/dotnet-3.1.tar.gz index 16627e89ad..8ce777cec1 100644 Binary files a/tests/resources/functions/dotnet-3.1.tar.gz and b/tests/resources/functions/dotnet-3.1.tar.gz differ diff --git a/tests/resources/functions/dotnet-3.1/Program.cs b/tests/resources/functions/dotnet-3.1/Program.cs index ee5894aa7f..9c20ee9f97 100644 --- a/tests/resources/functions/dotnet-3.1/Program.cs +++ b/tests/resources/functions/dotnet-3.1/Program.cs @@ -22,7 +22,7 @@ namespace dotnet Console.WriteLine(Environment.GetEnvironmentVariable("APPWRITE_FUNCTION_ENV_NAME")); Console.WriteLine(Environment.GetEnvironmentVariable("APPWRITE_FUNCTION_ENV_VERSION")); Console.WriteLine(Environment.GetEnvironmentVariable("APPWRITE_FUNCTION_EVENT")); - Console.WriteLine(Environment.GetEnvironmentVariable("APPWRITE_FUNCTION_EVENT_PAYLOAD")); + Console.WriteLine(Environment.GetEnvironmentVariable("APPWRITE_FUNCTION_EVENT_DATA")); } } } diff --git a/tests/resources/functions/dotnet-5.0.tar.gz b/tests/resources/functions/dotnet-5.0.tar.gz index 7117cf924f..1e82fe8619 100644 Binary files a/tests/resources/functions/dotnet-5.0.tar.gz and b/tests/resources/functions/dotnet-5.0.tar.gz differ diff --git a/tests/resources/functions/dotnet-5.0/Program.cs b/tests/resources/functions/dotnet-5.0/Program.cs index ee5894aa7f..9c20ee9f97 100644 --- a/tests/resources/functions/dotnet-5.0/Program.cs +++ b/tests/resources/functions/dotnet-5.0/Program.cs @@ -22,7 +22,7 @@ namespace dotnet Console.WriteLine(Environment.GetEnvironmentVariable("APPWRITE_FUNCTION_ENV_NAME")); Console.WriteLine(Environment.GetEnvironmentVariable("APPWRITE_FUNCTION_ENV_VERSION")); Console.WriteLine(Environment.GetEnvironmentVariable("APPWRITE_FUNCTION_EVENT")); - Console.WriteLine(Environment.GetEnvironmentVariable("APPWRITE_FUNCTION_EVENT_PAYLOAD")); + Console.WriteLine(Environment.GetEnvironmentVariable("APPWRITE_FUNCTION_EVENT_DATA")); } } } diff --git a/tests/resources/functions/node.tar.gz b/tests/resources/functions/node.tar.gz index b132b0a130..9f0fa40f7d 100644 Binary files a/tests/resources/functions/node.tar.gz and b/tests/resources/functions/node.tar.gz differ diff --git a/tests/resources/functions/node/index.js b/tests/resources/functions/node/index.js index b2dbbba1a4..f994323807 100644 --- a/tests/resources/functions/node/index.js +++ b/tests/resources/functions/node/index.js @@ -20,4 +20,4 @@ console.log(process.env.APPWRITE_FUNCTION_ENV_NAME); console.log(process.env.APPWRITE_FUNCTION_ENV_VERSION); // console.log(result['$id']); console.log(process.env.APPWRITE_FUNCTION_EVENT); -console.log(process.env.APPWRITE_FUNCTION_EVENT_PAYLOAD); \ No newline at end of file +console.log(process.env.APPWRITE_FUNCTION_EVENT_DATA); \ No newline at end of file diff --git a/tests/resources/functions/php-fn.tar.gz b/tests/resources/functions/php-fn.tar.gz index b6906b615e..762072967e 100644 Binary files a/tests/resources/functions/php-fn.tar.gz and b/tests/resources/functions/php-fn.tar.gz differ diff --git a/tests/resources/functions/php-fn/index.php b/tests/resources/functions/php-fn/index.php index 387ba8eb9e..a1e20cc776 100644 --- a/tests/resources/functions/php-fn/index.php +++ b/tests/resources/functions/php-fn/index.php @@ -25,7 +25,7 @@ echo $_ENV['APPWRITE_FUNCTION_ENV_NAME']."\n"; echo $_ENV['APPWRITE_FUNCTION_ENV_VERSION']."\n"; // echo $result['$id']; echo $_ENV['APPWRITE_FUNCTION_EVENT']."\n"; -echo $_ENV['APPWRITE_FUNCTION_EVENT_PAYLOAD']."\n"; +echo $_ENV['APPWRITE_FUNCTION_EVENT_DATA']."\n"; echo 'data:'.$_ENV['APPWRITE_FUNCTION_DATA']."\n"; echo 'userId:'.$_ENV['APPWRITE_FUNCTION_USER_ID']."\n"; echo 'jwt:'.$_ENV['APPWRITE_FUNCTION_JWT']."\n"; diff --git a/tests/resources/functions/php.tar.gz b/tests/resources/functions/php.tar.gz index 751cd74f2a..3e4fb632b5 100644 Binary files a/tests/resources/functions/php.tar.gz and b/tests/resources/functions/php.tar.gz differ diff --git a/tests/resources/functions/php/index.php b/tests/resources/functions/php/index.php index 58f8004c12..66267a4fd1 100644 --- a/tests/resources/functions/php/index.php +++ b/tests/resources/functions/php/index.php @@ -25,4 +25,4 @@ echo $_ENV['APPWRITE_FUNCTION_ENV_NAME']."\n"; echo $_ENV['APPWRITE_FUNCTION_ENV_VERSION']."\n"; // echo $result['$id']; echo $_ENV['APPWRITE_FUNCTION_EVENT']."\n"; -echo $_ENV['APPWRITE_FUNCTION_EVENT_PAYLOAD']."\n"; \ No newline at end of file +echo $_ENV['APPWRITE_FUNCTION_EVENT_DATA']."\n"; \ No newline at end of file diff --git a/tests/resources/functions/python.tar.gz b/tests/resources/functions/python.tar.gz index dbb07c3f53..bbd1642001 100644 Binary files a/tests/resources/functions/python.tar.gz and b/tests/resources/functions/python.tar.gz differ diff --git a/tests/resources/functions/python/main.py b/tests/resources/functions/python/main.py index 5da8f43f77..c6b2f6e5dd 100644 --- a/tests/resources/functions/python/main.py +++ b/tests/resources/functions/python/main.py @@ -20,4 +20,4 @@ print(os.environ["APPWRITE_FUNCTION_ENV_NAME"]) print(os.environ["APPWRITE_FUNCTION_ENV_VERSION"]) # print(result["$id"]) print(os.environ["APPWRITE_FUNCTION_EVENT"]) -print(os.environ["APPWRITE_FUNCTION_EVENT_PAYLOAD"]) \ No newline at end of file +print(os.environ["APPWRITE_FUNCTION_EVENT_DATA"]) \ No newline at end of file diff --git a/tests/resources/functions/ruby.tar.gz b/tests/resources/functions/ruby.tar.gz index 62efb011c9..3e913f73fd 100644 Binary files a/tests/resources/functions/ruby.tar.gz and b/tests/resources/functions/ruby.tar.gz differ diff --git a/tests/resources/functions/ruby/app.rb b/tests/resources/functions/ruby/app.rb index f9c4b08e2f..6972d75d94 100644 --- a/tests/resources/functions/ruby/app.rb +++ b/tests/resources/functions/ruby/app.rb @@ -20,4 +20,4 @@ puts ENV["APPWRITE_FUNCTION_ENV_NAME"] puts ENV["APPWRITE_FUNCTION_ENV_VERSION"] # puts result["$id"] puts ENV["APPWRITE_FUNCTION_EVENT"] -puts ENV["APPWRITE_FUNCTION_EVENT_PAYLOAD"] \ No newline at end of file +puts ENV["APPWRITE_FUNCTION_EVENT_DATA"] \ No newline at end of file