@autonomys/auto-files 1.5.11 → 1.5.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1 +1,298 @@
1
- # auto-files
1
+ # Auto Files
2
+
3
+ A TypeScript client library for interacting with the Auto Files service API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @autonomys/auto-files
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Basic Setup
14
+
15
+ ```typescript
16
+ import { createAutoFilesApi } from '@autonomys/auto-files'
17
+
18
+ const api = createAutoFilesApi('https://api.autofiles.com', 'your-api-secret')
19
+ ```
20
+
21
+ ### File Operations
22
+
23
+ #### Get File
24
+
25
+ ```typescript
26
+ import { createAutoFilesApi } from '@autonomys/auto-files'
27
+
28
+ const api = createAutoFilesApi('https://api.autofiles.com', 'your-api-secret')
29
+
30
+ try {
31
+ const fileStream = await api.getFile('your-file-cid', {
32
+ retriesPerFetch: 3,
33
+ onProgress: (progress) => {
34
+ console.log(`Download progress: ${progress * 100}%`)
35
+ },
36
+ ignoreCache: false,
37
+ })
38
+
39
+ // Handle the file stream
40
+ fileStream.pipe(process.stdout)
41
+ } catch (error) {
42
+ console.error('Error downloading file:', error)
43
+ }
44
+ ```
45
+
46
+ #### Get Chunked File
47
+
48
+ ```typescript
49
+ import { createAutoFilesApi } from '@autonomys/auto-files'
50
+
51
+ const api = createAutoFilesApi('https://api.autofiles.com', 'your-api-secret')
52
+
53
+ try {
54
+ const file = await api.getChunkedFile('your-file-cid', {
55
+ retriesPerFetch: 3,
56
+ onProgress: (progress) => {
57
+ console.log(`Download progress: ${progress * 100}%`)
58
+ },
59
+ })
60
+
61
+ console.log(`File size: ${file.length} bytes`)
62
+ console.log(`Compression: ${file.compression ? 'Yes' : 'No'}`)
63
+ console.log(`Encryption: ${file.encryption ? 'Yes' : 'No'}`)
64
+
65
+ // Handle the file data stream
66
+ file.data.pipe(process.stdout)
67
+ } catch (error) {
68
+ console.error('Error downloading chunked file:', error)
69
+ }
70
+ ```
71
+
72
+ #### Check File Cache Status
73
+
74
+ ```typescript
75
+ import { createAutoFilesApi } from '@autonomys/auto-files'
76
+
77
+ const api = createAutoFilesApi('https://api.autofiles.com', 'your-api-secret')
78
+
79
+ try {
80
+ const isCached = await api.isFileCached('your-file-cid')
81
+ console.log(`File is cached: ${isCached}`)
82
+ } catch (error) {
83
+ console.error('Error checking file cache status:', error)
84
+ }
85
+ ```
86
+
87
+ #### Get Node
88
+
89
+ ```typescript
90
+ import { createAutoFilesApi } from '@autonomys/auto-files'
91
+
92
+ const api = createAutoFilesApi('https://api.autofiles.com', 'your-api-secret')
93
+
94
+ try {
95
+ const nodeData = await api.getNode('your-node-cid')
96
+ console.log(`Node data size: ${nodeData.byteLength} bytes`)
97
+ } catch (error) {
98
+ console.error('Error fetching node:', error)
99
+ }
100
+ ```
101
+
102
+ ### Moderation Operations
103
+
104
+ #### Ban a File
105
+
106
+ ```typescript
107
+ import { createAutoFilesApi } from '@autonomys/auto-files'
108
+
109
+ const api = createAutoFilesApi('https://api.autofiles.com', 'your-api-secret')
110
+
111
+ try {
112
+ await api.banFile('your-file-cid')
113
+ console.log('File banned successfully')
114
+ } catch (error) {
115
+ console.error('Error banning file:', error)
116
+ }
117
+ ```
118
+
119
+ #### Unban a File
120
+
121
+ ```typescript
122
+ import { createAutoFilesApi } from '@autonomys/auto-files'
123
+
124
+ const api = createAutoFilesApi('https://api.autofiles.com', 'your-api-secret')
125
+
126
+ try {
127
+ await api.unbanFile('your-file-cid')
128
+ console.log('File unbanned successfully')
129
+ } catch (error) {
130
+ console.error('Error unbanning file:', error)
131
+ }
132
+ ```
133
+
134
+ #### Get Banned Files
135
+
136
+ ```typescript
137
+ import { createAutoFilesApi } from '@autonomys/auto-files'
138
+
139
+ const api = createAutoFilesApi('https://api.autofiles.com', 'your-api-secret')
140
+
141
+ try {
142
+ const bannedFiles = await api.getBannedFiles(1, 10)
143
+ console.log(`Found ${bannedFiles.length} banned files`)
144
+
145
+ for (const cid of bannedFiles) {
146
+ console.log(`CID: ${cid}`)
147
+ }
148
+ } catch (error) {
149
+ console.error('Error fetching banned files:', error)
150
+ }
151
+ ```
152
+
153
+ ## API Reference
154
+
155
+ ### `createAutoFilesApi(baseUrl: string, apiSecret: string)`
156
+
157
+ Creates an API client instance.
158
+
159
+ **Parameters:**
160
+
161
+ - `baseUrl` - The base URL of the Auto Files API
162
+ - `apiSecret` - The API secret key for authentication
163
+
164
+ **Returns:** An object containing methods to interact with the API
165
+
166
+ ### File Methods
167
+
168
+ #### `getFile(cid: string, options?: GetFileOptions)`
169
+
170
+ Fetches a complete file from the API.
171
+
172
+ **Parameters:**
173
+
174
+ - `cid` - The content identifier of the file
175
+ - `options` - Optional configuration
176
+ - `retriesPerFetch` - Number of retry attempts (default: 3)
177
+ - `onProgress` - Progress callback function (0-1)
178
+ - `ignoreCache` - Whether to ignore cache (default: false)
179
+
180
+ **Returns:** Promise<Readable> - File data stream
181
+
182
+ #### `getChunkedFile(cid: string, options?: GetChunkedFileOptions)`
183
+
184
+ Fetches a complete file with metadata.
185
+
186
+ **Parameters:**
187
+
188
+ - `cid` - The content identifier of the file
189
+ - `options` - Optional configuration
190
+ - `retriesPerFetch` - Number of retry attempts (default: 3)
191
+ - `onProgress` - Progress callback function (0-1)
192
+
193
+ **Returns:** Promise<FetchedFile> - File with metadata and data stream
194
+
195
+ #### `isFileCached(cid: string)`
196
+
197
+ Checks if a file is cached on the gateway.
198
+
199
+ **Parameters:**
200
+
201
+ - `cid` - The content identifier of the file
202
+
203
+ **Returns:** Promise<boolean> - Whether the file is cached
204
+
205
+ #### `getNode(cid: string)`
206
+
207
+ Fetches a specific node from the API.
208
+
209
+ **Parameters:**
210
+
211
+ - `cid` - The CID of the node
212
+
213
+ **Returns:** Promise<ArrayBuffer> - Node data
214
+
215
+ ### Moderation Methods
216
+
217
+ #### `banFile(cid: string)`
218
+
219
+ Bans a file by sending a request to the moderation service.
220
+
221
+ **Parameters:**
222
+
223
+ - `cid` - The content identifier of the file to ban
224
+
225
+ **Returns:** Promise<void>
226
+
227
+ #### `unbanFile(cid: string)`
228
+
229
+ Unbans a file by sending a request to the moderation service.
230
+
231
+ **Parameters:**
232
+
233
+ - `cid` - The content identifier of the file to unban
234
+
235
+ **Returns:** Promise<void>
236
+
237
+ #### `getBannedFiles(page?: number, limit?: number)`
238
+
239
+ Gets a list of banned files with pagination support.
240
+
241
+ **Parameters:**
242
+
243
+ - `page` - The page number for pagination (default: 1)
244
+ - `limit` - The number of files per page (default: 10)
245
+
246
+ **Returns:** Promise<BannedFilesResponse>
247
+
248
+ ## Types
249
+
250
+ ### `FetchedFile`
251
+
252
+ ```typescript
253
+ interface FetchedFile {
254
+ length: bigint
255
+ compression: CompressionOptions | undefined
256
+ encryption: EncryptionOptions | undefined
257
+ data: Readable
258
+ }
259
+ ```
260
+
261
+ ### `BannedFile`
262
+
263
+ ```typescript
264
+ interface BannedFile {
265
+ cid: string
266
+ bannedAt: string
267
+ reason?: string
268
+ bannedBy?: string
269
+ }
270
+ ```
271
+
272
+ ### `BannedFilesResponse`
273
+
274
+ ```typescript
275
+ interface BannedFilesResponse {
276
+ bannedFiles: BannedFile[]
277
+ totalCount?: number
278
+ page?: number
279
+ limit?: number
280
+ }
281
+ ```
282
+
283
+ ## Error Handling
284
+
285
+ All methods throw errors when API requests fail. Errors include HTTP status codes and descriptive messages.
286
+
287
+ ```typescript
288
+ try {
289
+ await api.banFile('invalid-cid')
290
+ } catch (error) {
291
+ console.error('Error:', error.message)
292
+ // Example: "Error banning file: 400 Bad Request"
293
+ }
294
+ ```
295
+
296
+ ## License
297
+
298
+ This project is licensed under the MIT License.
package/dist/api.d.ts CHANGED
@@ -24,6 +24,10 @@ export declare const createAutoFilesApi: (baseUrl: string, apiSecret: string) =>
24
24
  onProgress?: (progress: number) => void;
25
25
  }) => Promise<FetchedFile>;
26
26
  getNode: (cid: string) => Promise<ArrayBuffer>;
27
+ banFile: (cid: string) => Promise<void>;
28
+ unbanFile: (cid: string) => Promise<void>;
29
+ getBannedFiles: (page?: number, limit?: number) => Promise<string[]>;
30
+ isFileBanned: (cid: string) => Promise<boolean>;
27
31
  };
28
32
  export {};
29
33
  //# sourceMappingURL=api.d.ts.map
package/dist/api.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAEjC,UAAU,WAAW;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,kBAAkB,GAAG,SAAS,CAAA;IAC3C,UAAU,EAAE,iBAAiB,GAAG,SAAS,CAAA;IACzC,IAAI,EAAE,QAAQ,CAAA;CACf;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,EAAE,WAAW,MAAM;mBAmJ5D,MAAM,kDAKR;QACD,eAAe,CAAC,EAAE,MAAM,CAAA;QACxB,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;QACvC,WAAW,CAAC,EAAE,OAAO,CAAA;KACtB;wBA5C8B,MAAM;0BAlDhC,MAAM,qCAIR;QAAE,eAAe,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,KACvE,OAAO,CAAC,WAAW,CAAC;mBAzBK,MAAM,KAAG,OAAO,CAAC,WAAW,CAAC;CAgI1D,CAAA"}
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAGjC,UAAU,WAAW;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,kBAAkB,GAAG,SAAS,CAAA;IAC3C,UAAU,EAAE,iBAAiB,GAAG,SAAS,CAAA;IACzC,IAAI,EAAE,QAAQ,CAAA;CACf;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,EAAE,WAAW,MAAM;mBAmJ5D,MAAM,kDAKR;QACD,eAAe,CAAC,EAAE,MAAM,CAAA;QACxB,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;QACvC,WAAW,CAAC,EAAE,OAAO,CAAA;KACtB;wBA5C8B,MAAM;0BAlDhC,MAAM,qCAIR;QAAE,eAAe,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,KACvE,OAAO,CAAC,WAAW,CAAC;mBAzBK,MAAM,KAAG,OAAO,CAAC,WAAW,CAAC;mBAqI7B,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;qBAqBpB,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;4BAsBhB,MAAM,UAAa,MAAM,KAAQ,OAAO,CAAC,MAAM,EAAE,CAAC;wBAiBrD,MAAM,KAAG,OAAO,CAAC,OAAO,CAAC;CAqB3D,CAAA"}
package/dist/api.js CHANGED
@@ -151,6 +151,80 @@ const createAutoFilesApi = (baseUrl, apiSecret) => {
151
151
  });
152
152
  return file.data;
153
153
  });
154
- return { getFile, isFileCached, getChunkedFile, getNode };
154
+ /**
155
+ * Bans a file by sending a request to the moderation service
156
+ * @param cid - The content identifier of the file to ban
157
+ * @returns A Promise that resolves when the file has been successfully banned
158
+ * @throws Error if the ban operation fails
159
+ */
160
+ const banFile = (cid) => __awaiter(void 0, void 0, void 0, function* () {
161
+ const response = yield authFetch(`${baseUrl}/moderation/${cid}/ban`, {
162
+ method: 'POST',
163
+ });
164
+ if (!response.ok) {
165
+ throw new Error(`Error banning file: ${response.status} ${response.statusText}`);
166
+ }
167
+ const result = yield response.json();
168
+ if (!result.success) {
169
+ throw new Error(`Failed to ban file: ${result.message || 'Unknown error'}`);
170
+ }
171
+ });
172
+ /**
173
+ * Unbans a file by sending a request to the moderation service
174
+ * @param cid - The content identifier of the file to unban
175
+ * @returns A Promise that resolves when the file has been successfully unbanned
176
+ * @throws Error if the unban operation fails
177
+ */
178
+ const unbanFile = (cid) => __awaiter(void 0, void 0, void 0, function* () {
179
+ const response = yield authFetch(`${baseUrl}/moderation/${cid}/unban`, {
180
+ method: 'POST',
181
+ });
182
+ if (!response.ok) {
183
+ throw new Error(`Error unbanning file: ${response.status} ${response.statusText}`);
184
+ }
185
+ const result = yield response.json();
186
+ if (!result.success) {
187
+ throw new Error(`Failed to unban file: ${result.message || 'Unknown error'}`);
188
+ }
189
+ });
190
+ /**
191
+ * Gets a list of banned files with pagination support
192
+ * @param page - The page number for pagination (optional, defaults to 1)
193
+ * @param limit - The number of files per page (optional, defaults to 10)
194
+ * @returns A Promise that resolves to an array of CIDs
195
+ * @throws Error if the request fails
196
+ */
197
+ const getBannedFiles = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (page = 1, limit = 10) {
198
+ const response = yield authFetch(`${baseUrl}/moderation/banned?page=${page}&limit=${limit}`);
199
+ if (!response.ok) {
200
+ throw new Error(`Error fetching banned files: ${response.status} ${response.statusText}`);
201
+ }
202
+ const result = yield response.json();
203
+ return result.bannedFiles;
204
+ });
205
+ /**
206
+ * Checks if a file is banned by querying the moderation service
207
+ * @param cid - The content identifier of the file to check
208
+ * @returns A Promise that resolves to true if the file is banned, false otherwise
209
+ * @throws Error if the status check fails
210
+ */
211
+ const isFileBanned = (cid) => __awaiter(void 0, void 0, void 0, function* () {
212
+ const response = yield authFetch(`${baseUrl}/moderation/${cid}/status`);
213
+ if (!response.ok) {
214
+ throw new Error(`Error checking file ban status: ${response.status} ${response.statusText}`);
215
+ }
216
+ const result = yield response.json();
217
+ return result.isBanned;
218
+ });
219
+ return {
220
+ getFile,
221
+ isFileCached,
222
+ getChunkedFile,
223
+ getNode,
224
+ banFile,
225
+ unbanFile,
226
+ getBannedFiles,
227
+ isFileBanned,
228
+ };
155
229
  };
156
230
  exports.createAutoFilesApi = createAutoFilesApi;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autonomys/auto-files",
3
- "version": "1.5.11",
3
+ "version": "1.5.13",
4
4
  "packageManager": "yarn@4.7.0",
5
5
  "scripts": {
6
6
  "build": "tsc"
@@ -21,7 +21,7 @@
21
21
  }
22
22
  },
23
23
  "dependencies": {
24
- "@autonomys/auto-drive": "^1.5.11"
24
+ "@autonomys/auto-drive": "^1.5.13"
25
25
  },
26
- "gitHead": "d23aab1111c5acf2388bf5e8e4f92c5eb8ba972a"
26
+ "gitHead": "ed410d97d09e708002b35264bf9f80faccc10d3b"
27
27
  }