+3
-5
composer.json
+3
-5
composer.json
···
45
45
}
46
46
},
47
47
"scripts": {
48
-
"test": "vendor/bin/pest",
49
-
"test-coverage": "vendor/bin/pest --coverage",
48
+
"test": "vendor/bin/phpunit",
49
+
"test-coverage": "vendor/bin/phpunit --coverage-html coverage",
50
50
"format": "vendor/bin/php-cs-fixer fix"
51
51
},
52
52
"extra": {
···
62
62
"minimum-stability": "dev",
63
63
"prefer-stable": true,
64
64
"config": {
65
-
"allow-plugins": {
66
-
"pestphp/pest-plugin": false
67
-
}
65
+
"sort-packages": true
68
66
}
69
67
}
+41
-38
docs/extensions.md
+41
-38
docs/extensions.md
···
14
14
| `AtpClient::hasDomainExtension($domain, $name)` | Check if a request client extension is registered |
15
15
| `AtpClient::flushExtensions()` | Clear all extensions (useful for testing) |
16
16
17
-
The same methods are available on `AtpPublicClient` for unauthenticated extensions.
18
-
19
17
### Extension Types
20
18
21
19
| Type | Access Pattern | Use Case |
···
30
28
```bash
31
29
# Create a domain client extension
32
30
php artisan make:atp-client AnalyticsClient
33
-
34
-
# Create a public domain client extension
35
-
php artisan make:atp-client DiscoverClient --public
36
31
37
32
# Create a request client extension for an existing domain
38
33
php artisan make:atp-request MetricsClient --domain=bsky
39
-
40
-
# Create a public request client extension
41
-
php artisan make:atp-request TrendingClient --domain=bsky --public
42
34
```
43
35
44
36
The generated files are placed in configurable directories. You can customize these paths in `config/client.php`:
···
46
38
```php
47
39
'generators' => [
48
40
'client_path' => 'app/Services/Clients',
49
-
'client_public_path' => 'app/Services/Clients/Public',
50
41
'request_path' => 'app/Services/Clients/Requests',
51
-
'request_public_path' => 'app/Services/Clients/Public/Requests',
52
42
],
53
43
```
54
44
···
225
215
$authorMetrics = $client->bsky->metrics->getAuthorMetrics('someone.bsky.social');
226
216
```
227
217
228
-
## Public Client Extensions
218
+
## Public vs Authenticated Mode
229
219
230
-
The `AtpPublicClient` supports the same extension system for unauthenticated API access:
220
+
The `AtpClient` class works in both public and authenticated modes. Both `Atp::public()` and `Atp::as()` return the same `AtpClient` class:
231
221
232
222
```php
233
-
use SocialDept\AtpClient\Client\Public\AtpPublicClient;
223
+
// Public mode - no authentication
224
+
$publicClient = Atp::public('https://public.api.bsky.app');
225
+
$publicClient->bsky->actor->getProfile('someone.bsky.social');
234
226
235
-
// Domain client extension
236
-
AtpPublicClient::extend('discover', fn($atp) => new DiscoverClient($atp));
237
-
238
-
// Request client extension on existing domain
239
-
AtpPublicClient::extendDomain('bsky', 'trending', fn($bsky) => new TrendingClient($bsky));
227
+
// Authenticated mode - with session
228
+
$authClient = Atp::as('did:plc:xxx');
229
+
$authClient->bsky->actor->getProfile('someone.bsky.social');
240
230
```
241
231
242
-
For public request clients, extend `PublicRequest` instead of `Request`:
243
-
244
-
```php
245
-
<?php
246
-
247
-
namespace App\Atp;
248
-
249
-
use SocialDept\AtpClient\Client\Public\Requests\PublicRequest;
250
-
251
-
class TrendingPublicClient extends PublicRequest
252
-
{
253
-
public function getPopularFeeds(int $limit = 10): array
254
-
{
255
-
return $this->atp->bsky->feed->getPopularFeedGenerators($limit)->feeds;
256
-
}
257
-
}
258
-
```
232
+
Extensions registered on `AtpClient` work in both modes. The underlying HTTP layer automatically handles authentication based on whether a session is present.
259
233
260
234
## Registering Multiple Extensions
261
235
···
272
246
AtpClient::extendDomain('bsky', 'metrics', fn($bsky) => new BskyMetricsClient($bsky));
273
247
AtpClient::extendDomain('bsky', 'lists', fn($bsky) => new BskyListsClient($bsky));
274
248
AtpClient::extendDomain('atproto', 'backup', fn($atproto) => new RepoBackupClient($atproto));
275
-
276
-
// Public client extensions
277
-
AtpPublicClient::extend('discover', fn($atp) => new DiscoverClient($atp));
278
249
}
279
250
```
280
251
···
451
422
}
452
423
}
453
424
```
425
+
426
+
### Documenting Scope Requirements
427
+
428
+
Use the `#[ScopedEndpoint]` and `#[PublicEndpoint]` attributes to document the authentication requirements of your extension methods:
429
+
430
+
```php
431
+
use SocialDept\AtpClient\Attributes\PublicEndpoint;
432
+
use SocialDept\AtpClient\Attributes\ScopedEndpoint;
433
+
use SocialDept\AtpClient\Client\Requests\Request;
434
+
use SocialDept\AtpClient\Enums\Scope;
435
+
436
+
class BskyMetricsClient extends Request
437
+
{
438
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:app.bsky.feed.getTimeline')]
439
+
public function getTimelineMetrics(): array
440
+
{
441
+
$timeline = $this->atp->bsky->feed->getTimeline();
442
+
// Process and return metrics...
443
+
}
444
+
445
+
#[PublicEndpoint]
446
+
public function getPublicPostMetrics(string $uri): array
447
+
{
448
+
$thread = $this->atp->bsky->feed->getPostThread($uri);
449
+
// Process and return metrics...
450
+
}
451
+
}
452
+
```
453
+
454
+
> **Note:** These attributes currently serve as documentation only. Runtime scope enforcement will be implemented in a future release. Using them correctly now ensures forward compatibility.
455
+
456
+
Methods with `#[ScopedEndpoint]` indicate they require authentication, while methods with `#[PublicEndpoint]` work without authentication. See [scopes.md](scopes.md) for full documentation on scope handling.
454
457
455
458
## Available Domains
456
459
+408
docs/scopes.md
+408
docs/scopes.md
···
1
+
# OAuth Scopes
2
+
3
+
The AT Protocol uses OAuth scopes to control what actions an application can perform on behalf of a user. AtpClient provides attributes for documenting scope requirements on endpoints.
4
+
5
+
> **Note:** The `#[ScopedEndpoint]` and `#[PublicEndpoint]` attributes currently serve as documentation only. Runtime scope validation and enforcement will be implemented in a future release. Using these attributes correctly now ensures forward compatibility.
6
+
7
+
## Quick Reference
8
+
9
+
### Scope Enum
10
+
11
+
```php
12
+
use SocialDept\AtpClient\Enums\Scope;
13
+
14
+
// Transition scopes (current AT Protocol scopes)
15
+
Scope::Atproto // 'atproto' - Full access
16
+
Scope::TransitionGeneric // 'transition:generic' - General API access
17
+
Scope::TransitionEmail // 'transition:email' - Email access
18
+
Scope::TransitionChat // 'transition:chat.bsky' - Chat access
19
+
20
+
// Granular scope builders (future AT Protocol scopes)
21
+
Scope::repo('app.bsky.feed.post', ['create', 'delete']) // Record operations
22
+
Scope::rpc('app.bsky.feed.getTimeline') // RPC endpoint access
23
+
Scope::blob('image/*') // Blob upload access
24
+
Scope::account('email') // Account attribute access
25
+
Scope::identity('handle') // Identity attribute access
26
+
```
27
+
28
+
### ScopedEndpoint Attribute
29
+
30
+
```php
31
+
use SocialDept\AtpClient\Attributes\ScopedEndpoint;
32
+
use SocialDept\AtpClient\Enums\Scope;
33
+
34
+
#[ScopedEndpoint(Scope::TransitionGeneric)]
35
+
public function getTimeline(): GetTimelineResponse
36
+
{
37
+
// Method implementation
38
+
}
39
+
```
40
+
41
+
## Understanding AT Protocol Scopes
42
+
43
+
### Current Transition Scopes
44
+
45
+
The AT Protocol is currently in a transition period where broad "transition scopes" are used:
46
+
47
+
| Scope | Description |
48
+
|-------|-------------|
49
+
| `atproto` | Full access to the AT Protocol |
50
+
| `transition:generic` | General API access for most operations |
51
+
| `transition:email` | Access to email-related operations |
52
+
| `transition:chat.bsky` | Access to Bluesky chat features |
53
+
54
+
### Future Granular Scopes
55
+
56
+
The AT Protocol is moving toward granular scopes that provide fine-grained access control:
57
+
58
+
```php
59
+
// Record operations
60
+
'repo:app.bsky.feed.post' // All operations on posts
61
+
'repo:app.bsky.feed.post?action=create' // Only create posts
62
+
'repo:app.bsky.feed.like?action=create&action=delete' // Create or delete likes
63
+
'repo:*' // All collections, all actions
64
+
65
+
// RPC endpoint access
66
+
'rpc:app.bsky.feed.getTimeline' // Access to timeline endpoint
67
+
'rpc:app.bsky.feed.*' // All feed endpoints
68
+
69
+
// Blob operations
70
+
'blob:image/*' // Upload images
71
+
'blob:*/*' // Upload any blob type
72
+
73
+
// Account and identity
74
+
'account:email' // Access email
75
+
'identity:handle' // Manage handle
76
+
```
77
+
78
+
## The ScopedEndpoint Attribute
79
+
80
+
The `#[ScopedEndpoint]` attribute documents scope requirements on methods that require authentication.
81
+
82
+
### Basic Usage
83
+
84
+
```php
85
+
<?php
86
+
87
+
namespace App\Atp;
88
+
89
+
use SocialDept\AtpClient\Attributes\ScopedEndpoint;
90
+
use SocialDept\AtpClient\Client\Requests\Request;
91
+
use SocialDept\AtpClient\Enums\Scope;
92
+
93
+
class CustomClient extends Request
94
+
{
95
+
#[ScopedEndpoint(Scope::TransitionGeneric)]
96
+
public function getTimeline(): array
97
+
{
98
+
return $this->atp->client->get('app.bsky.feed.getTimeline')->json();
99
+
}
100
+
}
101
+
```
102
+
103
+
### With Granular Scope
104
+
105
+
Document the future granular scope that will replace the transition scope:
106
+
107
+
```php
108
+
#[ScopedEndpoint(
109
+
Scope::TransitionGeneric,
110
+
granular: 'rpc:app.bsky.feed.getTimeline'
111
+
)]
112
+
public function getTimeline(): GetTimelineResponse
113
+
{
114
+
// ...
115
+
}
116
+
```
117
+
118
+
### With Description
119
+
120
+
Add a human-readable description for documentation:
121
+
122
+
```php
123
+
#[ScopedEndpoint(
124
+
Scope::TransitionGeneric,
125
+
granular: 'rpc:app.bsky.feed.getTimeline',
126
+
description: 'Access to the user\'s home timeline'
127
+
)]
128
+
public function getTimeline(): GetTimelineResponse
129
+
{
130
+
// ...
131
+
}
132
+
```
133
+
134
+
### Multiple Scopes (AND Logic)
135
+
136
+
When a method requires multiple scopes, all must be present:
137
+
138
+
```php
139
+
#[ScopedEndpoint([Scope::TransitionGeneric, Scope::TransitionEmail])]
140
+
public function getEmailPreferences(): array
141
+
{
142
+
// Requires BOTH scopes
143
+
}
144
+
```
145
+
146
+
### Multiple Attributes (OR Logic)
147
+
148
+
Use multiple attributes for alternative scope requirements:
149
+
150
+
```php
151
+
#[ScopedEndpoint(Scope::Atproto)]
152
+
#[ScopedEndpoint(Scope::TransitionGeneric)]
153
+
public function getProfile(string $actor): ProfileViewDetailed
154
+
{
155
+
// Either scope satisfies the requirement
156
+
}
157
+
```
158
+
159
+
## Scope Enforcement (Planned)
160
+
161
+
> **Coming Soon:** Runtime scope enforcement is not yet implemented. The following documentation describes planned functionality for a future release.
162
+
163
+
### Configuration
164
+
165
+
Configure scope enforcement in `config/client.php` or via environment variables:
166
+
167
+
```php
168
+
'scope_enforcement' => ScopeEnforcementLevel::Permissive,
169
+
```
170
+
171
+
| Level | Behavior |
172
+
|-------|----------|
173
+
| `Strict` | Throws `MissingScopeException` if required scopes are missing |
174
+
| `Permissive` | Logs a warning but attempts the request anyway |
175
+
176
+
Set via environment variable:
177
+
178
+
```env
179
+
ATP_SCOPE_ENFORCEMENT=strict
180
+
```
181
+
182
+
### Programmatic Scope Checking
183
+
184
+
Check scopes programmatically using the `ScopeChecker`:
185
+
186
+
```php
187
+
use SocialDept\AtpClient\Auth\ScopeChecker;
188
+
use SocialDept\AtpClient\Facades\Atp;
189
+
190
+
$checker = app(ScopeChecker::class);
191
+
$session = Atp::as($did)->client->session();
192
+
193
+
// Check if session has a scope
194
+
if ($checker->hasScope($session, Scope::TransitionGeneric)) {
195
+
// Session has the scope
196
+
}
197
+
198
+
// Check multiple scopes
199
+
if ($checker->check($session, [Scope::TransitionGeneric, Scope::TransitionEmail])) {
200
+
// Session has ALL required scopes
201
+
}
202
+
203
+
// Check and fail if missing (respects enforcement level)
204
+
$checker->checkOrFail($session, [Scope::TransitionGeneric]);
205
+
206
+
// Check repo scope for specific action
207
+
if ($checker->checkRepoScope($session, 'app.bsky.feed.post', 'create')) {
208
+
// Can create posts
209
+
}
210
+
```
211
+
212
+
### Granular Pattern Matching
213
+
214
+
The scope checker supports wildcard patterns:
215
+
216
+
```php
217
+
// Check if session can access any feed endpoint
218
+
$checker->matchesGranular($session, 'rpc:app.bsky.feed.*');
219
+
220
+
// Check if session can upload images
221
+
$checker->matchesGranular($session, 'blob:image/*');
222
+
223
+
// Check if session has any repo access
224
+
$checker->matchesGranular($session, 'repo:*');
225
+
```
226
+
227
+
## Route Middleware (Planned)
228
+
229
+
> **Coming Soon:** Route middleware is not yet implemented. The following documentation describes planned functionality for a future release.
230
+
231
+
Protect Laravel routes based on ATP session scopes:
232
+
233
+
```php
234
+
use Illuminate\Support\Facades\Route;
235
+
236
+
// Single scope
237
+
Route::get('/timeline', TimelineController::class)
238
+
->middleware('atp.scope:transition:generic');
239
+
240
+
// Multiple scopes (AND logic)
241
+
Route::get('/email-settings', EmailSettingsController::class)
242
+
->middleware('atp.scope:transition:generic,transition:email');
243
+
```
244
+
245
+
### Middleware Configuration
246
+
247
+
Configure middleware behavior in `config/client.php`:
248
+
249
+
```php
250
+
'scope_authorization' => [
251
+
// What to do when scope check fails
252
+
'failure_action' => ScopeAuthorizationFailure::Abort, // abort, redirect, or exception
253
+
254
+
// Where to redirect (when failure_action is 'redirect')
255
+
'redirect_to' => '/login',
256
+
],
257
+
```
258
+
259
+
| Failure Action | Behavior |
260
+
|----------------|----------|
261
+
| `Abort` | Returns 403 Forbidden response |
262
+
| `Redirect` | Redirects to configured URL |
263
+
| `Exception` | Throws `ScopeAuthorizationException` |
264
+
265
+
Set via environment variables:
266
+
267
+
```env
268
+
ATP_SCOPE_FAILURE_ACTION=redirect
269
+
ATP_SCOPE_REDIRECT=/auth/login
270
+
```
271
+
272
+
### User Model Integration
273
+
274
+
For the middleware to work, your User model must implement `HasAtpSession`:
275
+
276
+
```php
277
+
<?php
278
+
279
+
namespace App\Models;
280
+
281
+
use Illuminate\Foundation\Auth\User as Authenticatable;
282
+
use SocialDept\AtpClient\Contracts\HasAtpSession;
283
+
284
+
class User extends Authenticatable implements HasAtpSession
285
+
{
286
+
public function getAtpDid(): ?string
287
+
{
288
+
return $this->atp_did;
289
+
}
290
+
}
291
+
```
292
+
293
+
## Public Mode and Scopes
294
+
295
+
Methods marked with `#[PublicEndpoint]` can be called without authentication using `Atp::public()`:
296
+
297
+
```php
298
+
// Public mode - no authentication required
299
+
$client = Atp::public('https://public.api.bsky.app');
300
+
$client->bsky->actor->getProfile('someone.bsky.social'); // Works without auth
301
+
302
+
// Authenticated mode - for endpoints requiring scopes
303
+
$client = Atp::as($did);
304
+
$client->bsky->feed->getTimeline(); // Requires transition:generic scope
305
+
```
306
+
307
+
Methods with `#[PublicEndpoint]` work in both modes, while methods with `#[ScopedEndpoint]` require authentication.
308
+
309
+
## Exception Handling (Planned)
310
+
311
+
> **Coming Soon:** These exceptions will be thrown when scope enforcement is implemented in a future release.
312
+
313
+
### MissingScopeException
314
+
315
+
Will be thrown when required scopes are missing and enforcement is strict:
316
+
317
+
```php
318
+
use SocialDept\AtpClient\Exceptions\MissingScopeException;
319
+
320
+
try {
321
+
$timeline = $client->bsky->feed->getTimeline();
322
+
} catch (MissingScopeException $e) {
323
+
$missing = $e->getMissingScopes(); // Scopes that are missing
324
+
$granted = $e->getGrantedScopes(); // Scopes the session has
325
+
326
+
// Handle missing scope
327
+
}
328
+
```
329
+
330
+
### ScopeAuthorizationException
331
+
332
+
Will be thrown by middleware when route access is denied:
333
+
334
+
```php
335
+
use SocialDept\AtpClient\Exceptions\ScopeAuthorizationException;
336
+
337
+
try {
338
+
// Route protected by atp.scope middleware
339
+
} catch (ScopeAuthorizationException $e) {
340
+
$required = $e->getRequiredScopes();
341
+
$granted = $e->getGrantedScopes();
342
+
$message = $e->getMessage();
343
+
}
344
+
```
345
+
346
+
## Best Practices
347
+
348
+
### 1. Document All Scope Requirements
349
+
350
+
Always add `#[ScopedEndpoint]` to methods that require authentication:
351
+
352
+
```php
353
+
#[ScopedEndpoint(
354
+
Scope::TransitionGeneric,
355
+
granular: 'rpc:app.bsky.feed.getTimeline',
356
+
description: 'Fetches the authenticated user\'s home timeline'
357
+
)]
358
+
public function getTimeline(): GetTimelineResponse
359
+
```
360
+
361
+
### 2. Use the Scope Enum
362
+
363
+
Prefer the `Scope` enum over string literals for type safety:
364
+
365
+
```php
366
+
// Good
367
+
#[ScopedEndpoint(Scope::TransitionGeneric)]
368
+
369
+
// Avoid
370
+
#[ScopedEndpoint('transition:generic')]
371
+
```
372
+
373
+
### 3. Request Minimal Scopes
374
+
375
+
When implementing OAuth, request only the scopes your application needs:
376
+
377
+
```php
378
+
$authUrl = Atp::oauth()->getAuthorizationUrl([
379
+
'scope' => 'atproto transition:generic',
380
+
]);
381
+
```
382
+
383
+
### 4. Handle Missing Scopes Gracefully
384
+
385
+
Check for scope availability before attempting operations:
386
+
387
+
```php
388
+
$checker = app(ScopeChecker::class);
389
+
$session = $client->client->session();
390
+
391
+
if ($checker->hasScope($session, Scope::TransitionChat)) {
392
+
$conversations = $client->chat->getConversations();
393
+
} else {
394
+
// Inform user they need to re-authorize with chat scope
395
+
}
396
+
```
397
+
398
+
### 5. Use Permissive Mode in Development
399
+
400
+
Start with permissive enforcement during development, then switch to strict for production:
401
+
402
+
```env
403
+
# .env.local
404
+
ATP_SCOPE_ENFORCEMENT=permissive
405
+
406
+
# .env.production
407
+
ATP_SCOPE_ENFORCEMENT=strict
408
+
```
+43
src/Attributes/PublicEndpoint.php
+43
src/Attributes/PublicEndpoint.php
···
1
+
<?php
2
+
3
+
namespace SocialDept\AtpClient\Attributes;
4
+
5
+
use Attribute;
6
+
7
+
/**
8
+
* Documents that a method is a public endpoint that does not require authentication.
9
+
*
10
+
* This attribute currently serves as documentation to indicate which AT Protocol
11
+
* endpoints can be called without an authenticated session. It helps developers
12
+
* understand which endpoints work with `Atp::public()` against public API endpoints
13
+
* like `https://public.api.bsky.app`.
14
+
*
15
+
* While this attribute does not currently perform runtime enforcement, scope
16
+
* validation will be implemented in a future release. Correctly attributing
17
+
* endpoints now ensures forward compatibility when enforcement is enabled.
18
+
*
19
+
* Public endpoints typically include operations like:
20
+
* - Reading public profiles and posts
21
+
* - Searching actors and content
22
+
* - Resolving handles to DIDs
23
+
* - Accessing repository data (sync endpoints)
24
+
* - Describing servers and feed generators
25
+
*
26
+
* @example Basic usage
27
+
* ```php
28
+
* #[PublicEndpoint]
29
+
* public function getProfile(string $actor): ProfileViewDetailed
30
+
* ```
31
+
*
32
+
* @see \SocialDept\AtpClient\Attributes\ScopedEndpoint For endpoints that require authentication
33
+
*/
34
+
#[Attribute(Attribute::TARGET_METHOD)]
35
+
class PublicEndpoint
36
+
{
37
+
/**
38
+
* @param string $description Human-readable description of the endpoint
39
+
*/
40
+
public function __construct(
41
+
public readonly string $description = '',
42
+
) {}
43
+
}
-37
src/Attributes/RequiresScope.php
-37
src/Attributes/RequiresScope.php
···
1
-
<?php
2
-
3
-
namespace SocialDept\AtpClient\Attributes;
4
-
5
-
use Attribute;
6
-
use SocialDept\AtpClient\Enums\Scope;
7
-
8
-
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
9
-
class RequiresScope
10
-
{
11
-
public array $scopes;
12
-
13
-
/**
14
-
* @param string|Scope|array<string|Scope> $scopes Required scope(s) for this method
15
-
* @param string|null $granular Future granular scope equivalent
16
-
* @param string $description Human-readable description of scope requirement
17
-
*/
18
-
public function __construct(
19
-
string|Scope|array $scopes,
20
-
public readonly ?string $granular = null,
21
-
public readonly string $description = '',
22
-
) {
23
-
$this->scopes = $this->normalizeScopes($scopes);
24
-
}
25
-
26
-
protected function normalizeScopes(string|Scope|array $scopes): array
27
-
{
28
-
if (! is_array($scopes)) {
29
-
$scopes = [$scopes];
30
-
}
31
-
32
-
return array_map(
33
-
fn ($scope) => $scope instanceof Scope ? $scope->value : $scope,
34
-
$scopes
35
-
);
36
-
}
37
-
}
+67
src/Attributes/ScopedEndpoint.php
+67
src/Attributes/ScopedEndpoint.php
···
1
+
<?php
2
+
3
+
namespace SocialDept\AtpClient\Attributes;
4
+
5
+
use Attribute;
6
+
use SocialDept\AtpClient\Enums\Scope;
7
+
8
+
/**
9
+
* Documents that a method requires authentication with specific OAuth scopes.
10
+
*
11
+
* This attribute currently serves as documentation to indicate which AT Protocol
12
+
* endpoints require authentication and what scopes they need. It helps developers
13
+
* understand scope requirements when building applications.
14
+
*
15
+
* While this attribute does not currently perform runtime enforcement, scope
16
+
* validation will be implemented in a future release. Correctly attributing
17
+
* endpoints now ensures forward compatibility when enforcement is enabled.
18
+
*
19
+
* The AT Protocol currently uses "transition scopes" (like `transition:generic`) while
20
+
* moving toward more granular scopes. The `granular` parameter allows documenting the
21
+
* future granular scope that will replace the transition scope.
22
+
*
23
+
* @example Basic usage with a transition scope
24
+
* ```php
25
+
* #[ScopedEndpoint(Scope::TransitionGeneric)]
26
+
* public function getTimeline(): GetTimelineResponse
27
+
* ```
28
+
*
29
+
* @example With future granular scope documented
30
+
* ```php
31
+
* #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:app.bsky.feed.getTimeline')]
32
+
* public function getTimeline(): GetTimelineResponse
33
+
* ```
34
+
*
35
+
* @see \SocialDept\AtpClient\Attributes\PublicEndpoint For endpoints that don't require authentication
36
+
* @see \SocialDept\AtpClient\Enums\Scope For available scope values
37
+
*/
38
+
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
39
+
class ScopedEndpoint
40
+
{
41
+
public array $scopes;
42
+
43
+
/**
44
+
* @param string|Scope|array<string|Scope> $scopes Required scope(s) for this method
45
+
* @param string|null $granular Future granular scope equivalent
46
+
* @param string $description Human-readable description of scope requirement
47
+
*/
48
+
public function __construct(
49
+
string|Scope|array $scopes,
50
+
public readonly ?string $granular = null,
51
+
public readonly string $description = '',
52
+
) {
53
+
$this->scopes = $this->normalizeScopes($scopes);
54
+
}
55
+
56
+
protected function normalizeScopes(string|Scope|array $scopes): array
57
+
{
58
+
if (! is_array($scopes)) {
59
+
$scopes = [$scopes];
60
+
}
61
+
62
+
return array_map(
63
+
fn ($scope) => $scope instanceof Scope ? $scope->value : $scope,
64
+
$scopes
65
+
);
66
+
}
67
+
}
+197
src/Builders/Concerns/BuildsRichText.php
+197
src/Builders/Concerns/BuildsRichText.php
···
1
+
<?php
2
+
3
+
namespace SocialDept\AtpClient\Builders\Concerns;
4
+
5
+
use SocialDept\AtpClient\RichText\FacetDetector;
6
+
use SocialDept\AtpResolver\Facades\Resolver;
7
+
8
+
trait BuildsRichText
9
+
{
10
+
protected string $text = '';
11
+
12
+
protected array $facets = [];
13
+
14
+
/**
15
+
* Add plain text
16
+
*/
17
+
public function text(string $text): self
18
+
{
19
+
$this->text .= $text;
20
+
21
+
return $this;
22
+
}
23
+
24
+
/**
25
+
* Add one or more new lines
26
+
*/
27
+
public function newLine(int $count = 1): self
28
+
{
29
+
$this->text .= str_repeat("\n", $count);
30
+
31
+
return $this;
32
+
}
33
+
34
+
/**
35
+
* Add mention (@handle)
36
+
*/
37
+
public function mention(string $handle, ?string $did = null): self
38
+
{
39
+
$handle = ltrim($handle, '@');
40
+
$start = $this->getBytePosition();
41
+
$this->text .= '@'.$handle;
42
+
$end = $this->getBytePosition();
43
+
44
+
if (! $did) {
45
+
try {
46
+
$did = Resolver::handleToDid($handle);
47
+
} catch (\Exception $e) {
48
+
return $this;
49
+
}
50
+
}
51
+
52
+
$this->facets[] = [
53
+
'index' => [
54
+
'byteStart' => $start,
55
+
'byteEnd' => $end,
56
+
],
57
+
'features' => [
58
+
[
59
+
'$type' => 'app.bsky.richtext.facet#mention',
60
+
'did' => $did,
61
+
],
62
+
],
63
+
];
64
+
65
+
return $this;
66
+
}
67
+
68
+
/**
69
+
* Add link with custom display text
70
+
*/
71
+
public function link(string $text, string $uri): self
72
+
{
73
+
$start = $this->getBytePosition();
74
+
$this->text .= $text;
75
+
$end = $this->getBytePosition();
76
+
77
+
$this->facets[] = [
78
+
'index' => [
79
+
'byteStart' => $start,
80
+
'byteEnd' => $end,
81
+
],
82
+
'features' => [
83
+
[
84
+
'$type' => 'app.bsky.richtext.facet#link',
85
+
'uri' => $uri,
86
+
],
87
+
],
88
+
];
89
+
90
+
return $this;
91
+
}
92
+
93
+
/**
94
+
* Add a URL (displayed as-is)
95
+
*/
96
+
public function url(string $url): self
97
+
{
98
+
return $this->link($url, $url);
99
+
}
100
+
101
+
/**
102
+
* Add hashtag
103
+
*/
104
+
public function tag(string $tag): self
105
+
{
106
+
$tag = ltrim($tag, '#');
107
+
108
+
$start = $this->getBytePosition();
109
+
$this->text .= '#'.$tag;
110
+
$end = $this->getBytePosition();
111
+
112
+
$this->facets[] = [
113
+
'index' => [
114
+
'byteStart' => $start,
115
+
'byteEnd' => $end,
116
+
],
117
+
'features' => [
118
+
[
119
+
'$type' => 'app.bsky.richtext.facet#tag',
120
+
'tag' => $tag,
121
+
],
122
+
],
123
+
];
124
+
125
+
return $this;
126
+
}
127
+
128
+
/**
129
+
* Auto-detect and add facets from plain text
130
+
*/
131
+
public function autoDetect(string $text): self
132
+
{
133
+
$start = $this->getBytePosition();
134
+
$this->text .= $text;
135
+
136
+
$detected = FacetDetector::detect($text);
137
+
138
+
foreach ($detected as $facet) {
139
+
$facet['index']['byteStart'] += $start;
140
+
$facet['index']['byteEnd'] += $start;
141
+
$this->facets[] = $facet;
142
+
}
143
+
144
+
return $this;
145
+
}
146
+
147
+
/**
148
+
* Get current byte position (UTF-8 byte offset)
149
+
*/
150
+
protected function getBytePosition(): int
151
+
{
152
+
return strlen($this->text);
153
+
}
154
+
155
+
/**
156
+
* Get the text content
157
+
*/
158
+
public function getText(): string
159
+
{
160
+
return $this->text;
161
+
}
162
+
163
+
/**
164
+
* Get the facets
165
+
*/
166
+
public function getFacets(): array
167
+
{
168
+
return $this->facets;
169
+
}
170
+
171
+
/**
172
+
* Get text and facets as array
173
+
*/
174
+
protected function getTextAndFacets(): array
175
+
{
176
+
return [
177
+
'text' => $this->text,
178
+
'facets' => $this->facets,
179
+
];
180
+
}
181
+
182
+
/**
183
+
* Get grapheme count (closest to what AT Protocol uses for limits)
184
+
*/
185
+
public function getGraphemeCount(): int
186
+
{
187
+
return grapheme_strlen($this->text);
188
+
}
189
+
190
+
/**
191
+
* Check if text exceeds AT Protocol post limit (300 graphemes)
192
+
*/
193
+
public function exceedsLimit(int $limit = 300): bool
194
+
{
195
+
return $this->getGraphemeCount() > $limit;
196
+
}
197
+
}
+93
src/Builders/Embeds/ImagesBuilder.php
+93
src/Builders/Embeds/ImagesBuilder.php
···
1
+
<?php
2
+
3
+
namespace SocialDept\AtpClient\Builders\Embeds;
4
+
5
+
class ImagesBuilder
6
+
{
7
+
protected array $images = [];
8
+
9
+
/**
10
+
* Create a new images builder instance
11
+
*/
12
+
public static function make(): self
13
+
{
14
+
return new self;
15
+
}
16
+
17
+
/**
18
+
* Add an image to the embed
19
+
*
20
+
* @param mixed $blob BlobReference or blob array
21
+
* @param string $alt Alt text for the image
22
+
* @param array|null $aspectRatio [width, height] aspect ratio
23
+
*/
24
+
public function add(mixed $blob, string $alt, ?array $aspectRatio = null): self
25
+
{
26
+
$image = [
27
+
'image' => $this->normalizeBlob($blob),
28
+
'alt' => $alt,
29
+
];
30
+
31
+
if ($aspectRatio !== null) {
32
+
$image['aspectRatio'] = [
33
+
'width' => $aspectRatio[0],
34
+
'height' => $aspectRatio[1],
35
+
];
36
+
}
37
+
38
+
$this->images[] = $image;
39
+
40
+
return $this;
41
+
}
42
+
43
+
/**
44
+
* Get all images
45
+
*/
46
+
public function getImages(): array
47
+
{
48
+
return $this->images;
49
+
}
50
+
51
+
/**
52
+
* Check if builder has images
53
+
*/
54
+
public function hasImages(): bool
55
+
{
56
+
return ! empty($this->images);
57
+
}
58
+
59
+
/**
60
+
* Get the count of images
61
+
*/
62
+
public function count(): int
63
+
{
64
+
return count($this->images);
65
+
}
66
+
67
+
/**
68
+
* Convert to embed array format
69
+
*/
70
+
public function toArray(): array
71
+
{
72
+
return [
73
+
'$type' => 'app.bsky.embed.images',
74
+
'images' => $this->images,
75
+
];
76
+
}
77
+
78
+
/**
79
+
* Normalize blob to array format
80
+
*/
81
+
protected function normalizeBlob(mixed $blob): array
82
+
{
83
+
if (is_array($blob)) {
84
+
return $blob;
85
+
}
86
+
87
+
if (method_exists($blob, 'toArray')) {
88
+
return $blob->toArray();
89
+
}
90
+
91
+
return (array) $blob;
92
+
}
93
+
}
+257
src/Builders/PostBuilder.php
+257
src/Builders/PostBuilder.php
···
1
+
<?php
2
+
3
+
namespace SocialDept\AtpClient\Builders;
4
+
5
+
use Closure;
6
+
use DateTimeInterface;
7
+
use SocialDept\AtpClient\Builders\Concerns\BuildsRichText;
8
+
use SocialDept\AtpClient\Builders\Embeds\ImagesBuilder;
9
+
use SocialDept\AtpClient\Client\Records\PostRecordClient;
10
+
use SocialDept\AtpClient\Contracts\Recordable;
11
+
use SocialDept\AtpClient\Data\StrongRef;
12
+
use SocialDept\AtpClient\Enums\Nsid\BskyFeed;
13
+
14
+
class PostBuilder implements Recordable
15
+
{
16
+
use BuildsRichText;
17
+
18
+
protected ?array $embed = null;
19
+
20
+
protected ?array $reply = null;
21
+
22
+
protected ?array $langs = null;
23
+
24
+
protected ?DateTimeInterface $createdAt = null;
25
+
26
+
protected ?PostRecordClient $client = null;
27
+
28
+
/**
29
+
* Create a new post builder instance
30
+
*/
31
+
public static function make(): self
32
+
{
33
+
return new self;
34
+
}
35
+
36
+
/**
37
+
* Add images embed
38
+
*
39
+
* @param Closure|array $images Closure receiving ImagesBuilder, or array of image data
40
+
*/
41
+
public function images(Closure|array $images): self
42
+
{
43
+
if ($images instanceof Closure) {
44
+
$builder = ImagesBuilder::make();
45
+
$images($builder);
46
+
$this->embed = $builder->toArray();
47
+
} else {
48
+
$this->embed = [
49
+
'$type' => 'app.bsky.embed.images',
50
+
'images' => array_map(fn ($img) => $this->normalizeImageData($img), $images),
51
+
];
52
+
}
53
+
54
+
return $this;
55
+
}
56
+
57
+
/**
58
+
* Add external link embed (link card)
59
+
*
60
+
* @param string $uri URL of the external content
61
+
* @param string $title Title of the link card
62
+
* @param string $description Description text
63
+
* @param mixed|null $thumb Optional thumbnail blob
64
+
*/
65
+
public function external(string $uri, string $title, string $description, mixed $thumb = null): self
66
+
{
67
+
$external = [
68
+
'uri' => $uri,
69
+
'title' => $title,
70
+
'description' => $description,
71
+
];
72
+
73
+
if ($thumb !== null) {
74
+
$external['thumb'] = $this->normalizeBlob($thumb);
75
+
}
76
+
77
+
$this->embed = [
78
+
'$type' => 'app.bsky.embed.external',
79
+
'external' => $external,
80
+
];
81
+
82
+
return $this;
83
+
}
84
+
85
+
/**
86
+
* Add video embed
87
+
*
88
+
* @param mixed $blob Video blob reference
89
+
* @param string|null $alt Alt text for the video
90
+
* @param array|null $captions Optional captions array
91
+
*/
92
+
public function video(mixed $blob, ?string $alt = null, ?array $captions = null): self
93
+
{
94
+
$video = [
95
+
'$type' => 'app.bsky.embed.video',
96
+
'video' => $this->normalizeBlob($blob),
97
+
];
98
+
99
+
if ($alt !== null) {
100
+
$video['alt'] = $alt;
101
+
}
102
+
103
+
if ($captions !== null) {
104
+
$video['captions'] = $captions;
105
+
}
106
+
107
+
$this->embed = $video;
108
+
109
+
return $this;
110
+
}
111
+
112
+
/**
113
+
* Add quote embed (embed another post)
114
+
*/
115
+
public function quote(StrongRef $post): self
116
+
{
117
+
$this->embed = [
118
+
'$type' => 'app.bsky.embed.record',
119
+
'record' => $post->toArray(),
120
+
];
121
+
122
+
return $this;
123
+
}
124
+
125
+
/**
126
+
* Set as a reply to another post
127
+
*
128
+
* @param StrongRef $parent The post being replied to
129
+
* @param StrongRef|null $root The root post of the thread (defaults to parent if not provided)
130
+
*/
131
+
public function replyTo(StrongRef $parent, ?StrongRef $root = null): self
132
+
{
133
+
$this->reply = [
134
+
'parent' => $parent->toArray(),
135
+
'root' => ($root ?? $parent)->toArray(),
136
+
];
137
+
138
+
return $this;
139
+
}
140
+
141
+
/**
142
+
* Set the post languages
143
+
*
144
+
* @param array $langs Array of BCP-47 language codes
145
+
*/
146
+
public function langs(array $langs): self
147
+
{
148
+
$this->langs = $langs;
149
+
150
+
return $this;
151
+
}
152
+
153
+
/**
154
+
* Set the creation timestamp
155
+
*/
156
+
public function createdAt(DateTimeInterface $date): self
157
+
{
158
+
$this->createdAt = $date;
159
+
160
+
return $this;
161
+
}
162
+
163
+
/**
164
+
* Bind to a PostRecordClient for creating the post
165
+
*/
166
+
public function for(PostRecordClient $client): self
167
+
{
168
+
$this->client = $client;
169
+
170
+
return $this;
171
+
}
172
+
173
+
/**
174
+
* Create the post (requires client binding via for() or build())
175
+
*
176
+
* @throws \RuntimeException If no client is bound
177
+
*/
178
+
public function create(): StrongRef
179
+
{
180
+
if ($this->client === null) {
181
+
throw new \RuntimeException(
182
+
'No client bound. Use ->for($client) or create via $client->bsky->post->build()'
183
+
);
184
+
}
185
+
186
+
return $this->client->create($this);
187
+
}
188
+
189
+
/**
190
+
* Convert to array for XRPC (implements Recordable)
191
+
*/
192
+
public function toArray(): array
193
+
{
194
+
$record = $this->getTextAndFacets();
195
+
196
+
if ($this->embed !== null) {
197
+
$record['embed'] = $this->embed;
198
+
}
199
+
200
+
if ($this->reply !== null) {
201
+
$record['reply'] = $this->reply;
202
+
}
203
+
204
+
if ($this->langs !== null) {
205
+
$record['langs'] = $this->langs;
206
+
}
207
+
208
+
$record['createdAt'] = ($this->createdAt ?? now())->format('c');
209
+
$record['$type'] = $this->getType();
210
+
211
+
return $record;
212
+
}
213
+
214
+
/**
215
+
* Get the record type (implements Recordable)
216
+
*/
217
+
public function getType(): string
218
+
{
219
+
return BskyFeed::Post->value;
220
+
}
221
+
222
+
/**
223
+
* Normalize image data from array format
224
+
*/
225
+
protected function normalizeImageData(array $data): array
226
+
{
227
+
$image = [
228
+
'image' => $this->normalizeBlob($data['blob'] ?? $data['image']),
229
+
'alt' => $data['alt'] ?? '',
230
+
];
231
+
232
+
if (isset($data['aspectRatio'])) {
233
+
$ratio = $data['aspectRatio'];
234
+
$image['aspectRatio'] = is_array($ratio) && isset($ratio['width'])
235
+
? $ratio
236
+
: ['width' => $ratio[0], 'height' => $ratio[1]];
237
+
}
238
+
239
+
return $image;
240
+
}
241
+
242
+
/**
243
+
* Normalize blob to array format
244
+
*/
245
+
protected function normalizeBlob(mixed $blob): array
246
+
{
247
+
if (is_array($blob)) {
248
+
return $blob;
249
+
}
250
+
251
+
if (method_exists($blob, 'toArray')) {
252
+
return $blob->toArray();
253
+
}
254
+
255
+
return (array) $blob;
256
+
}
257
+
}
+15
-17
src/Client/Records/FollowRecordClient.php
+15
-17
src/Client/Records/FollowRecordClient.php
···
3
3
namespace SocialDept\AtpClient\Client\Records;
4
4
5
5
use DateTimeInterface;
6
-
use SocialDept\AtpClient\Attributes\RequiresScope;
6
+
use SocialDept\AtpClient\Attributes\ScopedEndpoint;
7
7
use SocialDept\AtpClient\Client\Requests\Request;
8
-
use SocialDept\AtpClient\Data\StrongRef;
8
+
use SocialDept\AtpClient\Data\Record;
9
+
use SocialDept\AtpClient\Data\Responses\Atproto\Repo\CreateRecordResponse;
10
+
use SocialDept\AtpClient\Data\Responses\Atproto\Repo\DeleteRecordResponse;
9
11
use SocialDept\AtpClient\Enums\Nsid\BskyGraph;
10
12
use SocialDept\AtpClient\Enums\Scope;
11
13
···
16
18
*
17
19
* @requires transition:generic OR (rpc:com.atproto.repo.createRecord AND repo:app.bsky.graph.follow?action=create)
18
20
*/
19
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.createRecord')]
20
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'repo:app.bsky.graph.follow?action=create')]
21
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.createRecord')]
22
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.graph.follow?action=create')]
21
23
public function create(
22
24
string $subject,
23
25
?DateTimeInterface $createdAt = null
24
-
): StrongRef {
26
+
): CreateRecordResponse {
25
27
$record = [
26
28
'$type' => BskyGraph::Follow->value,
27
29
'subject' => $subject, // DID
28
30
'createdAt' => ($createdAt ?? now())->format('c'),
29
31
];
30
32
31
-
$response = $this->atp->atproto->repo->createRecord(
32
-
repo: $this->atp->client->session()->did(),
33
+
return $this->atp->atproto->repo->createRecord(
33
34
collection: BskyGraph::Follow,
34
35
record: $record
35
36
);
36
-
37
-
return StrongRef::fromResponse($response->json());
38
37
}
39
38
40
39
/**
···
42
41
*
43
42
* @requires transition:generic OR (rpc:com.atproto.repo.deleteRecord AND repo:app.bsky.graph.follow?action=delete)
44
43
*/
45
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.deleteRecord')]
46
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'repo:app.bsky.graph.follow?action=delete')]
47
-
public function delete(string $rkey): void
44
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.deleteRecord')]
45
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.graph.follow?action=delete')]
46
+
public function delete(string $rkey): DeleteRecordResponse
48
47
{
49
-
$this->atp->atproto->repo->deleteRecord(
50
-
repo: $this->atp->client->session()->did(),
48
+
return $this->atp->atproto->repo->deleteRecord(
51
49
collection: BskyGraph::Follow,
52
50
rkey: $rkey
53
51
);
···
58
56
*
59
57
* @requires transition:generic (rpc:com.atproto.repo.getRecord)
60
58
*/
61
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.getRecord')]
62
-
public function get(string $rkey, ?string $cid = null): array
59
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.getRecord')]
60
+
public function get(string $rkey, ?string $cid = null): Record
63
61
{
64
62
$response = $this->atp->atproto->repo->getRecord(
65
63
repo: $this->atp->client->session()->did(),
···
68
66
cid: $cid
69
67
);
70
68
71
-
return $response->json('value');
69
+
return Record::fromArrayRaw($response->toArray());
72
70
}
73
71
}
+15
-16
src/Client/Records/LikeRecordClient.php
+15
-16
src/Client/Records/LikeRecordClient.php
···
3
3
namespace SocialDept\AtpClient\Client\Records;
4
4
5
5
use DateTimeInterface;
6
-
use SocialDept\AtpClient\Attributes\RequiresScope;
6
+
use SocialDept\AtpClient\Attributes\ScopedEndpoint;
7
7
use SocialDept\AtpClient\Client\Requests\Request;
8
+
use SocialDept\AtpClient\Data\Record;
9
+
use SocialDept\AtpClient\Data\Responses\Atproto\Repo\CreateRecordResponse;
10
+
use SocialDept\AtpClient\Data\Responses\Atproto\Repo\DeleteRecordResponse;
8
11
use SocialDept\AtpClient\Data\StrongRef;
9
12
use SocialDept\AtpClient\Enums\Nsid\BskyFeed;
10
13
use SocialDept\AtpClient\Enums\Scope;
···
16
19
*
17
20
* @requires transition:generic OR (rpc:com.atproto.repo.createRecord AND repo:app.bsky.feed.like?action=create)
18
21
*/
19
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.createRecord')]
20
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'repo:app.bsky.feed.like?action=create')]
22
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.createRecord')]
23
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.feed.like?action=create')]
21
24
public function create(
22
25
StrongRef $subject,
23
26
?DateTimeInterface $createdAt = null
24
-
): StrongRef {
27
+
): CreateRecordResponse {
25
28
$record = [
26
29
'$type' => BskyFeed::Like->value,
27
30
'subject' => $subject->toArray(),
28
31
'createdAt' => ($createdAt ?? now())->format('c'),
29
32
];
30
33
31
-
$response = $this->atp->atproto->repo->createRecord(
32
-
repo: $this->atp->client->session()->did(),
34
+
return $this->atp->atproto->repo->createRecord(
33
35
collection: BskyFeed::Like,
34
36
record: $record
35
37
);
36
-
37
-
return StrongRef::fromResponse($response->json());
38
38
}
39
39
40
40
/**
···
42
42
*
43
43
* @requires transition:generic OR (rpc:com.atproto.repo.deleteRecord AND repo:app.bsky.feed.like?action=delete)
44
44
*/
45
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.deleteRecord')]
46
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'repo:app.bsky.feed.like?action=delete')]
47
-
public function delete(string $rkey): void
45
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.deleteRecord')]
46
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.feed.like?action=delete')]
47
+
public function delete(string $rkey): DeleteRecordResponse
48
48
{
49
-
$this->atp->atproto->repo->deleteRecord(
50
-
repo: $this->atp->client->session()->did(),
49
+
return $this->atp->atproto->repo->deleteRecord(
51
50
collection: BskyFeed::Like,
52
51
rkey: $rkey
53
52
);
···
58
57
*
59
58
* @requires transition:generic (rpc:com.atproto.repo.getRecord)
60
59
*/
61
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.getRecord')]
62
-
public function get(string $rkey, ?string $cid = null): array
60
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.getRecord')]
61
+
public function get(string $rkey, ?string $cid = null): Record
63
62
{
64
63
$response = $this->atp->atproto->repo->getRecord(
65
64
repo: $this->atp->client->session()->did(),
···
68
67
cid: $cid
69
68
);
70
69
71
-
return $response->json('value');
70
+
return Record::fromArrayRaw($response->toArray());
72
71
}
73
72
}
+42
-159
src/Client/Records/PostRecordClient.php
+42
-159
src/Client/Records/PostRecordClient.php
···
3
3
namespace SocialDept\AtpClient\Client\Records;
4
4
5
5
use DateTimeInterface;
6
-
use SocialDept\AtpClient\Attributes\RequiresScope;
6
+
use SocialDept\AtpClient\Attributes\ScopedEndpoint;
7
+
use SocialDept\AtpClient\Builders\PostBuilder;
7
8
use SocialDept\AtpClient\Client\Requests\Request;
8
9
use SocialDept\AtpClient\Contracts\Recordable;
10
+
use SocialDept\AtpClient\Data\Record;
11
+
use SocialDept\AtpClient\Data\Responses\Atproto\Repo\CreateRecordResponse;
12
+
use SocialDept\AtpClient\Data\Responses\Atproto\Repo\DeleteRecordResponse;
13
+
use SocialDept\AtpClient\Data\Responses\Atproto\Repo\PutRecordResponse;
9
14
use SocialDept\AtpClient\Data\StrongRef;
10
15
use SocialDept\AtpClient\Enums\Nsid\BskyFeed;
11
16
use SocialDept\AtpClient\Enums\Scope;
12
17
use SocialDept\AtpClient\RichText\TextBuilder;
18
+
use SocialDept\AtpSchema\Generated\App\Bsky\Feed\Defs\PostView;
13
19
14
20
class PostRecordClient extends Request
15
21
{
16
22
/**
23
+
* Create a new post builder bound to this client
24
+
*/
25
+
public function build(): PostBuilder
26
+
{
27
+
return PostBuilder::make()->for($this);
28
+
}
29
+
30
+
/**
17
31
* Create a post
18
32
*
19
33
* @requires transition:generic OR (rpc:com.atproto.repo.createRecord AND repo:app.bsky.feed.post?action=create)
20
34
*/
21
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.createRecord')]
22
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'repo:app.bsky.feed.post?action=create')]
35
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.createRecord')]
36
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.feed.post?action=create')]
23
37
public function create(
24
38
string|array|Recordable $content,
25
39
?array $facets = null,
···
27
41
?array $reply = null,
28
42
?array $langs = null,
29
43
?DateTimeInterface $createdAt = null
30
-
): StrongRef {
44
+
): CreateRecordResponse {
31
45
// Handle different input types
32
46
if (is_string($content)) {
33
47
$record = [
···
40
54
$record = $content;
41
55
}
42
56
43
-
// Add optional fields
44
-
if ($embed) {
45
-
$record['embed'] = $embed;
57
+
// Add optional fields (only for non-Recordable inputs)
58
+
if (! ($content instanceof Recordable)) {
59
+
if ($embed) {
60
+
$record['embed'] = $embed;
61
+
}
62
+
if ($reply) {
63
+
$record['reply'] = $reply;
64
+
}
65
+
if ($langs) {
66
+
$record['langs'] = $langs;
67
+
}
46
68
}
47
-
if ($reply) {
48
-
$record['reply'] = $reply;
49
-
}
50
-
if ($langs) {
51
-
$record['langs'] = $langs;
52
-
}
69
+
53
70
if (! isset($record['createdAt'])) {
54
71
$record['createdAt'] = ($createdAt ?? now())->format('c');
55
72
}
···
59
76
$record['$type'] = BskyFeed::Post->value;
60
77
}
61
78
62
-
$response = $this->atp->atproto->repo->createRecord(
63
-
repo: $this->atp->client->session()->did(),
79
+
return $this->atp->atproto->repo->createRecord(
64
80
collection: BskyFeed::Post,
65
81
record: $record
66
82
);
67
-
68
-
return StrongRef::fromResponse($response->json());
69
83
}
70
84
71
85
/**
···
73
87
*
74
88
* @requires transition:generic OR (rpc:com.atproto.repo.putRecord AND repo:app.bsky.feed.post?action=update)
75
89
*/
76
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.putRecord')]
77
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'repo:app.bsky.feed.post?action=update')]
78
-
public function update(string $rkey, array $record): StrongRef
90
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.putRecord')]
91
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.feed.post?action=update')]
92
+
public function update(string $rkey, array $record): PutRecordResponse
79
93
{
80
94
// Ensure $type is set
81
95
if (! isset($record['$type'])) {
82
96
$record['$type'] = BskyFeed::Post->value;
83
97
}
84
98
85
-
$response = $this->atp->atproto->repo->putRecord(
86
-
repo: $this->atp->client->session()->did(),
99
+
return $this->atp->atproto->repo->putRecord(
87
100
collection: BskyFeed::Post,
88
101
rkey: $rkey,
89
102
record: $record
90
103
);
91
-
92
-
return StrongRef::fromResponse($response->json());
93
104
}
94
105
95
106
/**
···
97
108
*
98
109
* @requires transition:generic OR (rpc:com.atproto.repo.deleteRecord AND repo:app.bsky.feed.post?action=delete)
99
110
*/
100
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.deleteRecord')]
101
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'repo:app.bsky.feed.post?action=delete')]
102
-
public function delete(string $rkey): void
111
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.deleteRecord')]
112
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.feed.post?action=delete')]
113
+
public function delete(string $rkey): DeleteRecordResponse
103
114
{
104
-
$this->atp->atproto->repo->deleteRecord(
105
-
repo: $this->atp->client->session()->did(),
115
+
return $this->atp->atproto->repo->deleteRecord(
106
116
collection: BskyFeed::Post,
107
117
rkey: $rkey
108
118
);
···
113
123
*
114
124
* @requires transition:generic (rpc:com.atproto.repo.getRecord)
115
125
*/
116
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.getRecord')]
117
-
public function get(string $rkey, ?string $cid = null): array
126
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.getRecord')]
127
+
public function get(string $rkey, ?string $cid = null): Record
118
128
{
119
129
$response = $this->atp->atproto->repo->getRecord(
120
130
repo: $this->atp->client->session()->did(),
···
123
133
cid: $cid
124
134
);
125
135
126
-
return $response->json('value');
136
+
return Record::fromArrayRaw($response->toArray());
127
137
}
128
138
129
-
/**
130
-
* Create a reply to another post
131
-
*
132
-
* @requires transition:generic OR (rpc:com.atproto.repo.createRecord AND repo:app.bsky.feed.post?action=create)
133
-
*/
134
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.createRecord')]
135
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'repo:app.bsky.feed.post?action=create')]
136
-
public function reply(
137
-
StrongRef $parent,
138
-
StrongRef $root,
139
-
string|array|Recordable $content,
140
-
?array $facets = null,
141
-
?array $embed = null,
142
-
?array $langs = null,
143
-
?DateTimeInterface $createdAt = null
144
-
): StrongRef {
145
-
$reply = [
146
-
'parent' => $parent->toArray(),
147
-
'root' => $root->toArray(),
148
-
];
149
-
150
-
return $this->create(
151
-
content: $content,
152
-
facets: $facets,
153
-
embed: $embed,
154
-
reply: $reply,
155
-
langs: $langs,
156
-
createdAt: $createdAt
157
-
);
158
-
}
159
-
160
-
/**
161
-
* Create a quote post (post with embedded post)
162
-
*
163
-
* @requires transition:generic OR (rpc:com.atproto.repo.createRecord AND repo:app.bsky.feed.post?action=create)
164
-
*/
165
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.createRecord')]
166
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'repo:app.bsky.feed.post?action=create')]
167
-
public function quote(
168
-
StrongRef $quotedPost,
169
-
string|array|Recordable $content,
170
-
?array $facets = null,
171
-
?array $langs = null,
172
-
?DateTimeInterface $createdAt = null
173
-
): StrongRef {
174
-
$embed = [
175
-
'$type' => 'app.bsky.embed.record',
176
-
'record' => $quotedPost->toArray(),
177
-
];
178
-
179
-
return $this->create(
180
-
content: $content,
181
-
facets: $facets,
182
-
embed: $embed,
183
-
langs: $langs,
184
-
createdAt: $createdAt
185
-
);
186
-
}
187
-
188
-
/**
189
-
* Create a post with images
190
-
*
191
-
* @requires transition:generic OR (rpc:com.atproto.repo.createRecord AND repo:app.bsky.feed.post?action=create)
192
-
*/
193
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.createRecord')]
194
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'repo:app.bsky.feed.post?action=create')]
195
-
public function withImages(
196
-
string|array|Recordable $content,
197
-
array $images,
198
-
?array $facets = null,
199
-
?array $langs = null,
200
-
?DateTimeInterface $createdAt = null
201
-
): StrongRef {
202
-
$embed = [
203
-
'$type' => 'app.bsky.embed.images',
204
-
'images' => $images,
205
-
];
206
-
207
-
return $this->create(
208
-
content: $content,
209
-
facets: $facets,
210
-
embed: $embed,
211
-
langs: $langs,
212
-
createdAt: $createdAt
213
-
);
214
-
}
215
-
216
-
/**
217
-
* Create a post with external link embed
218
-
*
219
-
* @requires transition:generic OR (rpc:com.atproto.repo.createRecord AND repo:app.bsky.feed.post?action=create)
220
-
*/
221
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.createRecord')]
222
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'repo:app.bsky.feed.post?action=create')]
223
-
public function withLink(
224
-
string|array|Recordable $content,
225
-
string $uri,
226
-
string $title,
227
-
string $description,
228
-
?string $thumbBlob = null,
229
-
?array $facets = null,
230
-
?array $langs = null,
231
-
?DateTimeInterface $createdAt = null
232
-
): StrongRef {
233
-
$external = [
234
-
'uri' => $uri,
235
-
'title' => $title,
236
-
'description' => $description,
237
-
];
238
-
239
-
if ($thumbBlob) {
240
-
$external['thumb'] = $thumbBlob;
241
-
}
242
-
243
-
$embed = [
244
-
'$type' => 'app.bsky.embed.external',
245
-
'external' => $external,
246
-
];
247
-
248
-
return $this->create(
249
-
content: $content,
250
-
facets: $facets,
251
-
embed: $embed,
252
-
langs: $langs,
253
-
createdAt: $createdAt
254
-
);
255
-
}
256
139
}
+23
-25
src/Client/Records/ProfileRecordClient.php
+23
-25
src/Client/Records/ProfileRecordClient.php
···
2
2
3
3
namespace SocialDept\AtpClient\Client\Records;
4
4
5
-
use SocialDept\AtpClient\Attributes\RequiresScope;
5
+
use SocialDept\AtpClient\Attributes\ScopedEndpoint;
6
6
use SocialDept\AtpClient\Client\Requests\Request;
7
-
use SocialDept\AtpClient\Data\StrongRef;
7
+
use SocialDept\AtpClient\Data\Record;
8
+
use SocialDept\AtpClient\Data\Responses\Atproto\Repo\PutRecordResponse;
8
9
use SocialDept\AtpClient\Enums\Nsid\BskyActor;
9
10
use SocialDept\AtpClient\Enums\Scope;
10
11
···
15
16
*
16
17
* @requires transition:generic OR (rpc:com.atproto.repo.putRecord AND repo:app.bsky.actor.profile?action=update)
17
18
*/
18
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.putRecord')]
19
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'repo:app.bsky.actor.profile?action=update')]
20
-
public function update(array $profile): StrongRef
19
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.putRecord')]
20
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.actor.profile?action=update')]
21
+
public function update(array $profile): PutRecordResponse
21
22
{
22
23
// Ensure $type is set
23
24
if (! isset($profile['$type'])) {
24
25
$profile['$type'] = BskyActor::Profile->value;
25
26
}
26
27
27
-
$response = $this->atp->atproto->repo->putRecord(
28
-
repo: $this->atp->client->session()->did(),
28
+
return $this->atp->atproto->repo->putRecord(
29
29
collection: BskyActor::Profile,
30
30
rkey: 'self', // Profile records always use 'self' as rkey
31
31
record: $profile
32
32
);
33
-
34
-
return StrongRef::fromResponse($response->json());
35
33
}
36
34
37
35
/**
···
39
37
*
40
38
* @requires transition:generic (rpc:com.atproto.repo.getRecord)
41
39
*/
42
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.getRecord')]
43
-
public function get(): array
40
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.getRecord')]
41
+
public function get(): Record
44
42
{
45
43
$response = $this->atp->atproto->repo->getRecord(
46
44
repo: $this->atp->client->session()->did(),
···
48
46
rkey: 'self'
49
47
);
50
48
51
-
return $response->json('value');
49
+
return Record::fromArrayRaw($response->toArray());
52
50
}
53
51
54
52
/**
···
56
54
*
57
55
* @requires transition:generic OR (rpc:com.atproto.repo.putRecord AND repo:app.bsky.actor.profile?action=update)
58
56
*/
59
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.putRecord')]
60
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'repo:app.bsky.actor.profile?action=update')]
61
-
public function updateDisplayName(string $displayName): StrongRef
57
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.putRecord')]
58
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.actor.profile?action=update')]
59
+
public function updateDisplayName(string $displayName): PutRecordResponse
62
60
{
63
61
$profile = $this->getOrCreateProfile();
64
62
$profile['displayName'] = $displayName;
···
71
69
*
72
70
* @requires transition:generic OR (rpc:com.atproto.repo.putRecord AND repo:app.bsky.actor.profile?action=update)
73
71
*/
74
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.putRecord')]
75
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'repo:app.bsky.actor.profile?action=update')]
76
-
public function updateDescription(string $description): StrongRef
72
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.putRecord')]
73
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.actor.profile?action=update')]
74
+
public function updateDescription(string $description): PutRecordResponse
77
75
{
78
76
$profile = $this->getOrCreateProfile();
79
77
$profile['description'] = $description;
···
86
84
*
87
85
* @requires transition:generic OR (rpc:com.atproto.repo.putRecord AND repo:app.bsky.actor.profile?action=update)
88
86
*/
89
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.putRecord')]
90
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'repo:app.bsky.actor.profile?action=update')]
91
-
public function updateAvatar(array $avatarBlob): StrongRef
87
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.putRecord')]
88
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.actor.profile?action=update')]
89
+
public function updateAvatar(array $avatarBlob): PutRecordResponse
92
90
{
93
91
$profile = $this->getOrCreateProfile();
94
92
$profile['avatar'] = $avatarBlob;
···
101
99
*
102
100
* @requires transition:generic OR (rpc:com.atproto.repo.putRecord AND repo:app.bsky.actor.profile?action=update)
103
101
*/
104
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.putRecord')]
105
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'repo:app.bsky.actor.profile?action=update')]
106
-
public function updateBanner(array $bannerBlob): StrongRef
102
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.putRecord')]
103
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'repo:app.bsky.actor.profile?action=update')]
104
+
public function updateBanner(array $bannerBlob): PutRecordResponse
107
105
{
108
106
$profile = $this->getOrCreateProfile();
109
107
$profile['banner'] = $bannerBlob;
···
117
115
protected function getOrCreateProfile(): array
118
116
{
119
117
try {
120
-
return $this->get();
118
+
return $this->get()->value;
121
119
} catch (\Exception $e) {
122
120
// Profile doesn't exist, return empty structure
123
121
return [
+11
-8
src/Client/Requests/Atproto/IdentityRequestClient.php
+11
-8
src/Client/Requests/Atproto/IdentityRequestClient.php
···
2
2
3
3
namespace SocialDept\AtpClient\Client\Requests\Atproto;
4
4
5
-
use SocialDept\AtpClient\Attributes\RequiresScope;
5
+
use SocialDept\AtpClient\Attributes\PublicEndpoint;
6
+
use SocialDept\AtpClient\Attributes\ScopedEndpoint;
6
7
use SocialDept\AtpClient\Client\Requests\Request;
8
+
use SocialDept\AtpClient\Data\Responses\Atproto\Identity\ResolveHandleResponse;
9
+
use SocialDept\AtpClient\Data\Responses\EmptyResponse;
7
10
use SocialDept\AtpClient\Enums\Nsid\AtprotoIdentity;
8
11
use SocialDept\AtpClient\Enums\Scope;
9
12
···
12
15
/**
13
16
* Resolve handle to DID
14
17
*
15
-
* @requires transition:generic (rpc:com.atproto.identity.resolveHandle)
16
-
*
17
18
* @see https://docs.bsky.app/docs/api/com-atproto-identity-resolve-handle
18
19
*/
19
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.identity.resolveHandle')]
20
-
public function resolveHandle(string $handle): string
20
+
#[PublicEndpoint]
21
+
public function resolveHandle(string $handle): ResolveHandleResponse
21
22
{
22
23
$response = $this->atp->client->get(
23
24
endpoint: AtprotoIdentity::ResolveHandle,
24
25
params: compact('handle')
25
26
);
26
27
27
-
return $response->json()['did'];
28
+
return ResolveHandleResponse::fromArray($response->json());
28
29
}
29
30
30
31
/**
···
34
35
*
35
36
* @see https://docs.bsky.app/docs/api/com-atproto-identity-update-handle
36
37
*/
37
-
#[RequiresScope(Scope::Atproto, granular: 'identity:handle')]
38
-
public function updateHandle(string $handle): void
38
+
#[ScopedEndpoint(Scope::Atproto, granular: 'identity:handle')]
39
+
public function updateHandle(string $handle): EmptyResponse
39
40
{
40
41
$this->atp->client->post(
41
42
endpoint: AtprotoIdentity::UpdateHandle,
42
43
body: compact('handle')
43
44
);
45
+
46
+
return new EmptyResponse;
44
47
}
45
48
}
+12
-17
src/Client/Requests/Atproto/RepoRequestClient.php
+12
-17
src/Client/Requests/Atproto/RepoRequestClient.php
···
5
5
use BackedEnum;
6
6
use Illuminate\Http\UploadedFile;
7
7
use InvalidArgumentException;
8
-
use SocialDept\AtpClient\Attributes\RequiresScope;
8
+
use SocialDept\AtpClient\Attributes\PublicEndpoint;
9
+
use SocialDept\AtpClient\Attributes\ScopedEndpoint;
9
10
use SocialDept\AtpClient\Auth\ScopeChecker;
10
11
use SocialDept\AtpClient\Client\Requests\Request;
11
12
use SocialDept\AtpClient\Data\Responses\Atproto\Repo\CreateRecordResponse;
···
29
30
*
30
31
* @see https://docs.bsky.app/docs/api/com-atproto-repo-create-record
31
32
*/
32
-
#[RequiresScope(Scope::TransitionGeneric, description: 'Create records in repository')]
33
+
#[ScopedEndpoint(Scope::TransitionGeneric, description: 'Create records in repository')]
33
34
public function createRecord(
34
-
string $repo,
35
35
string|BackedEnum $collection,
36
36
array $record,
37
37
?string $rkey = null,
38
38
bool $validate = true,
39
39
?string $swapCommit = null
40
40
): CreateRecordResponse {
41
+
$repo = $this->atp->client->session()->did();
41
42
$collection = $collection instanceof BackedEnum ? $collection->value : $collection;
42
43
$this->checkCollectionScope($collection, 'create');
43
44
···
59
60
*
60
61
* @see https://docs.bsky.app/docs/api/com-atproto-repo-delete-record
61
62
*/
62
-
#[RequiresScope(Scope::TransitionGeneric, description: 'Delete records from repository')]
63
+
#[ScopedEndpoint(Scope::TransitionGeneric, description: 'Delete records from repository')]
63
64
public function deleteRecord(
64
-
string $repo,
65
65
string|BackedEnum $collection,
66
66
string $rkey,
67
67
?string $swapRecord = null,
68
68
?string $swapCommit = null
69
69
): DeleteRecordResponse {
70
+
$repo = $this->atp->client->session()->did();
70
71
$collection = $collection instanceof BackedEnum ? $collection->value : $collection;
71
72
$this->checkCollectionScope($collection, 'delete');
72
73
···
88
89
*
89
90
* @see https://docs.bsky.app/docs/api/com-atproto-repo-put-record
90
91
*/
91
-
#[RequiresScope(Scope::TransitionGeneric, description: 'Update records in repository')]
92
+
#[ScopedEndpoint(Scope::TransitionGeneric, description: 'Update records in repository')]
92
93
public function putRecord(
93
-
string $repo,
94
94
string|BackedEnum $collection,
95
95
string $rkey,
96
96
array $record,
···
98
98
?string $swapRecord = null,
99
99
?string $swapCommit = null
100
100
): PutRecordResponse {
101
+
$repo = $this->atp->client->session()->did();
101
102
$collection = $collection instanceof BackedEnum ? $collection->value : $collection;
102
103
$this->checkCollectionScope($collection, 'update');
103
104
···
115
116
/**
116
117
* Get a record
117
118
*
118
-
* @requires transition:generic (rpc:com.atproto.repo.getRecord)
119
-
*
120
119
* @see https://docs.bsky.app/docs/api/com-atproto-repo-get-record
121
120
*/
122
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.getRecord')]
121
+
#[PublicEndpoint]
123
122
public function getRecord(
124
123
string $repo,
125
124
string|BackedEnum $collection,
···
138
137
/**
139
138
* List records in a collection
140
139
*
141
-
* @requires transition:generic (rpc:com.atproto.repo.listRecords)
142
-
*
143
140
* @see https://docs.bsky.app/docs/api/com-atproto-repo-list-records
144
141
*/
145
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.listRecords')]
142
+
#[PublicEndpoint]
146
143
public function listRecords(
147
144
string $repo,
148
145
string|BackedEnum $collection,
···
173
170
*
174
171
* @see https://docs.bsky.app/docs/api/com-atproto-repo-upload-blob
175
172
*/
176
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'blob:*/*')]
173
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'blob:*/*')]
177
174
public function uploadBlob(UploadedFile|SplFileInfo|string $file, ?string $mimeType = null): BlobReference
178
175
{
179
176
// Handle different input types
···
200
197
/**
201
198
* Describe the repository
202
199
*
203
-
* @requires transition:generic (rpc:com.atproto.repo.describeRepo)
204
-
*
205
200
* @see https://docs.bsky.app/docs/api/com-atproto-repo-describe-repo
206
201
*/
207
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.describeRepo')]
202
+
#[PublicEndpoint]
208
203
public function describeRepo(string $repo): DescribeRepoResponse
209
204
{
210
205
$response = $this->atp->client->get(
+4
-5
src/Client/Requests/Atproto/ServerRequestClient.php
+4
-5
src/Client/Requests/Atproto/ServerRequestClient.php
···
2
2
3
3
namespace SocialDept\AtpClient\Client\Requests\Atproto;
4
4
5
-
use SocialDept\AtpClient\Attributes\RequiresScope;
5
+
use SocialDept\AtpClient\Attributes\PublicEndpoint;
6
+
use SocialDept\AtpClient\Attributes\ScopedEndpoint;
6
7
use SocialDept\AtpClient\Client\Requests\Request;
7
8
use SocialDept\AtpClient\Data\Responses\Atproto\Server\DescribeServerResponse;
8
9
use SocialDept\AtpClient\Data\Responses\Atproto\Server\GetSessionResponse;
···
18
19
*
19
20
* @see https://docs.bsky.app/docs/api/com-atproto-server-get-session
20
21
*/
21
-
#[RequiresScope(Scope::Atproto, granular: 'rpc:com.atproto.server.getSession')]
22
+
#[ScopedEndpoint(Scope::Atproto, granular: 'rpc:com.atproto.server.getSession')]
22
23
public function getSession(): GetSessionResponse
23
24
{
24
25
$response = $this->atp->client->get(
···
31
32
/**
32
33
* Describe server
33
34
*
34
-
* @requires atproto (rpc:com.atproto.server.describeServer)
35
-
*
36
35
* @see https://docs.bsky.app/docs/api/com-atproto-server-describe-server
37
36
*/
38
-
#[RequiresScope(Scope::Atproto, granular: 'rpc:com.atproto.server.describeServer')]
37
+
#[PublicEndpoint]
39
38
public function describeServer(): DescribeServerResponse
40
39
{
41
40
$response = $this->atp->client->get(
+31
-26
src/Client/Requests/Atproto/SyncRequestClient.php
+31
-26
src/Client/Requests/Atproto/SyncRequestClient.php
···
3
3
namespace SocialDept\AtpClient\Client\Requests\Atproto;
4
4
5
5
use BackedEnum;
6
-
use SocialDept\AtpClient\Attributes\RequiresScope;
6
+
use SocialDept\AtpClient\Attributes\PublicEndpoint;
7
7
use SocialDept\AtpClient\Client\Requests\Request;
8
8
use SocialDept\AtpClient\Data\Responses\Atproto\Sync\GetRepoStatusResponse;
9
9
use SocialDept\AtpClient\Data\Responses\Atproto\Sync\ListBlobsResponse;
10
+
use SocialDept\AtpClient\Data\Responses\Atproto\Sync\ListReposByCollectionResponse;
10
11
use SocialDept\AtpClient\Data\Responses\Atproto\Sync\ListReposResponse;
11
12
use SocialDept\AtpClient\Enums\Nsid\AtprotoSync;
12
-
use SocialDept\AtpClient\Enums\Scope;
13
13
use SocialDept\AtpClient\Http\Response;
14
14
use SocialDept\AtpSchema\Generated\Com\Atproto\Repo\Defs\CommitMeta;
15
15
···
18
18
/**
19
19
* Get a blob associated with a given account
20
20
*
21
-
* @requires atproto (rpc:com.atproto.sync.getBlob)
22
-
*
23
21
* @see https://docs.bsky.app/docs/api/com-atproto-sync-get-blob
24
22
*/
25
-
#[RequiresScope(Scope::Atproto, granular: 'rpc:com.atproto.sync.getBlob')]
23
+
#[PublicEndpoint]
26
24
public function getBlob(string $did, string $cid): Response
27
25
{
28
26
return $this->atp->client->get(
···
34
32
/**
35
33
* Download a repository export as CAR file
36
34
*
37
-
* @requires atproto (rpc:com.atproto.sync.getRepo)
38
-
*
39
35
* @see https://docs.bsky.app/docs/api/com-atproto-sync-get-repo
40
36
*/
41
-
#[RequiresScope(Scope::Atproto, granular: 'rpc:com.atproto.sync.getRepo')]
37
+
#[PublicEndpoint]
42
38
public function getRepo(string $did, ?string $since = null): Response
43
39
{
44
40
return $this->atp->client->get(
···
50
46
/**
51
47
* Enumerates all the DID, rev, and commit CID for all repos hosted by this service
52
48
*
53
-
* @requires atproto (rpc:com.atproto.sync.listRepos)
54
-
*
55
49
* @see https://docs.bsky.app/docs/api/com-atproto-sync-list-repos
56
50
*/
57
-
#[RequiresScope(Scope::Atproto, granular: 'rpc:com.atproto.sync.listRepos')]
51
+
#[PublicEndpoint]
58
52
public function listRepos(int $limit = 500, ?string $cursor = null): ListReposResponse
59
53
{
60
54
$response = $this->atp->client->get(
···
66
60
}
67
61
68
62
/**
63
+
* Enumerates all the DIDs with records in a specific collection
64
+
*
65
+
* @see https://docs.bsky.app/docs/api/com-atproto-sync-list-repos-by-collection
66
+
*/
67
+
#[PublicEndpoint]
68
+
public function listReposByCollection(
69
+
string|BackedEnum $collection,
70
+
int $limit = 500,
71
+
?string $cursor = null
72
+
): ListReposByCollectionResponse {
73
+
$collection = $collection instanceof BackedEnum ? $collection->value : $collection;
74
+
75
+
$response = $this->atp->client->get(
76
+
endpoint: AtprotoSync::ListReposByCollection,
77
+
params: compact('collection', 'limit', 'cursor')
78
+
);
79
+
80
+
return ListReposByCollectionResponse::fromArray($response->json());
81
+
}
82
+
83
+
/**
69
84
* Get the current commit CID & revision of the specified repo
70
-
*
71
-
* @requires atproto (rpc:com.atproto.sync.getLatestCommit)
72
85
*
73
86
* @see https://docs.bsky.app/docs/api/com-atproto-sync-get-latest-commit
74
87
*/
75
-
#[RequiresScope(Scope::Atproto, granular: 'rpc:com.atproto.sync.getLatestCommit')]
88
+
#[PublicEndpoint]
76
89
public function getLatestCommit(string $did): CommitMeta
77
90
{
78
91
$response = $this->atp->client->get(
···
85
98
86
99
/**
87
100
* Get data blocks needed to prove the existence or non-existence of record
88
-
*
89
-
* @requires atproto (rpc:com.atproto.sync.getRecord)
90
101
*
91
102
* @see https://docs.bsky.app/docs/api/com-atproto-sync-get-record
92
103
*/
93
-
#[RequiresScope(Scope::Atproto, granular: 'rpc:com.atproto.sync.getRecord')]
104
+
#[PublicEndpoint]
94
105
public function getRecord(string $did, string|BackedEnum $collection, string $rkey): Response
95
106
{
96
107
$collection = $collection instanceof BackedEnum ? $collection->value : $collection;
···
103
114
104
115
/**
105
116
* List blob CIDs for an account, since some repo revision
106
-
*
107
-
* @requires atproto (rpc:com.atproto.sync.listBlobs)
108
117
*
109
118
* @see https://docs.bsky.app/docs/api/com-atproto-sync-list-blobs
110
119
*/
111
-
#[RequiresScope(Scope::Atproto, granular: 'rpc:com.atproto.sync.listBlobs')]
120
+
#[PublicEndpoint]
112
121
public function listBlobs(
113
122
string $did,
114
123
?string $since = null,
···
126
135
/**
127
136
* Get data blocks from a given repo, by CID
128
137
*
129
-
* @requires atproto (rpc:com.atproto.sync.getBlocks)
130
-
*
131
138
* @see https://docs.bsky.app/docs/api/com-atproto-sync-get-blocks
132
139
*/
133
-
#[RequiresScope(Scope::Atproto, granular: 'rpc:com.atproto.sync.getBlocks')]
140
+
#[PublicEndpoint]
134
141
public function getBlocks(string $did, array $cids): Response
135
142
{
136
143
return $this->atp->client->get(
···
142
149
/**
143
150
* Get the hosting status for a repository, on this server
144
151
*
145
-
* @requires atproto (rpc:com.atproto.sync.getRepoStatus)
146
-
*
147
152
* @see https://docs.bsky.app/docs/api/com-atproto-sync-get-repo-status
148
153
*/
149
-
#[RequiresScope(Scope::Atproto, granular: 'rpc:com.atproto.sync.getRepoStatus')]
154
+
#[PublicEndpoint]
150
155
public function getRepoStatus(string $did): GetRepoStatusResponse
151
156
{
152
157
$response = $this->atp->client->get(
+7
-1
src/Client/Requests/Bsky/ActorRequestClient.php
+7
-1
src/Client/Requests/Bsky/ActorRequestClient.php
···
2
2
3
3
namespace SocialDept\AtpClient\Client\Requests\Bsky;
4
4
5
+
use SocialDept\AtpClient\Attributes\PublicEndpoint;
5
6
use SocialDept\AtpClient\Client\Requests\Request;
6
7
use SocialDept\AtpClient\Data\Responses\Bsky\Actor\GetProfilesResponse;
7
8
use SocialDept\AtpClient\Data\Responses\Bsky\Actor\GetSuggestionsResponse;
···
17
18
*
18
19
* @see https://docs.bsky.app/docs/api/app-bsky-actor-get-profile
19
20
*/
21
+
#[PublicEndpoint]
20
22
public function getProfile(string $actor): ProfileViewDetailed
21
23
{
22
24
$response = $this->atp->client->get(
···
24
26
params: compact('actor')
25
27
);
26
28
27
-
return ProfileViewDetailed::fromArray($response->json());
29
+
return ProfileViewDetailed::fromArray($response->toArray());
28
30
}
29
31
30
32
/**
···
32
34
*
33
35
* @see https://docs.bsky.app/docs/api/app-bsky-actor-get-profiles
34
36
*/
37
+
#[PublicEndpoint]
35
38
public function getProfiles(array $actors): GetProfilesResponse
36
39
{
37
40
$response = $this->atp->client->get(
···
47
50
*
48
51
* @see https://docs.bsky.app/docs/api/app-bsky-actor-get-suggestions
49
52
*/
53
+
#[PublicEndpoint]
50
54
public function getSuggestions(int $limit = 50, ?string $cursor = null): GetSuggestionsResponse
51
55
{
52
56
$response = $this->atp->client->get(
···
62
66
*
63
67
* @see https://docs.bsky.app/docs/api/app-bsky-actor-search-actors
64
68
*/
69
+
#[PublicEndpoint]
65
70
public function searchActors(string $q, int $limit = 25, ?string $cursor = null): SearchActorsResponse
66
71
{
67
72
$response = $this->atp->client->get(
···
77
82
*
78
83
* @see https://docs.bsky.app/docs/api/app-bsky-actor-search-actors-typeahead
79
84
*/
85
+
#[PublicEndpoint]
80
86
public function searchActorsTypeahead(string $q, int $limit = 10): SearchActorsTypeaheadResponse
81
87
{
82
88
$response = $this->atp->client->get(
+17
-2
src/Client/Requests/Bsky/FeedRequestClient.php
+17
-2
src/Client/Requests/Bsky/FeedRequestClient.php
···
2
2
3
3
namespace SocialDept\AtpClient\Client\Requests\Bsky;
4
4
5
-
use SocialDept\AtpClient\Attributes\RequiresScope;
5
+
use SocialDept\AtpClient\Attributes\PublicEndpoint;
6
+
use SocialDept\AtpClient\Attributes\ScopedEndpoint;
6
7
use SocialDept\AtpClient\Client\Requests\Request;
7
8
use SocialDept\AtpClient\Data\Responses\Bsky\Feed\DescribeFeedGeneratorResponse;
8
9
use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetActorFeedsResponse;
···
29
30
*
30
31
* @see https://docs.bsky.app/docs/api/app-bsky-feed-describe-feed-generator
31
32
*/
33
+
#[PublicEndpoint]
32
34
public function describeFeedGenerator(): DescribeFeedGeneratorResponse
33
35
{
34
36
$response = $this->atp->client->get(
···
43
45
*
44
46
* @see https://docs.bsky.app/docs/api/app-bsky-feed-get-timeline
45
47
*/
46
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:app.bsky.feed.getTimeline')]
48
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:app.bsky.feed.getTimeline')]
47
49
public function getTimeline(int $limit = 50, ?string $cursor = null): GetTimelineResponse
48
50
{
49
51
$response = $this->atp->client->get(
···
59
61
*
60
62
* @see https://docs.bsky.app/docs/api/app-bsky-feed-get-author-feed
61
63
*/
64
+
#[PublicEndpoint]
62
65
public function getAuthorFeed(
63
66
string $actor,
64
67
int $limit = 50,
···
78
81
*
79
82
* @see https://docs.bsky.app/docs/api/app-bsky-feed-get-actor-feeds
80
83
*/
84
+
#[PublicEndpoint]
81
85
public function getActorFeeds(string $actor, int $limit = 50, ?string $cursor = null): GetActorFeedsResponse
82
86
{
83
87
$response = $this->atp->client->get(
···
93
97
*
94
98
* @see https://docs.bsky.app/docs/api/app-bsky-feed-get-actor-likes
95
99
*/
100
+
#[PublicEndpoint]
96
101
public function getActorLikes(string $actor, int $limit = 50, ?string $cursor = null): GetActorLikesResponse
97
102
{
98
103
$response = $this->atp->client->get(
···
108
113
*
109
114
* @see https://docs.bsky.app/docs/api/app-bsky-feed-get-feed
110
115
*/
116
+
#[PublicEndpoint]
111
117
public function getFeed(string $feed, int $limit = 50, ?string $cursor = null): GetFeedResponse
112
118
{
113
119
$response = $this->atp->client->get(
···
123
129
*
124
130
* @see https://docs.bsky.app/docs/api/app-bsky-feed-get-feed-generator
125
131
*/
132
+
#[PublicEndpoint]
126
133
public function getFeedGenerator(string $feed): GetFeedGeneratorResponse
127
134
{
128
135
$response = $this->atp->client->get(
···
138
145
*
139
146
* @see https://docs.bsky.app/docs/api/app-bsky-feed-get-feed-generators
140
147
*/
148
+
#[PublicEndpoint]
141
149
public function getFeedGenerators(array $feeds): GetFeedGeneratorsResponse
142
150
{
143
151
$response = $this->atp->client->get(
···
153
161
*
154
162
* @see https://docs.bsky.app/docs/api/app-bsky-feed-get-post-thread
155
163
*/
164
+
#[PublicEndpoint]
156
165
public function getPostThread(string $uri, int $depth = 6, int $parentHeight = 80): GetPostThreadResponse
157
166
{
158
167
$response = $this->atp->client->get(
···
168
177
*
169
178
* @see https://docs.bsky.app/docs/api/app-bsky-feed-get-posts
170
179
*/
180
+
#[PublicEndpoint]
171
181
public function getPosts(array $uris): GetPostsResponse
172
182
{
173
183
$response = $this->atp->client->get(
···
183
193
*
184
194
* @see https://docs.bsky.app/docs/api/app-bsky-feed-get-likes
185
195
*/
196
+
#[PublicEndpoint]
186
197
public function getLikes(
187
198
string $uri,
188
199
int $limit = 50,
···
202
213
*
203
214
* @see https://docs.bsky.app/docs/api/app-bsky-feed-get-quotes
204
215
*/
216
+
#[PublicEndpoint]
205
217
public function getQuotes(
206
218
string $uri,
207
219
int $limit = 50,
···
221
233
*
222
234
* @see https://docs.bsky.app/docs/api/app-bsky-feed-get-reposted-by
223
235
*/
236
+
#[PublicEndpoint]
224
237
public function getRepostedBy(
225
238
string $uri,
226
239
int $limit = 50,
···
240
253
*
241
254
* @see https://docs.bsky.app/docs/api/app-bsky-feed-get-suggested-feeds
242
255
*/
256
+
#[PublicEndpoint]
243
257
public function getSuggestedFeeds(int $limit = 50, ?string $cursor = null): GetSuggestedFeedsResponse
244
258
{
245
259
$response = $this->atp->client->get(
···
255
269
*
256
270
* @see https://docs.bsky.app/docs/api/app-bsky-feed-search-posts
257
271
*/
272
+
#[PublicEndpoint]
258
273
public function searchPosts(
259
274
string $q,
260
275
int $limit = 25,
+10
src/Client/Requests/Bsky/GraphRequestClient.php
+10
src/Client/Requests/Bsky/GraphRequestClient.php
···
2
2
3
3
namespace SocialDept\AtpClient\Client\Requests\Bsky;
4
4
5
+
use SocialDept\AtpClient\Attributes\PublicEndpoint;
5
6
use SocialDept\AtpClient\Client\Requests\Request;
6
7
use SocialDept\AtpClient\Data\Responses\Bsky\Graph\GetFollowersResponse;
7
8
use SocialDept\AtpClient\Data\Responses\Bsky\Graph\GetFollowsResponse;
···
21
22
*
22
23
* @see https://docs.bsky.app/docs/api/app-bsky-graph-get-followers
23
24
*/
25
+
#[PublicEndpoint]
24
26
public function getFollowers(string $actor, int $limit = 50, ?string $cursor = null): GetFollowersResponse
25
27
{
26
28
$response = $this->atp->client->get(
···
36
38
*
37
39
* @see https://docs.bsky.app/docs/api/app-bsky-graph-get-follows
38
40
*/
41
+
#[PublicEndpoint]
39
42
public function getFollows(string $actor, int $limit = 50, ?string $cursor = null): GetFollowsResponse
40
43
{
41
44
$response = $this->atp->client->get(
···
51
54
*
52
55
* @see https://docs.bsky.app/docs/api/app-bsky-graph-get-known-followers
53
56
*/
57
+
#[PublicEndpoint]
54
58
public function getKnownFollowers(string $actor, int $limit = 50, ?string $cursor = null): GetKnownFollowersResponse
55
59
{
56
60
$response = $this->atp->client->get(
···
66
70
*
67
71
* @see https://docs.bsky.app/docs/api/app-bsky-graph-get-list
68
72
*/
73
+
#[PublicEndpoint]
69
74
public function getList(string $list, int $limit = 50, ?string $cursor = null): GetListResponse
70
75
{
71
76
$response = $this->atp->client->get(
···
81
86
*
82
87
* @see https://docs.bsky.app/docs/api/app-bsky-graph-get-lists
83
88
*/
89
+
#[PublicEndpoint]
84
90
public function getLists(string $actor, int $limit = 50, ?string $cursor = null): GetListsResponse
85
91
{
86
92
$response = $this->atp->client->get(
···
96
102
*
97
103
* @see https://docs.bsky.app/docs/api/app-bsky-graph-get-relationships
98
104
*/
105
+
#[PublicEndpoint]
99
106
public function getRelationships(string $actor, array $others = []): GetRelationshipsResponse
100
107
{
101
108
$response = $this->atp->client->get(
···
111
118
*
112
119
* @see https://docs.bsky.app/docs/api/app-bsky-graph-get-starter-pack
113
120
*/
121
+
#[PublicEndpoint]
114
122
public function getStarterPack(string $starterPack): StarterPackView
115
123
{
116
124
$response = $this->atp->client->get(
···
126
134
*
127
135
* @see https://docs.bsky.app/docs/api/app-bsky-graph-get-starter-packs
128
136
*/
137
+
#[PublicEndpoint]
129
138
public function getStarterPacks(array $uris): GetStarterPacksResponse
130
139
{
131
140
$response = $this->atp->client->get(
···
141
150
*
142
151
* @see https://docs.bsky.app/docs/api/app-bsky-graph-get-suggested-follows-by-actor
143
152
*/
153
+
#[PublicEndpoint]
144
154
public function getSuggestedFollowsByActor(string $actor): GetSuggestedFollowsByActorResponse
145
155
{
146
156
$response = $this->atp->client->get(
+2
src/Client/Requests/Bsky/LabelerRequestClient.php
+2
src/Client/Requests/Bsky/LabelerRequestClient.php
···
2
2
3
3
namespace SocialDept\AtpClient\Client\Requests\Bsky;
4
4
5
+
use SocialDept\AtpClient\Attributes\PublicEndpoint;
5
6
use SocialDept\AtpClient\Client\Requests\Request;
6
7
use SocialDept\AtpClient\Data\Responses\Bsky\Labeler\GetServicesResponse;
7
8
use SocialDept\AtpClient\Enums\Nsid\BskyLabeler;
···
13
14
*
14
15
* @see https://docs.bsky.app/docs/api/app-bsky-labeler-get-services
15
16
*/
17
+
#[PublicEndpoint]
16
18
public function getServices(array $dids, bool $detailed = false): GetServicesResponse
17
19
{
18
20
$response = $this->atp->client->get(
+8
-5
src/Client/Requests/Chat/ActorRequestClient.php
+8
-5
src/Client/Requests/Chat/ActorRequestClient.php
···
2
2
3
3
namespace SocialDept\AtpClient\Client\Requests\Chat;
4
4
5
-
use SocialDept\AtpClient\Attributes\RequiresScope;
5
+
use SocialDept\AtpClient\Attributes\ScopedEndpoint;
6
6
use SocialDept\AtpClient\Client\Requests\Request;
7
+
use SocialDept\AtpClient\Data\Responses\EmptyResponse;
7
8
use SocialDept\AtpClient\Enums\Nsid\ChatActor;
8
9
use SocialDept\AtpClient\Enums\Scope;
9
10
use SocialDept\AtpClient\Http\Response;
···
17
18
*
18
19
* @see https://docs.bsky.app/docs/api/chat-bsky-actor-export-account-data
19
20
*/
20
-
#[RequiresScope(Scope::TransitionChat, granular: 'rpc:chat.bsky.actor.getActorMetadata')]
21
+
#[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.actor.getActorMetadata')]
21
22
public function getActorMetadata(): Response
22
23
{
23
24
return $this->atp->client->get(
···
32
33
*
33
34
* @see https://docs.bsky.app/docs/api/chat-bsky-actor-export-account-data
34
35
*/
35
-
#[RequiresScope(Scope::TransitionChat, granular: 'rpc:chat.bsky.actor.exportAccountData')]
36
+
#[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.actor.exportAccountData')]
36
37
public function exportAccountData(): Response
37
38
{
38
39
return $this->atp->client->get(
···
47
48
*
48
49
* @see https://docs.bsky.app/docs/api/chat-bsky-actor-delete-account
49
50
*/
50
-
#[RequiresScope(Scope::TransitionChat, granular: 'rpc:chat.bsky.actor.deleteAccount')]
51
-
public function deleteAccount(): void
51
+
#[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.actor.deleteAccount')]
52
+
public function deleteAccount(): EmptyResponse
52
53
{
53
54
$this->atp->client->post(
54
55
endpoint: ChatActor::DeleteAccount
55
56
);
57
+
58
+
return new EmptyResponse;
56
59
}
57
60
}
+13
-13
src/Client/Requests/Chat/ConvoRequestClient.php
+13
-13
src/Client/Requests/Chat/ConvoRequestClient.php
···
2
2
3
3
namespace SocialDept\AtpClient\Client\Requests\Chat;
4
4
5
-
use SocialDept\AtpClient\Attributes\RequiresScope;
5
+
use SocialDept\AtpClient\Attributes\ScopedEndpoint;
6
6
use SocialDept\AtpClient\Client\Requests\Request;
7
7
use SocialDept\AtpClient\Data\Responses\Chat\Convo\GetLogResponse;
8
8
use SocialDept\AtpClient\Data\Responses\Chat\Convo\GetMessagesResponse;
···
24
24
*
25
25
* @see https://docs.bsky.app/docs/api/chat-bsky-convo-get-convo
26
26
*/
27
-
#[RequiresScope(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.getConvo')]
27
+
#[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.getConvo')]
28
28
public function getConvo(string $convoId): ConvoView
29
29
{
30
30
$response = $this->atp->client->get(
···
42
42
*
43
43
* @see https://docs.bsky.app/docs/api/chat-bsky-convo-get-convo-for-members
44
44
*/
45
-
#[RequiresScope(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.getConvoForMembers')]
45
+
#[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.getConvoForMembers')]
46
46
public function getConvoForMembers(array $members): ConvoView
47
47
{
48
48
$response = $this->atp->client->get(
···
60
60
*
61
61
* @see https://docs.bsky.app/docs/api/chat-bsky-convo-list-convos
62
62
*/
63
-
#[RequiresScope(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.listConvos')]
63
+
#[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.listConvos')]
64
64
public function listConvos(int $limit = 50, ?string $cursor = null): ListConvosResponse
65
65
{
66
66
$response = $this->atp->client->get(
···
78
78
*
79
79
* @see https://docs.bsky.app/docs/api/chat-bsky-convo-get-messages
80
80
*/
81
-
#[RequiresScope(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.getMessages')]
81
+
#[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.getMessages')]
82
82
public function getMessages(
83
83
string $convoId,
84
84
int $limit = 50,
···
99
99
*
100
100
* @see https://docs.bsky.app/docs/api/chat-bsky-convo-send-message
101
101
*/
102
-
#[RequiresScope(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.sendMessage')]
102
+
#[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.sendMessage')]
103
103
public function sendMessage(string $convoId, array $message): MessageView
104
104
{
105
105
$response = $this->atp->client->post(
···
117
117
*
118
118
* @see https://docs.bsky.app/docs/api/chat-bsky-convo-send-message-batch
119
119
*/
120
-
#[RequiresScope(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.sendMessageBatch')]
120
+
#[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.sendMessageBatch')]
121
121
public function sendMessageBatch(array $items): SendMessageBatchResponse
122
122
{
123
123
$response = $this->atp->client->post(
···
135
135
*
136
136
* @see https://docs.bsky.app/docs/api/chat-bsky-convo-delete-message-for-self
137
137
*/
138
-
#[RequiresScope(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.deleteMessageForSelf')]
138
+
#[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.deleteMessageForSelf')]
139
139
public function deleteMessageForSelf(string $convoId, string $messageId): DeletedMessageView
140
140
{
141
141
$response = $this->atp->client->post(
···
153
153
*
154
154
* @see https://docs.bsky.app/docs/api/chat-bsky-convo-update-read
155
155
*/
156
-
#[RequiresScope(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.updateRead')]
156
+
#[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.updateRead')]
157
157
public function updateRead(string $convoId, ?string $messageId = null): ConvoView
158
158
{
159
159
$response = $this->atp->client->post(
···
171
171
*
172
172
* @see https://docs.bsky.app/docs/api/chat-bsky-convo-mute-convo
173
173
*/
174
-
#[RequiresScope(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.muteConvo')]
174
+
#[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.muteConvo')]
175
175
public function muteConvo(string $convoId): ConvoView
176
176
{
177
177
$response = $this->atp->client->post(
···
189
189
*
190
190
* @see https://docs.bsky.app/docs/api/chat-bsky-convo-unmute-convo
191
191
*/
192
-
#[RequiresScope(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.unmuteConvo')]
192
+
#[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.unmuteConvo')]
193
193
public function unmuteConvo(string $convoId): ConvoView
194
194
{
195
195
$response = $this->atp->client->post(
···
207
207
*
208
208
* @see https://docs.bsky.app/docs/api/chat-bsky-convo-leave-convo
209
209
*/
210
-
#[RequiresScope(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.leaveConvo')]
210
+
#[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.leaveConvo')]
211
211
public function leaveConvo(string $convoId): LeaveConvoResponse
212
212
{
213
213
$response = $this->atp->client->post(
···
225
225
*
226
226
* @see https://docs.bsky.app/docs/api/chat-bsky-convo-get-log
227
227
*/
228
-
#[RequiresScope(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.getLog')]
228
+
#[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.getLog')]
229
229
public function getLog(?string $cursor = null): GetLogResponse
230
230
{
231
231
$response = $this->atp->client->get(
+9
-9
src/Client/Requests/Ozone/ModerationRequestClient.php
+9
-9
src/Client/Requests/Ozone/ModerationRequestClient.php
···
2
2
3
3
namespace SocialDept\AtpClient\Client\Requests\Ozone;
4
4
5
-
use SocialDept\AtpClient\Attributes\RequiresScope;
5
+
use SocialDept\AtpClient\Attributes\ScopedEndpoint;
6
6
use SocialDept\AtpClient\Client\Requests\Request;
7
7
use SocialDept\AtpClient\Data\Responses\Ozone\Moderation\QueryEventsResponse;
8
8
use SocialDept\AtpClient\Data\Responses\Ozone\Moderation\QueryStatusesResponse;
···
24
24
*
25
25
* @see https://docs.bsky.app/docs/api/tools-ozone-moderation-get-event
26
26
*/
27
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.getEvent')]
27
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.getEvent')]
28
28
public function getModerationEvent(int $id): ModEventViewDetail
29
29
{
30
30
$response = $this->atp->client->get(
···
42
42
*
43
43
* @see https://docs.bsky.app/docs/api/tools-ozone-moderation-query-events
44
44
*/
45
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.getEvents')]
45
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.getEvents')]
46
46
public function getModerationEvents(
47
47
?string $subject = null,
48
48
?array $types = null,
···
66
66
*
67
67
* @see https://docs.bsky.app/docs/api/tools-ozone-moderation-get-record
68
68
*/
69
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.getRecord')]
69
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.getRecord')]
70
70
public function getRecord(string $uri, ?string $cid = null): RecordViewDetail
71
71
{
72
72
$response = $this->atp->client->get(
···
84
84
*
85
85
* @see https://docs.bsky.app/docs/api/tools-ozone-moderation-get-repo
86
86
*/
87
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.getRepo')]
87
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.getRepo')]
88
88
public function getRepo(string $did): RepoViewDetail
89
89
{
90
90
$response = $this->atp->client->get(
···
102
102
*
103
103
* @see https://docs.bsky.app/docs/api/tools-ozone-moderation-query-events
104
104
*/
105
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.queryEvents')]
105
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.queryEvents')]
106
106
public function queryEvents(
107
107
?array $types = null,
108
108
?string $createdBy = null,
···
129
129
*
130
130
* @see https://docs.bsky.app/docs/api/tools-ozone-moderation-query-statuses
131
131
*/
132
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.queryStatuses')]
132
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.queryStatuses')]
133
133
public function queryStatuses(
134
134
?string $subject = null,
135
135
?array $tags = null,
···
155
155
*
156
156
* @see https://docs.bsky.app/docs/api/tools-ozone-moderation-search-repos
157
157
*/
158
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.searchRepos')]
158
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.searchRepos')]
159
159
public function searchRepos(
160
160
?string $term = null,
161
161
?string $invitedBy = null,
···
180
180
*
181
181
* @see https://docs.bsky.app/docs/api/tools-ozone-moderation-emit-event
182
182
*/
183
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.emitEvent')]
183
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.emitEvent')]
184
184
public function emitEvent(
185
185
array $event,
186
186
string $subject,
+3
-3
src/Client/Requests/Ozone/ServerRequestClient.php
+3
-3
src/Client/Requests/Ozone/ServerRequestClient.php
···
2
2
3
3
namespace SocialDept\AtpClient\Client\Requests\Ozone;
4
4
5
-
use SocialDept\AtpClient\Attributes\RequiresScope;
5
+
use SocialDept\AtpClient\Attributes\ScopedEndpoint;
6
6
use SocialDept\AtpClient\Client\Requests\Request;
7
7
use SocialDept\AtpClient\Data\Responses\Ozone\Server\GetConfigResponse;
8
8
use SocialDept\AtpClient\Enums\Nsid\OzoneServer;
···
18
18
*
19
19
* @see https://docs.bsky.app/docs/api/tools-ozone-server-get-config
20
20
*/
21
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.server.getBlob')]
21
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.server.getBlob')]
22
22
public function getBlob(string $did, string $cid): Response
23
23
{
24
24
return $this->atp->client->get(
···
34
34
*
35
35
* @see https://docs.bsky.app/docs/api/tools-ozone-server-get-config
36
36
*/
37
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.server.getConfig')]
37
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.server.getConfig')]
38
38
public function getConfig(): GetConfigResponse
39
39
{
40
40
$response = $this->atp->client->get(
+17
-19
src/Client/Requests/Ozone/TeamRequestClient.php
+17
-19
src/Client/Requests/Ozone/TeamRequestClient.php
···
2
2
3
3
namespace SocialDept\AtpClient\Client\Requests\Ozone;
4
4
5
-
use SocialDept\AtpClient\Attributes\RequiresScope;
5
+
use SocialDept\AtpClient\Attributes\ScopedEndpoint;
6
6
use SocialDept\AtpClient\Client\Requests\Request;
7
+
use SocialDept\AtpClient\Data\Responses\EmptyResponse;
7
8
use SocialDept\AtpClient\Data\Responses\Ozone\Team\ListMembersResponse;
9
+
use SocialDept\AtpClient\Data\Responses\Ozone\Team\MemberResponse;
8
10
use SocialDept\AtpClient\Enums\Nsid\OzoneTeam;
9
11
use SocialDept\AtpClient\Enums\Scope;
10
12
···
15
17
*
16
18
* @requires transition:generic (rpc:tools.ozone.team.getMember)
17
19
*
18
-
* @return array<string, mixed> Team member object
19
-
*
20
20
* @see https://docs.bsky.app/docs/api/tools-ozone-team-list-members
21
21
*/
22
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.team.getMember')]
23
-
public function getTeamMember(string $did): array
22
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.team.getMember')]
23
+
public function getTeamMember(string $did): MemberResponse
24
24
{
25
25
$response = $this->atp->client->get(
26
26
endpoint: OzoneTeam::GetMember,
27
27
params: compact('did')
28
28
);
29
29
30
-
return $response->json();
30
+
return MemberResponse::fromArray($response->json());
31
31
}
32
32
33
33
/**
···
37
37
*
38
38
* @see https://docs.bsky.app/docs/api/tools-ozone-team-list-members
39
39
*/
40
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.team.listMembers')]
40
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.team.listMembers')]
41
41
public function listTeamMembers(int $limit = 50, ?string $cursor = null): ListMembersResponse
42
42
{
43
43
$response = $this->atp->client->get(
···
53
53
*
54
54
* @requires transition:generic (rpc:tools.ozone.team.addMember)
55
55
*
56
-
* @return array<string, mixed> Team member object
57
-
*
58
56
* @see https://docs.bsky.app/docs/api/tools-ozone-team-add-member
59
57
*/
60
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.team.addMember')]
61
-
public function addTeamMember(string $did, string $role): array
58
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.team.addMember')]
59
+
public function addTeamMember(string $did, string $role): MemberResponse
62
60
{
63
61
$response = $this->atp->client->post(
64
62
endpoint: OzoneTeam::AddMember,
65
63
body: compact('did', 'role')
66
64
);
67
65
68
-
return $response->json();
66
+
return MemberResponse::fromArray($response->json());
69
67
}
70
68
71
69
/**
···
73
71
*
74
72
* @requires transition:generic (rpc:tools.ozone.team.updateMember)
75
73
*
76
-
* @return array<string, mixed> Team member object
77
-
*
78
74
* @see https://docs.bsky.app/docs/api/tools-ozone-team-update-member
79
75
*/
80
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.team.updateMember')]
76
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.team.updateMember')]
81
77
public function updateTeamMember(
82
78
string $did,
83
79
?bool $disabled = null,
84
80
?string $role = null
85
-
): array {
81
+
): MemberResponse {
86
82
$response = $this->atp->client->post(
87
83
endpoint: OzoneTeam::UpdateMember,
88
84
body: array_filter(
···
91
87
)
92
88
);
93
89
94
-
return $response->json();
90
+
return MemberResponse::fromArray($response->json());
95
91
}
96
92
97
93
/**
···
101
97
*
102
98
* @see https://docs.bsky.app/docs/api/tools-ozone-team-delete-member
103
99
*/
104
-
#[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.team.deleteMember')]
105
-
public function deleteTeamMember(string $did): void
100
+
#[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.team.deleteMember')]
101
+
public function deleteTeamMember(string $did): EmptyResponse
106
102
{
107
103
$this->atp->client->post(
108
104
endpoint: OzoneTeam::DeleteMember,
109
105
body: compact('did')
110
106
);
107
+
108
+
return new EmptyResponse;
111
109
}
112
110
}
+29
src/Data/Responses/Atproto/Identity/ResolveHandleResponse.php
+29
src/Data/Responses/Atproto/Identity/ResolveHandleResponse.php
···
1
+
<?php
2
+
3
+
namespace SocialDept\AtpClient\Data\Responses\Atproto\Identity;
4
+
5
+
use Illuminate\Contracts\Support\Arrayable;
6
+
7
+
/**
8
+
* @implements Arrayable<string, string>
9
+
*/
10
+
class ResolveHandleResponse implements Arrayable
11
+
{
12
+
public function __construct(
13
+
public readonly string $did,
14
+
) {}
15
+
16
+
public static function fromArray(array $data): self
17
+
{
18
+
return new self(
19
+
did: $data['did'],
20
+
);
21
+
}
22
+
23
+
public function toArray(): array
24
+
{
25
+
return [
26
+
'did' => $this->did,
27
+
];
28
+
}
29
+
}
+36
src/Data/Responses/Atproto/Sync/ListReposByCollectionResponse.php
+36
src/Data/Responses/Atproto/Sync/ListReposByCollectionResponse.php
···
1
+
<?php
2
+
3
+
namespace SocialDept\AtpClient\Data\Responses\Atproto\Sync;
4
+
5
+
use Illuminate\Contracts\Support\Arrayable;
6
+
use Illuminate\Support\Collection;
7
+
8
+
/**
9
+
* @implements Arrayable<string, mixed>
10
+
*/
11
+
class ListReposByCollectionResponse implements Arrayable
12
+
{
13
+
/**
14
+
* @param Collection<int, array{did: string, rev: string}> $repos
15
+
*/
16
+
public function __construct(
17
+
public readonly Collection $repos,
18
+
public readonly ?string $cursor = null,
19
+
) {}
20
+
21
+
public static function fromArray(array $data): self
22
+
{
23
+
return new self(
24
+
repos: collect($data['repos'] ?? []),
25
+
cursor: $data['cursor'] ?? null,
26
+
);
27
+
}
28
+
29
+
public function toArray(): array
30
+
{
31
+
return [
32
+
'repos' => $this->repos->all(),
33
+
'cursor' => $this->cursor,
34
+
];
35
+
}
36
+
}
+25
src/Data/Responses/EmptyResponse.php
+25
src/Data/Responses/EmptyResponse.php
···
1
+
<?php
2
+
3
+
namespace SocialDept\AtpClient\Data\Responses;
4
+
5
+
use Illuminate\Contracts\Support\Arrayable;
6
+
7
+
/**
8
+
* Response class for endpoints that return empty objects.
9
+
*
10
+
* @implements Arrayable<string, mixed>
11
+
*/
12
+
class EmptyResponse implements Arrayable
13
+
{
14
+
public function __construct() {}
15
+
16
+
public static function fromArray(array $data): self
17
+
{
18
+
return new self;
19
+
}
20
+
21
+
public function toArray(): array
22
+
{
23
+
return [];
24
+
}
25
+
}
+44
src/Data/Responses/Ozone/Team/MemberResponse.php
+44
src/Data/Responses/Ozone/Team/MemberResponse.php
···
1
+
<?php
2
+
3
+
namespace SocialDept\AtpClient\Data\Responses\Ozone\Team;
4
+
5
+
use Illuminate\Contracts\Support\Arrayable;
6
+
7
+
/**
8
+
* @implements Arrayable<string, mixed>
9
+
*/
10
+
class MemberResponse implements Arrayable
11
+
{
12
+
public function __construct(
13
+
public readonly string $did,
14
+
public readonly bool $disabled,
15
+
public readonly ?string $role = null,
16
+
public readonly ?string $createdAt = null,
17
+
public readonly ?string $updatedAt = null,
18
+
public readonly ?string $lastUpdatedBy = null,
19
+
) {}
20
+
21
+
public static function fromArray(array $data): self
22
+
{
23
+
return new self(
24
+
did: $data['did'],
25
+
disabled: $data['disabled'] ?? false,
26
+
role: $data['role'] ?? null,
27
+
createdAt: $data['createdAt'] ?? null,
28
+
updatedAt: $data['updatedAt'] ?? null,
29
+
lastUpdatedBy: $data['lastUpdatedBy'] ?? null,
30
+
);
31
+
}
32
+
33
+
public function toArray(): array
34
+
{
35
+
return array_filter([
36
+
'did' => $this->did,
37
+
'disabled' => $this->disabled,
38
+
'role' => $this->role,
39
+
'createdAt' => $this->createdAt,
40
+
'updatedAt' => $this->updatedAt,
41
+
'lastUpdatedBy' => $this->lastUpdatedBy,
42
+
], fn ($v) => $v !== null);
43
+
}
44
+
}
+1
src/Enums/Nsid/AtprotoSync.php
+1
src/Enums/Nsid/AtprotoSync.php
···
10
10
case GetBlob = 'com.atproto.sync.getBlob';
11
11
case GetRepo = 'com.atproto.sync.getRepo';
12
12
case ListRepos = 'com.atproto.sync.listRepos';
13
+
case ListReposByCollection = 'com.atproto.sync.listReposByCollection';
13
14
case GetLatestCommit = 'com.atproto.sync.getLatestCommit';
14
15
case GetRecord = 'com.atproto.sync.getRecord';
15
16
case ListBlobs = 'com.atproto.sync.listBlobs';
+5
-186
src/RichText/TextBuilder.php
+5
-186
src/RichText/TextBuilder.php
···
2
2
3
3
namespace SocialDept\AtpClient\RichText;
4
4
5
-
use SocialDept\AtpResolver\Facades\Resolver;
5
+
use SocialDept\AtpClient\Builders\Concerns\BuildsRichText;
6
6
7
7
class TextBuilder
8
8
{
9
-
protected string $text = '';
10
-
protected array $facets = [];
9
+
use BuildsRichText;
11
10
12
11
/**
13
12
* Create a new text builder instance
14
13
*/
15
14
public static function make(): self
16
15
{
17
-
return new self();
16
+
return new self;
18
17
}
19
18
20
19
/**
···
22
21
*/
23
22
public static function build(callable $callback): array
24
23
{
25
-
$builder = new self();
24
+
$builder = new self;
26
25
$callback($builder);
27
26
28
27
return $builder->toArray();
29
28
}
30
29
31
30
/**
32
-
* Add plain text
33
-
*/
34
-
public function text(string $text): self
35
-
{
36
-
$this->text .= $text;
37
-
38
-
return $this;
39
-
}
40
-
41
-
/**
42
-
* Add a new line
43
-
*/
44
-
public function newLine(): self
45
-
{
46
-
$this->text .= "\n";
47
-
48
-
return $this;
49
-
}
50
-
51
-
/**
52
-
* Add mention (@handle)
53
-
*/
54
-
public function mention(string $handle, ?string $did = null): self
55
-
{
56
-
$handle = ltrim($handle, '@');
57
-
$start = $this->getBytePosition();
58
-
$this->text .= '@'.$handle;
59
-
$end = $this->getBytePosition();
60
-
61
-
// Resolve DID if not provided
62
-
if (! $did) {
63
-
try {
64
-
$did = Resolver::handleToDid($handle);
65
-
} catch (\Exception $e) {
66
-
// If resolution fails, still add the text but skip the facet
67
-
return $this;
68
-
}
69
-
}
70
-
71
-
$this->facets[] = [
72
-
'index' => [
73
-
'byteStart' => $start,
74
-
'byteEnd' => $end,
75
-
],
76
-
'features' => [
77
-
[
78
-
'$type' => 'app.bsky.richtext.facet#mention',
79
-
'did' => $did,
80
-
],
81
-
],
82
-
];
83
-
84
-
return $this;
85
-
}
86
-
87
-
/**
88
-
* Add link with custom display text
89
-
*/
90
-
public function link(string $text, string $uri): self
91
-
{
92
-
$start = $this->getBytePosition();
93
-
$this->text .= $text;
94
-
$end = $this->getBytePosition();
95
-
96
-
$this->facets[] = [
97
-
'index' => [
98
-
'byteStart' => $start,
99
-
'byteEnd' => $end,
100
-
],
101
-
'features' => [
102
-
[
103
-
'$type' => 'app.bsky.richtext.facet#link',
104
-
'uri' => $uri,
105
-
],
106
-
],
107
-
];
108
-
109
-
return $this;
110
-
}
111
-
112
-
/**
113
-
* Add a URL (displayed as-is)
114
-
*/
115
-
public function url(string $url): self
116
-
{
117
-
return $this->link($url, $url);
118
-
}
119
-
120
-
/**
121
-
* Add hashtag
122
-
*/
123
-
public function tag(string $tag): self
124
-
{
125
-
$tag = ltrim($tag, '#');
126
-
127
-
$start = $this->getBytePosition();
128
-
$this->text .= '#'.$tag;
129
-
$end = $this->getBytePosition();
130
-
131
-
$this->facets[] = [
132
-
'index' => [
133
-
'byteStart' => $start,
134
-
'byteEnd' => $end,
135
-
],
136
-
'features' => [
137
-
[
138
-
'$type' => 'app.bsky.richtext.facet#tag',
139
-
'tag' => $tag,
140
-
],
141
-
],
142
-
];
143
-
144
-
return $this;
145
-
}
146
-
147
-
/**
148
-
* Auto-detect and add facets from plain text
149
-
*/
150
-
public function autoDetect(string $text): self
151
-
{
152
-
$start = $this->getBytePosition();
153
-
$this->text .= $text;
154
-
155
-
// Detect facets in the added text
156
-
$detected = FacetDetector::detect($text);
157
-
158
-
// Adjust byte positions to account for existing text
159
-
foreach ($detected as $facet) {
160
-
$facet['index']['byteStart'] += $start;
161
-
$facet['index']['byteEnd'] += $start;
162
-
$this->facets[] = $facet;
163
-
}
164
-
165
-
return $this;
166
-
}
167
-
168
-
/**
169
-
* Get current byte position
170
-
*/
171
-
protected function getBytePosition(): int
172
-
{
173
-
return strlen($this->text);
174
-
}
175
-
176
-
/**
177
-
* Get the text content
178
-
*/
179
-
public function getText(): string
180
-
{
181
-
return $this->text;
182
-
}
183
-
184
-
/**
185
-
* Get the facets
186
-
*/
187
-
public function getFacets(): array
188
-
{
189
-
return $this->facets;
190
-
}
191
-
192
-
/**
193
31
* Build the final text and facets array
194
32
*/
195
33
public function toArray(): array
196
34
{
197
-
return [
198
-
'text' => $this->text,
199
-
'facets' => $this->facets,
200
-
];
35
+
return $this->getTextAndFacets();
201
36
}
202
37
203
38
/**
···
233
68
public function getByteCount(): int
234
69
{
235
70
return strlen($this->text);
236
-
}
237
-
238
-
/**
239
-
* Check if text exceeds AT Protocol post limit (300 graphemes)
240
-
*/
241
-
public function exceedsLimit(int $limit = 300): bool
242
-
{
243
-
return $this->getGraphemeCount() > $limit;
244
-
}
245
-
246
-
/**
247
-
* Get grapheme count (closest to what AT Protocol uses)
248
-
*/
249
-
public function getGraphemeCount(): int
250
-
{
251
-
return grapheme_strlen($this->text);
252
71
}
253
72
254
73
/**