From 0c7e7cca289398d1daa0c3054814c43a52542724 Mon Sep 17 00:00:00 2001 From: Siddharth Bhansali Date: Tue, 16 Jul 2024 22:25:39 +0530 Subject: [PATCH] feat: filter connection platforms (#8) --- README.md | 2 +- composer.json | 2 +- src/AuthKit.php | 8 +++++--- src/package.json | 10 ---------- src/test.php | 6 ------ 5 files changed, 7 insertions(+), 21 deletions(-) delete mode 100644 src/package.json delete mode 100644 src/test.php diff --git a/README.md b/README.md index 9f89593..73a0fbc 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ $response = $authkit->create([ echo json_encode($response); ``` -Of if you're using Laravel, you can define a route like below: +Or if you're using Laravel, you can define a route like below: ```php secret = $secret; $this->configs = $configs; + $this->environment = str_contains($secret, "sk_live_") ? "live" : "test"; } private function getUrl(string $type): string @@ -103,7 +105,7 @@ private function getConnectionDefinitions(): array /** * @throws GuzzleException */ - private function getServiceId(): array + private function getSessionId(): array { return $this->apiCall("GET", $this->getUrl("get_session_id")); } @@ -122,7 +124,7 @@ private function createEmbedToken($connected_platforms, $event_links, $settings) "label" => $event_links["label"], "environment" => str_starts_with($this->secret, "sk_test") ? "test" : "live", "expiresAt" => (time() * 1000) + (5 * 1000 * 60), - "sessionId" => $this->getServiceId()['id'], + "sessionId" => $this->getSessionId()['id'], "features" => $settings["features"] ]; @@ -140,7 +142,7 @@ public function create(array $payload): array|string $active_connection_definitions = isset($connection_definitions["rows"]) ? array_filter($connection_definitions["rows"], fn ($connection_definition) => $connection_definition["active"]) : []; $connected_platforms = isset($settings["connectedPlatforms"]) ? array_values(array_filter($settings["connectedPlatforms"], - fn ($platform) => in_array($platform["connectionDefinitionId"], array_column($active_connection_definitions, "_id")) && $platform["active"])) : []; + fn ($platform) => in_array($platform["connectionDefinitionId"], array_column($active_connection_definitions, "_id")) && $platform["active"] && ($this->environment === "live" ? (isset($platform["environment"]) && $platform["environment"] === "live") : ((isset($platform["environment"]) && $platform["environment"] === 'test') || !isset($platform["environment"]))))) : []; return $this->createEmbedToken($connected_platforms, $event_link, $settings); } catch (GuzzleException $e) { diff --git a/src/package.json b/src/package.json deleted file mode 100644 index 92d802b..0000000 --- a/src/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "src", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "private": true -} diff --git a/src/test.php b/src/test.php deleted file mode 100644 index ce91514..0000000 --- a/src/test.php +++ /dev/null @@ -1,6 +0,0 @@ -