|
| 1 | +# Pastefy Client |
| 2 | + |
| 3 | +A TypeScript client for interacting with the [Pastefy.app](https://pastefy.app) API (v2). This library provides full access to pastes, folders, tags, users, and more, and supports both authenticated and public endpoints. |
| 4 | + |
| 5 | +## ✨ Features |
| 6 | + |
| 7 | +* Create, edit, delete and fetch pastes (including support for multipaste) |
| 8 | +* Manage folders and organize pastes |
| 9 | +* Fetch and filter public trending or latest pastes |
| 10 | +* Manage users and authentication |
| 11 | +* API key management |
| 12 | +* Fully typed with TypeScript |
| 13 | +* Built-in error handling with custom exceptions |
| 14 | + |
| 15 | +## 🚀 Installation |
| 16 | + |
| 17 | +```bash |
| 18 | +npm install @interaapps/pastefy |
| 19 | +``` |
| 20 | + |
| 21 | +## 📦 Usage |
| 22 | + |
| 23 | +```ts |
| 24 | +import { PastefyClient } from '@interaapps/pastefy-client'; |
| 25 | + |
| 26 | +const client = new PastefyClient('YOUR_API_KEY'); |
| 27 | + |
| 28 | +// Create a paste |
| 29 | +const paste = await client.createPaste({ |
| 30 | + title: 'Hello World', |
| 31 | + content: 'This is a sample paste.', |
| 32 | + visibility: 'PUBLIC', |
| 33 | +}); |
| 34 | +console.log(paste.id); |
| 35 | +``` |
| 36 | + |
| 37 | +## 📚 API Overview |
| 38 | + |
| 39 | +### 📝 Paste |
| 40 | + |
| 41 | +* `createPaste(paste: CreatePasteRequest)` |
| 42 | +* `editPaste(id: string, data: EditPasteRequest)` |
| 43 | +* `getPastes(query: PasteFilters)` |
| 44 | +* `getPaste(id: string)` |
| 45 | +* `getPasteRaw(id: string)` |
| 46 | +* `deletePaste(id: string)` |
| 47 | +* `starPaste(id: string)` |
| 48 | +* `unstarPaste(id: string)` |
| 49 | +* `getPublicPastes(query: PasteFilters)` |
| 50 | +* `getPublicTrendingPastes(query: PasteFilters)` |
| 51 | +* `getLatestPublicPastes(query: PasteFilters)` |
| 52 | +* `getUserPastes(query: PasteFilters)` |
| 53 | +* `getStarredPastes(query: PasteFilters)` |
| 54 | + |
| 55 | +### 📁 Folders |
| 56 | + |
| 57 | +* `createFolder(data: CreateFolderRequest)` |
| 58 | +* `getFolder(id: string, options?)` |
| 59 | +* `getFolders(query: Filters)` |
| 60 | +* `getUserFolders(query?)` |
| 61 | + |
| 62 | +### 👤 User |
| 63 | + |
| 64 | +* `getCurrentUser()` |
| 65 | +* `getUserOverview()` |
| 66 | +* `getPublicUser(id: string)` |
| 67 | +* `getUser(id: string)` |
| 68 | +* `getUsers(query: string)` |
| 69 | +* `editUser(id: string, data: EditUser)` |
| 70 | +* `deleteUser(id: string)` |
| 71 | + |
| 72 | +### 🔑 API Keys |
| 73 | + |
| 74 | +* `createApiKey()` |
| 75 | +* `getApiKeys()` |
| 76 | +* `deleteApiKey(id: string)` |
| 77 | + |
| 78 | +### 🏷 Tags |
| 79 | + |
| 80 | +* `getTags(query: Filters)` |
| 81 | +* `getTag(id: string)` |
| 82 | + |
| 83 | +## 🔐 Authentication |
| 84 | + |
| 85 | +Pass your API token when creating the client instance: |
| 86 | + |
| 87 | +```ts |
| 88 | +const client = new PastefyClient('your-api-token'); |
| 89 | +``` |
| 90 | + |
| 91 | +You can also update the token later: |
| 92 | + |
| 93 | +```ts |
| 94 | +client.setApiToken('new-token'); |
| 95 | +``` |
| 96 | + |
| 97 | +## ❗ Exceptions |
| 98 | + |
| 99 | +Custom exceptions are automatically thrown for common error types: |
| 100 | + |
| 101 | +* `AuthenticationException` |
| 102 | +* `AwaitingAccessException` |
| 103 | +* `BlockedException` |
| 104 | +* `FeatureDisabledException` |
| 105 | +* `NotFoundException` |
| 106 | +* `PastePrivateException` |
| 107 | +* `PermissionsDeniedException` |
| 108 | + |
| 109 | +Catch them like this: |
| 110 | + |
| 111 | +```ts |
| 112 | +try { |
| 113 | + await client.getPaste('invalid-id'); |
| 114 | +} catch (e) { |
| 115 | + if (e instanceof NotFoundException) { |
| 116 | + console.error('Paste not found'); |
| 117 | + } |
| 118 | +} |
| 119 | +``` |
| 120 | + |
| 121 | +## 🧱 Types |
| 122 | + |
| 123 | +The library exports many useful types: |
| 124 | + |
| 125 | +* `Paste`, `CreatePasteRequest`, `EditPasteRequest` |
| 126 | +* `Folder`, `CreateFolderRequest` |
| 127 | +* `User`, `PublicUser`, `UserAsAdmin`, `EditUser` |
| 128 | +* `Tag` |
| 129 | +* `Filters`, `PasteFilters` |
| 130 | +* `ApiKey` |
| 131 | +* `UserOverview` |
| 132 | + |
| 133 | +## 🧪 Example |
| 134 | + |
| 135 | +```ts |
| 136 | +const paste = await client.createPaste({ |
| 137 | + title: 'My First Paste', |
| 138 | + content: 'Welcome to Pastefy!', |
| 139 | + visibility: 'UNLISTED', |
| 140 | + tags: ['welcome', 'test'], |
| 141 | +}); |
| 142 | + |
| 143 | +console.log(`Paste created at: https://pastefy.app/${paste.id}`); |
| 144 | +``` |
| 145 | + |
| 146 | +## 🔗 Related |
| 147 | + |
| 148 | +* [Pastefy.app](https://pastefy.app) |
| 149 | + |
| 150 | +## 📄 License |
| 151 | + |
| 152 | +MIT License |
0 commit comments