{"id":25428771,"url":"https://github.com/weavevm/bundler-upload-sdk","last_synced_at":"2025-05-14T08:35:05.872Z","repository":{"id":275611964,"uuid":"925142075","full_name":"weaveVM/bundler-upload-sdk","owner":"weaveVM","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-07T08:44:23.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-07T09:37:43.895Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/weaveVM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-31T10:06:31.000Z","updated_at":"2025-03-07T08:44:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"24843212-8bb6-4319-ac3e-1a16b45fc435","html_url":"https://github.com/weaveVM/bundler-upload-sdk","commit_stats":null,"previous_names":["weavevm/bundler-upload-sdk"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weaveVM%2Fbundler-upload-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weaveVM%2Fbundler-upload-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weaveVM%2Fbundler-upload-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weaveVM%2Fbundler-upload-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weaveVM","download_url":"https://codeload.github.com/weaveVM/bundler-upload-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254104679,"owners_count":22015521,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-17T01:47:32.496Z","updated_at":"2025-05-14T08:35:05.863Z","avatar_url":"https://github.com/weaveVM.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bundler SDK\n\nA JavaScript SDK for interacting with the Bundler upload service.\n\n## Installation\n\n```bash\nnpm install bundler-upload-sdk\n```\n\n## Usage\n\n### Node.js\n\n```javascript\nimport { BundlerSDK } from 'bundler-upload-sdk';\n\n// Initialize the SDK with your endpoint and API key\nconst bundler = new BundlerSDK('http://127.0.0.1:8000', 'your-api-key');\n\n// Upload multiple files with their associated tags\ntry {\n  const txHash = await bundler.upload([\n    {\n      file: paperFileBuffer,\n      tags: {\n        'content-type': 'text/plain',\n        'filename': 'paper.txt'\n      }\n    },\n    {\n      file: woodFileBuffer,\n      tags: {\n        'content-type': 'text/plain',\n        'filename': 'wood.txt'\n      }\n    }\n  ]);\n  console.log('Upload successful! Transaction hash:', txHash);\n} catch (error) {\n  console.error('Upload failed:', error.message);\n}\n\n// Upload a single file with tags\ntry {\n  const txHash = await bundler.upload([\n    {\n      file: fileBuffer,\n      tags: {\n        'content-type': 'image/jpeg',\n        'category': 'photos',\n        'userId': '123'\n      }\n    }\n  ]);\n  console.log('Upload successful! Transaction hash:', txHash);\n} catch (error) {\n  console.error('Upload failed:', error.message);\n}\n```\n\n### Browser\n\nFor browser environments, you need to use the browser-specific version of the SDK:\n\n```javascript\nimport { BundlerSDK } from 'bundler-upload-sdk/browser';\n\n// Initialize the SDK with your endpoint and API key\nconst bundler = new BundlerSDK('http://127.0.0.1:8000', 'your-api-key');\n\n// Example: Upload a file from a file input element\ndocument.getElementById('fileInput').addEventListener('change', async (event) =\u003e {\n  const file = event.target.files[0];\n  if (!file) return;\n  \n  try {\n    const txHash = await bundler.upload([\n      {\n        file: file,\n        tags: {\n          'content-type': file.type,\n          'filename': file.name\n        }\n      }\n    ]);\n    console.log('Upload successful! Transaction hash:', txHash);\n  } catch (error) {\n    console.error('Upload failed:', error.message);\n  }\n});\n\n// Example: Upload a Blob created in the browser\nconst blob = new Blob(['Hello, world!'], { type: 'text/plain' });\ntry {\n  const txHash = await bundler.upload([\n    {\n      file: blob,\n      tags: {\n        'content-type': 'text/plain',\n        'filename': 'hello.txt'\n      }\n    }\n  ]);\n  console.log('Upload successful! Transaction hash:', txHash);\n} catch (error) {\n  console.error('Upload failed:', error.message);\n}\n```\n\n## API Reference\n\n### `new BundlerSDK(endpoint, apiKey)`\n\nCreates a new BundlerSDK instance.\n\n- `endpoint` (string): The API endpoint URL\n- `apiKey` (string): The API key for authentication\n\n### `upload(uploads)`\n\nUploads one or more files with their associated tags.\n\n- `uploads` (Array): An array of upload objects, each containing:\n  - `file`: The file to upload\n    - In Node.js: Can be a Buffer, Blob, or File object\n    - In browser: Can be a Blob or File object\n  - `tags` (Object, optional): Key-value pairs of tags to attach to the file\n- Returns: Promise\u003cstring\u003e - Resolves with the transaction hash\n- Throws: Error if the upload fails or network error occurs\n\n### Usage in different environments\n\n#### Node.js\n```javascript\nimport { BundlerSDK } from 'bundler-upload-sdk';\n```\n\n#### Browser\n```javascript\nimport { BundlerSDK } from 'bundler-upload-sdk/browser';\n```\n\n#### Bundlers (Webpack, Rollup, etc.)\nThe package.json includes the `browser` field, so most bundlers will automatically use the browser version when bundling for browser environments.\n\nExample curl command equivalent to the SDK usage:\n```bash\ncurl -X POST http://127.0.0.1:8000/upload \\\n  -H \"Authorization: your-api-key\" \\\n  -F \"file=@paper.txt\" \\\n  -F \"tag_content-type=text/plain\" \\\n  -F \"tag_filename=paper.txt\" \\\n  -F \"file=@wood.txt\" \\\n  -F \"tag_content-type=text/plain\" \\\n  -F \"tag_filename=wood.txt\"\n```\n\n## Error Handling\n\nThe SDK throws errors in the following cases:\n- Missing required parameters (endpoint, apiKey)\n- Empty uploads array or missing files\n- Network errors during upload\n- Server errors (non-200 responses)\n- Invalid or missing API key\n- Malformed server response\n\n## Development\n\nThe Node.js version of this SDK uses:\n- `form-data` for handling multipart form data uploads\n- `node-fetch` for making HTTP requests\n\nThe browser version uses native browser APIs:\n- Built-in fetch API for making HTTP requests\n- Built-in FormData API for multipart form data uploads\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweavevm%2Fbundler-upload-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweavevm%2Fbundler-upload-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweavevm%2Fbundler-upload-sdk/lists"}