Skip to content

Commit

Permalink
feat: filter connection platforms (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharth-bhansali authored Jul 16, 2024
1 parent 772799d commit 0c7e7cc
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php
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": "integrationos/authkit-php",
"version": "1.0.0",
"version": "1.2.0",
"type": "library",
"autoload": {
"psr-4": {
Expand Down
8 changes: 5 additions & 3 deletions src/AuthKit.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ class AuthKit
{
private string $secret;
private array $configs;
private string $environment;

function __construct(string $secret, array $configs = [])
{
$this->secret = $secret;
$this->configs = $configs;
$this->environment = str_contains($secret, "sk_live_") ? "live" : "test";
}

private function getUrl(string $type): string
Expand Down Expand Up @@ -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"));
}
Expand All @@ -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"]
];

Expand All @@ -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) {
Expand Down
10 changes: 0 additions & 10 deletions src/package.json

This file was deleted.

6 changes: 0 additions & 6 deletions src/test.php

This file was deleted.

0 comments on commit 0c7e7cc

Please sign in to comment.