Skip to content

Develop #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .git_hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

docker run --rm -v $(pwd):/code ghcr.io/php-cs-fixer/php-cs-fixer:${FIXER_VERSION:-3-php8.3} fix --config=/code/.php-cs-fixer.php /code/src
docker run --rm -v $(pwd):/code ghcr.io/php-cs-fixer/php-cs-fixer:3.64-php8.3 fix --config=/code/.php-cs-fixer.php
8 changes: 7 additions & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@
'operators' => ['=>' => null],
],
'multiline_whitespace_before_semicolons' => false,
'phpdoc_trim' => false,
'phpdoc_no_empty_return' => false,
'phpdoc_types_order' => [
'null_adjustment' => 'always_last',
'sort_algorithm' => 'none',
],
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
->in(__DIR__ . "/src")
);
56 changes: 56 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,59 @@
## [5.0.0-develop.3](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/compare/v5.0.0-develop.2...v5.0.0-develop.3) (2024-09-09)


### Bug Fixes

* php-cs-fixer keep nullable return annotations ([99011b7](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/commit/99011b736a2782fc50f488d5e83d489540a860fb))

## [5.0.0-develop.3](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/compare/v5.0.0-develop.2...v5.0.0-develop.3) (2024-09-04)


### Bug Fixes

* php-cs-fixer keep nullable return annotations ([99011b7](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/commit/99011b736a2782fc50f488d5e83d489540a860fb))

## [5.0.0-develop.2](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/compare/v5.0.0-develop.1...v5.0.0-develop.2) (2024-09-04)


### Bug Fixes

* use linter with current config via docker ([9613c34](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/commit/9613c34535c8ef675a0d5e129ca4a23b1ee6fcc9))

## [5.0.0-develop.1](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/compare/v4.1.0...v5.0.0-develop.1) (2024-09-04)


### ⚠ BREAKING CHANGES

* Renamed Error Response Model Names
`ErrorEvent403ResponseError` → `Common403ErrorResponse`
`ManyRequestsResponse` → `TooManyRequestsResponse`
* Webhook `tag` field is now optional
* API Methods now throws `SerializationException`
* API Methods returns tuple instead of models
* API Methods removed other than `getModel`
* Upgraded minimum php version to 8.1
* Request logic is rewritten, Upgraded minimum php version to 8.1

### Features

* add `remoteControl`, `velocity` and `developerTools` signals ([5bf9368](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/commit/5bf9368fb1bb5abbfa72366fe6c66fe32352ad54))
* add delete visitor data endpoint ([a00f325](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/commit/a00f325706af38cc20e4c387db44dfa83c7a7a22))
* add retry after policy to api exception ([64e0510](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/commit/64e05100a2c20c8d1f8e5f9719ee5292c59761c2))
* add support for validating webhook signatures inter-768 ([6a4cbd6](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/commit/6a4cbd6e2a521a209806337d90ae8f7e291a534b))
* add update event endpoint (PUT) ([cb21d0b](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/commit/cb21d0b4c48b7b94f4e9a7de1ab74313fe339e5f))
* change api to return tuple instead of serialized model ([62e4ad3](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/commit/62e4ad3020425667f45e3beeb166b4095a437ab5))
* introduce rawResponse for getVisits and getEvent methods ([9b01ba6](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/commit/9b01ba65e7ac794c77afedc155823baef2c80b17))
* introduce serialization exception ([bfea23a](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/commit/bfea23a50b61152d4fc65d290c730d0e3fcb6123))
* only generate models and docs from swagger codegen ([26e984f](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/commit/26e984ffd01dc9f21af3dd4da75fcb7e4309961f))
* remove raw response and introduce with http info ([ce2fedf](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/commit/ce2fedfcd94f5f1459049ba49eff75e2d3b8620c))
* rewrite request logic ([0016822](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/commit/001682270fd4370484b25062550a65bd375b9372))
* upgrade min php version to 8 ([5698871](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/commit/5698871fa497ee4ad50b2941d39769b45f15dfc2))


### Bug Fixes

* serializaiton problem on sealed results ([29cb26c](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/commit/29cb26c3f50bfa035ca750948bb92a2299f579bd))

## [5.0.0](https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/compare/v4.1.0...v5.0.0) (2024-09-04)


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
This PHP package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:

- API version: 3
- Package version: 5.0.0
- Package version: dev-5.0.0-3
- Build package: io.swagger.codegen.v3.generators.php.PhpClientCodegen

## Requirements
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fingerprint/fingerprint-pro-server-api-sdk",
"version": "5.0.0",
"version": "dev-5.0.0-3",
"description": "Fingerprint Pro Server API provides a way for validating visitors’ data issued by Fingerprint Pro.",
"keywords": [
"swagger",
Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"gitUserId": "fingerprintjs",
"gitRepoId": "fingerprint-pro-server-api-php-sdk",
"description": "Fingerprint Pro Server API provides a way for validating visitors’ data issued by Fingerprint Pro.",
"artifactVersion": "5.0.0"
"artifactVersion": "dev-5.0.0-3"
}
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
env_file:
- .env
lint:
image: ghcr.io/php-cs-fixer/php-cs-fixer:${FIXER_VERSION:-3-php8.3}
image: ghcr.io/php-cs-fixer/php-cs-fixer:3.64-php8.3
volumes:
- .:/code
- ./.php-cs-fixer.php:/code/.php-cs-fixer.php
Expand Down
56 changes: 29 additions & 27 deletions generate_coverage_report.php
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
<?php

# This script generates JSON report for coverage badge github action and generates markdown report for coverage-diff github action
// This script generates JSON report for coverage badge github action and generates markdown report for coverage-diff github action

$outputPath = __DIR__ . "/cov/json/";
$markdownPath = __DIR__ . "/cov/markdown/";
$outputPath = __DIR__.'/cov/json/';
$markdownPath = __DIR__.'/cov/markdown/';

$contents = file_get_contents(__DIR__ . "/cov/xml/clover.xml");
$contents = file_get_contents(__DIR__.'/cov/xml/clover.xml');
$xml = simplexml_load_string($contents);
$arr = json_decode(json_encode($xml), true);

$metrics = $arr["project"]["metrics"]["@attributes"];
$metrics = $arr['project']['metrics']['@attributes'];

// Calculate coverage metrics
$statementsCovered = (int)$metrics["coveredstatements"];
$statementsTotal = (int)$metrics["statements"];
$statementsCovered = (int) $metrics['coveredstatements'];
$statementsTotal = (int) $metrics['statements'];
$statementsPct = $statementsTotal > 0 ? ($statementsCovered / $statementsTotal) * 100 : 0;

$functionsCovered = (int)$metrics["coveredmethods"];
$functionsTotal = (int)$metrics["methods"];
$functionsCovered = (int) $metrics['coveredmethods'];
$functionsTotal = (int) $metrics['methods'];
$functionsPct = $functionsTotal > 0 ? ($functionsCovered / $functionsTotal) * 100 : 0;

// Function to return color based on percentage
function getCoverageStatus($percentage) {
function getCoverageStatus($percentage)
{
if ($percentage >= 80) {
return ":green_circle:";
} elseif ($percentage >= 50) {
return ":yellow_circle:";
} else {
return ":red_circle:";
return ':green_circle:';
}
if ($percentage >= 50) {
return ':yellow_circle:';
}

return ':red_circle:';
}

// Generate JSON report
$map = [
"total" => [
"statements" => ["pct" => number_format($statementsPct, 2)],
]
'total' => [
'statements' => ['pct' => number_format($statementsPct, 2)],
],
];
file_put_contents($outputPath . "index.json", json_encode($map));
file_put_contents($outputPath.'index.json', json_encode($map));

// Generate Markdown report
$markdown = "# Code Coverage Report\n\n";
Expand All @@ -64,15 +66,15 @@ function getCoverageStatus($percentage) {
$markdown .= "| St. | File | Methods | Statements | Total Coverage |\n";
$markdown .= "|-----|------|---------|------------|----------------|\n";

foreach ($arr["project"]["file"] as $file) {
$filePath = 'src/' . explode('src/', $file["@attributes"]['name'])[1];
$fileMetrics = $file["metrics"]["@attributes"];
foreach ($arr['project']['file'] as $file) {
$filePath = 'src/'.explode('src/', $file['@attributes']['name'])[1];
$fileMetrics = $file['metrics']['@attributes'];

$methodsPct = $fileMetrics["methods"] > 0 ? ($fileMetrics["coveredmethods"] / $fileMetrics["methods"]) * 100 : 0;
$statementsPct = $fileMetrics["statements"] > 0 ? ($fileMetrics["coveredstatements"] / $fileMetrics["statements"]) * 100 : 0;
$methodsPct = $fileMetrics['methods'] > 0 ? ($fileMetrics['coveredmethods'] / $fileMetrics['methods']) * 100 : 0;
$statementsPct = $fileMetrics['statements'] > 0 ? ($fileMetrics['coveredstatements'] / $fileMetrics['statements']) * 100 : 0;

$fileElements = (int)$fileMetrics["elements"];
$fileCoveredElements = (int)$fileMetrics["coveredelements"];
$fileElements = (int) $fileMetrics['elements'];
$fileCoveredElements = (int) $fileMetrics['coveredelements'];
$totalCoveragePct = $fileElements > 0 ? ($fileCoveredElements / $fileElements) * 100 : 0;

$markdown .= sprintf(
Expand All @@ -87,4 +89,4 @@ function getCoverageStatus($percentage) {

$markdown .= "\n</details>\n";

file_put_contents($markdownPath . "coverage_report.md", $markdown);
file_put_contents($markdownPath.'coverage_report.md', $markdown);
47 changes: 26 additions & 21 deletions run_checks.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
<?php

require_once(__DIR__ . '/vendor/autoload.php');
require_once __DIR__.'/vendor/autoload.php';

$host = getenv('FP_API_HOST');
$api_key = getenv('FP_PRIVATE_API_KEY');

use Fingerprint\ServerAPI\Api\FingerprintApi;
use Fingerprint\ServerAPI\Configuration;
use GuzzleHttp\Client;
use Fingerprint\ServerAPI\Webhook\WebhookVerifier;
use GuzzleHttp\Client;

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);

$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";
$request_id = $_ENV['FP_REQUEST_ID'] ?? getenv('FP_REQUEST_ID') ?? "Request ID not defined";
$region_env = $_ENV['FP_REGION'] ?? getenv('FP_REGION') ?? "us";
$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';
$request_id = $_ENV['FP_REQUEST_ID'] ?? getenv('FP_REQUEST_ID') ?? 'Request ID not defined';
$region_env = $_ENV['FP_REGION'] ?? getenv('FP_REGION') ?? 'us';

$region = Configuration::REGION_GLOBAL;
if ($region_env === 'eu') {
if ('eu' === $region_env) {
$region = Configuration::REGION_EUROPE;
} else if ($region_env === 'ap') {
} elseif ('ap' === $region_env) {
$region = Configuration::REGION_ASIA;
}

Expand All @@ -44,64 +43,70 @@

try {
list($result, $response) = $client->getVisits($visitor_id);
if($result->getVisitorId() !== $visitor_id) {
if ($result->getVisitorId() !== $visitor_id) {
throw new Exception('Argument visitorId is not equal to deserialized getVisitorId');
}
fwrite(STDOUT, sprintf("Got visits: %s \n", $response->getBody()->getContents()));
} catch (Exception $e) {
fwrite(STDERR, sprintf("Exception when calling FingerprintApi->getVisits: %s\n", $e->getMessage()));

exit(1);
}

try {
/** @var $result \Fingerprint\ServerAPI\Model\EventResponse */
/** @var \Fingerprint\ServerAPI\Model\EventResponse $result */
list($result, $response) = $client->getEvent($request_id);
if($result->getProducts()->getIdentification()->getData()->getRequestId() !== $request_id) {
if ($result->getProducts()->getIdentification()->getData()->getRequestId() !== $request_id) {
throw new Exception('Argument requestId is not equal to deserialized getRequestId');
}
fwrite(STDOUT, sprintf("\n\nGot event: %s \n", $response->getBody()->getContents()));
} catch (Exception $e) {
fwrite(STDERR, sprintf("\n\nException when calling FingerprintApi->getVisits: %s\n", $e->getMessage()));

exit(1);
}

$eventPromise = $client->getEventAsync($request_id);
$eventPromise->then(function ($tuple) use($request_id) {
$eventPromise->then(function ($tuple) use ($request_id) {
list($result, $response) = $tuple;
if($result->getProducts()->getIdentification()->getData()->getRequestId() !== $request_id) {
if ($result->getProducts()->getIdentification()->getData()->getRequestId() !== $request_id) {
throw new Exception('Argument requestId is not equal to deserialized getRequestId');
}
fwrite(STDOUT, sprintf("\n\nGot async event: %s \n", $response->getBody()->getContents()));
}, function($exception) {
}, function ($exception) {
fwrite(STDERR, sprintf("\n\nException when calling FingerprintApi->getVisits: %s\n", $exception->getMessage()));

exit(1);
})->wait();

$visitsPromise = $client->getVisitsAsync($visitor_id);
$visitsPromise->then(function($tuple) use($visitor_id) {
$visitsPromise->then(function ($tuple) use ($visitor_id) {
list($result, $response) = $tuple;
if($result->getVisitorId() !== $visitor_id) {
if ($result->getVisitorId() !== $visitor_id) {
throw new Exception('Argument visitorId is not equal to deserialized getVisitorId');
}
fwrite(STDOUT, sprintf("\n\nGot async visits: %s \n", $response->getBody()->getContents()));
}, function ($exception) {
fwrite(STDERR, sprintf("\n\nException when calling FingerprintApi->getVisits: %s\n", $exception->getMessage()));

exit(1);
})->wait();

$webhookSecret = "secret";
$webhookData = "data";
$webhookHeader = "v1=1b2c16b75bd2a870c114153ccda5bcfca63314bc722fa160d690de133ccbb9db";
$webhookSecret = 'secret';
$webhookData = 'data';
$webhookHeader = 'v1=1b2c16b75bd2a870c114153ccda5bcfca63314bc722fa160d690de133ccbb9db';
$isValidWebhookSign = WebhookVerifier::IsValidWebhookSignature($webhookHeader, $webhookData, $webhookSecret);
if($isValidWebhookSign) {
if ($isValidWebhookSign) {
fwrite(STDOUT, sprintf("\n\nVerified webhook signature\n"));
} else {
fwrite(STDERR, sprintf("\n\nWebhook signature verification failed\n"));

exit(1);
}

// Enable the deprecated ArrayAccess return type warning again if needed
error_reporting(error_reporting() | E_DEPRECATED);

fwrite(STDOUT, "\n\nChecks passed\n");

exit(0);
10 changes: 8 additions & 2 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@ rm -f ./src/Model/*

java -jar ./bin/swagger-codegen-cli.jar generate -t ./template -l php -i ./res/fingerprint-server-api.yaml -o ./ -c config.json

if [ -z "$GITHUB_ACTIONS" ]; then
docker-compose run --rm lint
if [ ! -f .php-cs-fixer.php ]; then
echo ".php-cs-fixer.php configuration file not found!"
exit 1
fi

echo "Using .php-cs-fixer.php configuration:"
cat .php-cs-fixer.php

docker run --rm -v $(pwd):/code ghcr.io/php-cs-fixer/php-cs-fixer:3.64-php8.3 fix --config=/code/.php-cs-fixer.php

# fix invalid code generated for structure with additionalProperties
(
# Model file fix
Expand Down
9 changes: 5 additions & 4 deletions sealed_results_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
use Fingerprint\ServerAPI\Sealed\DecryptionKey;
use Fingerprint\ServerAPI\Sealed\Sealed;

require_once(__DIR__ . '/vendor/autoload.php');
require_once __DIR__.'/vendor/autoload.php';

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->safeLoad();

$sealed_result = base64_decode($_ENV['BASE64_SEALED_RESULT'] ?? getenv('BASE64_SEALED_RESULT') ?? "");
$sealed_key = base64_decode($_ENV['BASE64_KEY'] ?? getenv('BASE64_KEY') ?? "");

$sealed_result = base64_decode($_ENV['BASE64_SEALED_RESULT'] ?? getenv('BASE64_SEALED_RESULT') ?? '');
$sealed_key = base64_decode($_ENV['BASE64_KEY'] ?? getenv('BASE64_KEY') ?? '');

// Temporarily suppress a million deprecated ArrayAccess return type warnings for readability
// Our SDK generator does not yet support PHP's new attributes system
Expand All @@ -24,11 +23,13 @@
fwrite(STDOUT, sprintf("Unsealed event: %s \n", $data));
} catch (Exception $e) {
fwrite(STDERR, sprintf("Exception when unsealing event: %s\n", $e->getMessage()));

exit(1);
}

// Enable the deprecated ArrayAccess return type warning again if needed
error_reporting(error_reporting() | E_DEPRECATED);

fwrite(STDOUT, "Checks passed\n");

exit(0);
Loading
Loading