diff --git a/.env.example b/.env.example index 2eca626b..448640f2 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ FP_PRIVATE_API_KEY= -FP_VISITOR_ID= -FP_REQUEST_ID= +FP_VISITOR_ID_TO_DELETE= +FP_REQUEST_ID_TO_UPDATE= # "eu" or "ap", the default is "us" -FP_REGION= \ No newline at end of file +FP_REGION= diff --git a/.github/workflows/functional.yml b/.github/workflows/functional.yml index 83b79054..512ebfb4 100644 --- a/.github/workflows/functional.yml +++ b/.github/workflows/functional.yml @@ -1,9 +1,9 @@ name: Functional tests on: - pull_request_target: - branches: - - '*' + push: + branches-ignore: + - main workflow_dispatch: schedule: - cron: '0 5 * * *' @@ -34,8 +34,6 @@ jobs: env: FP_PRIVATE_API_KEY: "${{ secrets.FP_PRIVATE_API_KEY }}" FP_API_HOST: "${{ secrets.FP_API_HOST }}" - FP_VISITOR_ID: "${{ secrets.FP_VISITOR_ID }}" - FP_REQUEST_ID: "${{ secrets.FP_REQUEST_ID }}" report-status: needs: functional_tests diff --git a/run_checks.php b/run_checks.php index fe55c81c..53f35dc9 100644 --- a/run_checks.php +++ b/run_checks.php @@ -19,9 +19,7 @@ $dotenv->safeLoad(); $api_key = $_ENV['FP_PRIVATE_API_KEY'] ?? getenv('FP_PRIVATE_API_KEY') ?? 'Private API Key not defined'; -$visitor_id = $_ENV['FP_VISITOR_ID'] ?? getenv('FP_VISITOR_ID') ?? 'Visitor ID not defined'; $visitor_id_to_delete = $_ENV['FP_VISITOR_ID_TO_DELETE'] ?? getenv('FP_VISITOR_ID_TO_DELETE') ?? false; -$request_id = $_ENV['FP_REQUEST_ID'] ?? getenv('FP_REQUEST_ID') ?? 'Request ID not defined'; $request_id_to_update = $_ENV['FP_REQUEST_ID_TO_UPDATE'] ?? getenv('FP_REQUEST_ID_TO_UPDATE') ?? false; $region_env = $_ENV['FP_REGION'] ?? getenv('FP_REGION') ?? 'us'; @@ -47,6 +45,28 @@ // https://github.com/swagger-api/swagger-codegen/issues/11820 error_reporting(error_reporting() & ~E_DEPRECATED); +// FingerprintApi->searchEvents usage example +try { + // 3 month from now + $start = (new DateTime())->sub(new DateInterval('P3M')); + $end = new DateTime(); + + /** @var SearchEventsResponse $result */ + list($result, $response) = $client->searchEvents(10, start: $start->getTimestamp() * 1000, end: $end->getTimestamp() * 1000); + if (!is_countable($result->getEvents()) || count($result->getEvents()) === 0) { + throw new Exception('No events found'); + } + $identification_data = $result->getEvents()[0]->getProducts()->getIdentification()->getData(); + $visitor_id = $identification_data->getVisitorId(); + $request_id = $identification_data->getRequestId(); + fwrite(STDOUT, sprintf("\n\nGot events: %s \n", $response->getBody()->getContents())); +} catch (Exception $e) { + fwrite(STDERR, sprintf("\n\nException when calling FingerprintApi->searchEvents: %s\n", $e->getMessage())); + + exit(1); +} + +// FingerprintApi->getVisits usage example try { /** @var VisitorsGetResponse $result */ list($result, $response) = $client->getVisits($visitor_id); @@ -60,6 +80,7 @@ exit(1); } +// FingerprintApi->deleteVisitorData usage example if ($visitor_id_to_delete) { try { list($model, $response) = $client->deleteVisitorData($visitor_id_to_delete); @@ -70,6 +91,7 @@ } } +// FingerprintApi->getEvent usage example try { /** @var EventsGetResponse $result */ list($result, $response) = $client->getEvent($request_id); @@ -83,23 +105,7 @@ exit(1); } -try { - // 2 years from now - $start = (new DateTime())->sub(new DateInterval('P2Y')); - $end = new DateTime(); - - /** @var SearchEventsResponse $result */ - list($result, $response) = $client->searchEvents(10, start: $start->getTimestamp() * 1000, end: $end->getTimestamp() * 1000); - if (!is_countable($result->getEvents()) || count($result->getEvents()) === 0) { - throw new Exception('No events found'); - } - fwrite(STDOUT, sprintf("\n\nGot events: %s \n", $response->getBody()->getContents())); -} catch (Exception $e) { - fwrite(STDERR, sprintf("\n\nException when calling FingerprintApi->searchEvents: %s\n", $e->getMessage())); - - exit(1); -} - +// FingerprintApi->updateEvent usage example if ($request_id_to_update) { try { $body = new EventsUpdateRequest([ @@ -113,6 +119,7 @@ } } +// Call API asynchronously examples $eventPromise = $client->getEventAsync($request_id); $eventPromise->then(function ($tuple) use ($request_id) { list($result, $response) = $tuple; @@ -139,6 +146,7 @@ exit(1); })->wait(); +// Webhook verification example $webhookSecret = 'secret'; $webhookData = 'data'; $webhookHeader = 'v1=1b2c16b75bd2a870c114153ccda5bcfca63314bc722fa160d690de133ccbb9db'; @@ -151,6 +159,27 @@ exit(1); } +// Check that old events still match expected format +try { + list($result_old) = $client->searchEvents(1, start: $start->getTimestamp() * 1000, end: $end->getTimestamp() * 1000, reverse: true); + if (!is_countable($result_old->getEvents()) || count($result_old->getEvents()) === 0) { + throw new Exception('No old events found'); + } + $identification_data_old = $result_old->getEvents()[0]->getProducts()->getIdentification()->getData(); + $visitor_id_old = $identification_data_old->getVisitorId(); + $request_id_old = $identification_data_old->getRequestId(); + + if ($visitor_id === $visitor_id_old || $request_id === $request_id_old) { + throw new Exception('Old events are identical to new'); + } + + list($result, $response) = $client->getEvent($request_id_old); + list($result, $response) = $client->getVisits($visitor_id_old); + fwrite(STDERR, sprintf("\n\nOld events are good\n")); +} catch (Exception $e) { + fwrite(STDERR, sprintf("\n\nException when trying to read old data: %s\n", $e->getMessage())); +} + // Enable the deprecated ArrayAccess return type warning again if needed error_reporting(error_reporting() | E_DEPRECATED);