Laravel AT Protocol Client (alpha & unstable)
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'refs/heads/dev'

+30 -12
+5 -2
src/Auth/ScopeChecker.php
··· 2 2 3 3 namespace SocialDept\AtpClient\Auth; 4 4 5 + use BackedEnum; 5 6 use Illuminate\Support\Facades\Log; 6 7 use SocialDept\AtpClient\Enums\Scope; 7 8 use SocialDept\AtpClient\Enums\ScopeEnforcementLevel; ··· 197 198 /** 198 199 * Check if the session has repo access for a specific collection and action. 199 200 */ 200 - public function checkRepoScope(Session $session, string $collection, string $action): bool 201 + public function checkRepoScope(Session $session, string|BackedEnum $collection, string $action): bool 201 202 { 203 + $collection = $collection instanceof BackedEnum ? $collection->value : $collection; 202 204 $required = "repo:{$collection}?action={$action}"; 203 205 204 206 return $this->sessionHasScope($session, $required); ··· 209 211 * 210 212 * @throws MissingScopeException 211 213 */ 212 - public function checkRepoScopeOrFail(Session $session, string $collection, string $action): void 214 + public function checkRepoScopeOrFail(Session $session, string|BackedEnum $collection, string $action): void 213 215 { 216 + $collection = $collection instanceof BackedEnum ? $collection->value : $collection; 214 217 $required = "repo:{$collection}?action={$action}"; 215 218 216 219 $this->checkOrFail($session, [$required]);
+5 -2
src/Client/Public/Requests/Atproto/RepoPublicRequestClient.php
··· 2 2 3 3 namespace SocialDept\AtpClient\Client\Public\Requests\Atproto; 4 4 5 + use BackedEnum; 5 6 use SocialDept\AtpClient\Client\Public\Requests\PublicRequest; 6 7 use SocialDept\AtpClient\Data\Responses\Atproto\Repo\DescribeRepoResponse; 7 8 use SocialDept\AtpClient\Data\Responses\Atproto\Repo\GetRecordResponse; ··· 17 18 */ 18 19 public function getRecord( 19 20 string $repo, 20 - string $collection, 21 + string|BackedEnum $collection, 21 22 string $rkey, 22 23 ?string $cid = null 23 24 ): GetRecordResponse { 25 + $collection = $collection instanceof BackedEnum ? $collection->value : $collection; 24 26 $response = $this->atp->client->get( 25 27 endpoint: AtprotoRepo::GetRecord, 26 28 params: compact('repo', 'collection', 'rkey', 'cid') ··· 36 38 */ 37 39 public function listRecords( 38 40 string $repo, 39 - string $collection, 41 + string|BackedEnum $collection, 40 42 int $limit = 50, 41 43 ?string $cursor = null, 42 44 bool $reverse = false 43 45 ): ListRecordsResponse { 46 + $collection = $collection instanceof BackedEnum ? $collection->value : $collection; 44 47 $response = $this->atp->client->get( 45 48 endpoint: AtprotoRepo::ListRecords, 46 49 params: compact('repo', 'collection', 'limit', 'cursor', 'reverse')
+11 -5
src/Client/Requests/Atproto/RepoRequestClient.php
··· 2 2 3 3 namespace SocialDept\AtpClient\Client\Requests\Atproto; 4 4 5 + use BackedEnum; 5 6 use Illuminate\Http\UploadedFile; 6 7 use InvalidArgumentException; 7 8 use SocialDept\AtpClient\Attributes\RequiresScope; ··· 31 32 #[RequiresScope(Scope::TransitionGeneric, description: 'Create records in repository')] 32 33 public function createRecord( 33 34 string $repo, 34 - string $collection, 35 + string|BackedEnum $collection, 35 36 array $record, 36 37 ?string $rkey = null, 37 38 bool $validate = true, 38 39 ?string $swapCommit = null 39 40 ): CreateRecordResponse { 41 + $collection = $collection instanceof BackedEnum ? $collection->value : $collection; 40 42 $this->checkCollectionScope($collection, 'create'); 41 43 42 44 $response = $this->atp->client->post( ··· 60 62 #[RequiresScope(Scope::TransitionGeneric, description: 'Delete records from repository')] 61 63 public function deleteRecord( 62 64 string $repo, 63 - string $collection, 65 + string|BackedEnum $collection, 64 66 string $rkey, 65 67 ?string $swapRecord = null, 66 68 ?string $swapCommit = null 67 69 ): DeleteRecordResponse { 70 + $collection = $collection instanceof BackedEnum ? $collection->value : $collection; 68 71 $this->checkCollectionScope($collection, 'delete'); 69 72 70 73 $response = $this->atp->client->post( ··· 88 91 #[RequiresScope(Scope::TransitionGeneric, description: 'Update records in repository')] 89 92 public function putRecord( 90 93 string $repo, 91 - string $collection, 94 + string|BackedEnum $collection, 92 95 string $rkey, 93 96 array $record, 94 97 bool $validate = true, 95 98 ?string $swapRecord = null, 96 99 ?string $swapCommit = null 97 100 ): PutRecordResponse { 101 + $collection = $collection instanceof BackedEnum ? $collection->value : $collection; 98 102 $this->checkCollectionScope($collection, 'update'); 99 103 100 104 $response = $this->atp->client->post( ··· 118 122 #[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.getRecord')] 119 123 public function getRecord( 120 124 string $repo, 121 - string $collection, 125 + string|BackedEnum $collection, 122 126 string $rkey, 123 127 ?string $cid = null 124 128 ): GetRecordResponse { 129 + $collection = $collection instanceof BackedEnum ? $collection->value : $collection; 125 130 $response = $this->atp->client->get( 126 131 endpoint: AtprotoRepo::GetRecord, 127 132 params: compact('repo', 'collection', 'rkey', 'cid') ··· 140 145 #[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.listRecords')] 141 146 public function listRecords( 142 147 string $repo, 143 - string $collection, 148 + string|BackedEnum $collection, 144 149 int $limit = 50, 145 150 ?string $cursor = null, 146 151 bool $reverse = false 147 152 ): ListRecordsResponse { 153 + $collection = $collection instanceof BackedEnum ? $collection->value : $collection; 148 154 $response = $this->atp->client->get( 149 155 endpoint: AtprotoRepo::ListRecords, 150 156 params: compact('repo', 'collection', 'limit', 'cursor', 'reverse')
+4 -1
src/Client/Requests/Atproto/SyncRequestClient.php
··· 2 2 3 3 namespace SocialDept\AtpClient\Client\Requests\Atproto; 4 4 5 + use BackedEnum; 5 6 use SocialDept\AtpClient\Attributes\RequiresScope; 6 7 use SocialDept\AtpClient\Client\Requests\Request; 7 8 use SocialDept\AtpClient\Data\Responses\Atproto\Sync\GetRepoStatusResponse; ··· 90 91 * @see https://docs.bsky.app/docs/api/com-atproto-sync-get-record 91 92 */ 92 93 #[RequiresScope(Scope::Atproto, granular: 'rpc:com.atproto.sync.getRecord')] 93 - public function getRecord(string $did, string $collection, string $rkey): Response 94 + public function getRecord(string $did, string|BackedEnum $collection, string $rkey): Response 94 95 { 96 + $collection = $collection instanceof BackedEnum ? $collection->value : $collection; 97 + 95 98 return $this->atp->client->get( 96 99 endpoint: AtprotoSync::GetRecord, 97 100 params: compact('did', 'collection', 'rkey')
+5 -2
src/Enums/Scope.php
··· 2 2 3 3 namespace SocialDept\AtpClient\Enums; 4 4 5 + use BackedEnum; 6 + 5 7 enum Scope: string 6 8 { 7 9 // Transition scopes (current) ··· 13 15 /** 14 16 * Build a repo scope string for record operations. 15 17 * 16 - * @param string $collection The collection NSID (e.g., 'app.bsky.feed.post') 18 + * @param string|BackedEnum $collection The collection NSID (e.g., 'app.bsky.feed.post') 17 19 * @param array|null $actions The action (create, update, delete) 18 20 * 19 21 * @return string 20 22 */ 21 - public static function repo(string $collection, ?array $actions = []): string 23 + public static function repo(string|BackedEnum $collection, ?array $actions = []): string 22 24 { 25 + $collection = $collection instanceof BackedEnum ? $collection->value : $collection; 23 26 $scope = "repo:{$collection}"; 24 27 25 28 if (!empty($actions)) {