Skip to content

Commit e006924

Browse files
bors[bot]meili-botalallema
authored
Merge #292
292: Changes related to the next Meilisearch release (v0.26.0) r=alallema a=meili-bot Related to this issue: meilisearch/integration-guides#181 This PR: - gathers the changes related to the next Meilisearch release (v0.26.0) so that this package is ready when the official release is out. - should pass the tests against the [latest pre-release of Meilisearch](https://github.com/meilisearch/meilisearch/releases). - might eventually contain test failures until the Meilisearch v0.26.0 is out. ⚠️ This PR should NOT be merged until the next release of Meilisearch (v0.26.0) is out. _This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/master/guides/pre-release-week.md) purpose._ Done: - #296 - #298 - #297 - #302 Co-authored-by: meili-bot <[email protected]> Co-authored-by: Amélie <[email protected]> Co-authored-by: bors[bot] <26634292+bors[bot]@users.noreply.github.com> Co-authored-by: alallema <[email protected]>
2 parents 39b371e + 201ff7c commit e006924

File tree

15 files changed

+514
-79
lines changed

15 files changed

+514
-79
lines changed

.code-samples.meilisearch.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,3 +432,18 @@ security_guide_delete_key_1: |-
432432
authorization_header_1: |-
433433
$client = new Client('http://127.0.0.1:7700', 'masterKey');
434434
$client->getKeys();
435+
tenant_token_guide_generate_sdk_1: |-
436+
$searchRules = (object) [
437+
'patient_medical_records' => (object) [
438+
'filter' => 'user_id = 1',
439+
]
440+
];
441+
$options = [
442+
'apiKey' => 'B5KdX2MY2jV6EXfUs6scSfmC...',
443+
'expiresAt' => new DateTime('2025-12-20'),
444+
];
445+
446+
$token = $client->generateTenantToken($searchRules, $options);
447+
tenant_token_guide_search_sdk_1: |-
448+
$frontEndClient = new Client('http://127.0.0.1:7700', $token);
449+
$frontEndClient->index('patient_medical_records')->search('blood test');

.github/workflows/pre-release-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Get the latest Meilisearch RC
3131
run: echo "MEILISEARCH_VERSION=$(curl https://raw.githubusercontent.com/meilisearch/integration-guides/main/scripts/get-latest-meilisearch-rc.sh | bash)" >> $GITHUB_ENV
3232
- name: Meilisearch (${{ env.MEILISEARCH_VERSION }}) setup with Docker
33-
run: docker run -d -p 7700:7700 getmeili/meilisearch:${{ env.MEILISEARCH_VERSION }} ./meilisearch --master-key=masterKey --no-analytics=true
33+
run: docker run -d -p 7700:7700 getmeili/meilisearch:${{ env.MEILISEARCH_VERSION }} ./meilisearch --master-key=masterKey --no-analytics
3434
- name: Run test suite - default HTTP client (Guzzle 7)
3535
run: |
3636
sh scripts/tests.sh

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
composer remove --dev friendsofphp/php-cs-fixer --no-update --no-interaction
6161
composer update --prefer-dist --no-progress
6262
- name: Meilisearch (latest version) setup with Docker
63-
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey --no-analytics=true
63+
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey --no-analytics
6464
- name: Run test suite - default HTTP client (Guzzle 7)
6565
run: |
6666
sh scripts/tests.sh

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Each PR should pass the tests and the linter to be accepted.
4343
```bash
4444
# Tests
4545
curl -L https://install.meilisearch.com | sh # download Meilisearch
46-
./meilisearch --master-key=masterKey --no-analytics=true # run Meilisearch
46+
./meilisearch --master-key=masterKey --no-analytics # run Meilisearch
4747
composer test
4848
# Linter (with auto-fix)
4949
composer lint:fix

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ $index->search(
215215

216216
## 🤖 Compatibility with Meilisearch
217217

218-
This package only guarantees the compatibility with the [version v0.25.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.25.0).
218+
This package only guarantees the compatibility with the [version v0.26.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.26.0).
219219

220220
## 💡 Learn More
221221

src/Client.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use MeiliSearch\Endpoints\Keys;
1616
use MeiliSearch\Endpoints\Stats;
1717
use MeiliSearch\Endpoints\Tasks;
18+
use MeiliSearch\Endpoints\TenantToken;
1819
use MeiliSearch\Endpoints\Version;
1920
use Psr\Http\Client\ClientInterface;
2021
use Psr\Http\Message\RequestFactoryInterface;
@@ -35,6 +36,7 @@ class Client
3536
private Stats $stats;
3637
private Tasks $tasks;
3738
private Dumps $dumps;
39+
private TenantToken $tenantToken;
3840

3941
public function __construct(
4042
string $url,
@@ -50,5 +52,6 @@ public function __construct(
5052
$this->tasks = new Tasks($this->http);
5153
$this->keys = new Keys($this->http);
5254
$this->dumps = new Dumps($this->http);
55+
$this->tenantToken = new TenantToken($this->http, $apiKey);
5356
}
5457
}

src/Contracts/Endpoint.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ abstract class Endpoint
88
{
99
protected const PATH = '';
1010
protected Http $http;
11+
protected ?string $apiKey;
1112

12-
public function __construct(Http $http)
13+
public function __construct(Http $http, ?string $apiKey = null)
1314
{
1415
$this->http = $http;
16+
$this->apiKey = $apiKey;
1517
}
1618

1719
public function show(): ?array

src/Delegates/HandlesSystem.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@ public function stats(): array
3131
{
3232
return $this->stats->show();
3333
}
34+
35+
public function generateTenantToken($searchRules, ?array $options = []): string
36+
{
37+
return $this->tenantToken->generateTenantToken($searchRules, $options);
38+
}
3439
}

src/Endpoints/Delegates/HandlesKeys.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,31 @@
44

55
namespace MeiliSearch\Endpoints\Delegates;
66

7+
use MeiliSearch\Endpoints\Keys;
8+
79
trait HandlesKeys
810
{
911
public function getKeys(): array
1012
{
1113
return $this->keys->all();
1214
}
1315

14-
public function getKey($key): array
16+
public function getRawKeys(): array
17+
{
18+
return $this->keys->allRaw();
19+
}
20+
21+
public function getKey($key): Keys
1522
{
1623
return $this->keys->get($key);
1724
}
1825

19-
public function createKey(array $options = []): array
26+
public function createKey(array $options = []): Keys
2027
{
2128
return $this->keys->create($options);
2229
}
2330

24-
public function updateKey(string $key, array $options = []): array
31+
public function updateKey(string $key, array $options = []): Keys
2532
{
2633
return $this->keys->update($key, $options);
2734
}

src/Endpoints/Keys.php

Lines changed: 109 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,133 @@
44

55
namespace MeiliSearch\Endpoints;
66

7+
use DateTime;
78
use MeiliSearch\Contracts\Endpoint;
9+
use MeiliSearch\Contracts\Http;
810

911
class Keys extends Endpoint
1012
{
1113
protected const PATH = '/keys';
1214

13-
public function get($key): array
15+
private ?string $key;
16+
private ?string $description;
17+
private ?array $actions;
18+
private ?array $indexes;
19+
private ?DateTime $expiresAt;
20+
private ?DateTime $createdAt;
21+
private ?DateTime $updatedAt;
22+
23+
public function __construct(Http $http, $key = null, $description = null, $actions = null, $indexes = null, $expiresAt = null, $createdAt = null, $updatedAt = null)
24+
{
25+
$this->key = $key;
26+
$this->description = $description;
27+
$this->actions = $actions;
28+
$this->indexes = $indexes;
29+
$this->expiresAt = $expiresAt;
30+
$this->createdAt = $createdAt;
31+
$this->updatedAt = $updatedAt;
32+
33+
parent::__construct($http);
34+
}
35+
36+
/**
37+
* @return $this
38+
*/
39+
protected function newInstance(array $attributes): self
40+
{
41+
$this->key = $attributes['key'];
42+
$this->description = $attributes['description'];
43+
$this->actions = $attributes['actions'];
44+
$this->indexes = $attributes['indexes'];
45+
if ($attributes['expiresAt']) {
46+
$this->expiresAt = date_create_from_format('Y-m-d\TH:i:s\Z', $attributes['expiresAt']);
47+
}
48+
if ($attributes['createdAt']) {
49+
$this->createdAt = date_create_from_format('Y-m-d\TH:i:s.vu\Z', $attributes['createdAt']);
50+
}
51+
if ($attributes['updatedAt']) {
52+
$this->updatedAt = date_create_from_format('Y-m-d\TH:i:s.vu\Z', $attributes['updatedAt']);
53+
}
54+
55+
return $this;
56+
}
57+
58+
public function getKey(): ?string
59+
{
60+
return $this->key;
61+
}
62+
63+
public function getDescription(): ?string
64+
{
65+
return $this->description;
66+
}
67+
68+
public function getActions(): ?array
69+
{
70+
return $this->actions;
71+
}
72+
73+
public function getIndexes(): ?array
74+
{
75+
return $this->indexes;
76+
}
77+
78+
public function getExpiresAt(): ?DateTime
79+
{
80+
return $this->expiresAt;
81+
}
82+
83+
public function getCreatedAt(): ?DateTime
1484
{
15-
return $this->http->get(self::PATH.'/'.$key);
85+
return $this->createdAt;
86+
}
87+
88+
public function getUpdatedAt(): ?DateTime
89+
{
90+
return $this->updatedAt;
91+
}
92+
93+
public function get($key): self
94+
{
95+
$response = $this->http->get(self::PATH.'/'.$key);
96+
97+
return $this->newInstance($response);
1698
}
1799

18100
public function all(): array
101+
{
102+
$keys = [];
103+
104+
foreach ($this->allRaw()['results'] as $key) {
105+
$keys[] = $this->newInstance($key);
106+
}
107+
108+
return $keys;
109+
}
110+
111+
public function allRaw(): array
19112
{
20113
return $this->http->get(self::PATH.'/');
21114
}
22115

23-
public function create(array $options = []): array
116+
public function create(array $options = []): self
24117
{
25-
return $this->http->post(self::PATH, $options);
118+
if ($options['expiresAt'] && $options['expiresAt'] instanceof DateTime) {
119+
$options['expiresAt'] = $options['expiresAt']->format('Y-m-d\TH:i:s.vu\Z');
120+
}
121+
$response = $this->http->post(self::PATH, $options);
122+
123+
return $this->newInstance($response);
26124
}
27125

28-
public function update(string $key, array $options = []): array
126+
public function update(string $key, array $options = []): self
29127
{
30-
return $this->http->patch(self::PATH.'/'.$key, $options);
128+
if ($options['expiresAt'] && $options['expiresAt'] instanceof DateTime) {
129+
$options['expiresAt'] = $options['expiresAt']->format('Y-m-d\TH:i:s.vu\Z');
130+
}
131+
$response = $this->http->patch(self::PATH.'/'.$key, $options);
132+
133+
return $this->newInstance($response);
31134
}
32135

33136
public function delete(string $key): array

0 commit comments

Comments
 (0)