{"id":32689379,"url":"https://github.com/hazbase/storage","last_synced_at":"2026-03-15T07:03:54.006Z","repository":{"id":314288787,"uuid":"1054920638","full_name":"hazbase/storage","owner":"hazbase","description":"A lightweight SDK for the hazBase IPFS storage API (backed by Pinata).","archived":false,"fork":false,"pushed_at":"2025-10-28T19:36:29.000Z","size":91,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-11T11:17:31.491Z","etag":null,"topics":["backend","blockchain","dapps","ethereum","evm","ipfs","storage","web3"],"latest_commit_sha":null,"homepage":"https://lp.hazbase.com","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hazbase.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-11T14:09:23.000Z","updated_at":"2025-10-28T19:36:33.000Z","dependencies_parsed_at":"2025-09-11T17:14:04.141Z","dependency_job_id":"c8a0660d-98a1-4f18-879e-fe5712a8e4a8","html_url":"https://github.com/hazbase/storage","commit_stats":null,"previous_names":["hazbase/storage"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/hazbase/storage","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazbase%2Fstorage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazbase%2Fstorage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazbase%2Fstorage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazbase%2Fstorage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hazbase","download_url":"https://codeload.github.com/hazbase/storage/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazbase%2Fstorage/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30537152,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-15T06:53:40.532Z","status":"ssl_error","status_checked_at":"2026-03-15T06:51:47.131Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["backend","blockchain","dapps","ethereum","evm","ipfs","storage","web3"],"created_at":"2025-11-01T13:00:59.408Z","updated_at":"2026-03-15T07:03:54.001Z","avatar_url":"https://github.com/hazbase.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @hazbase/storage\n[![npm version](https://badge.fury.io/js/@hazbase%2Fstorage.svg)](https://badge.fury.io/js/@hazbase%2Fstorage)\n[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\n## Overview\n`@hazbase/storage` is a lightweight **SDK for the hazBase IPFS storage API** (backed by Pinata).  \nIt works in **browsers and Node.js** and provides concise functions for **pinning (upload)**, **unpinning (delete)**, and **building public gateway URLs**.  \nUnder the hood, it integrates with `@hazbase/auth` to **validate your client key**.\n\n- Base endpoint: `{{API_ENDPOINT}}/api/ipfs/*` (configure via `@hazbase/auth`)\n- Main functions: `pinFile(files)`, `unpin(cid)`, `gatewayUrl(cid)`\n- Internals: Node uses `formdata-node` and `form-data-encoder` for streaming `FormData`\n\n---\n\n## Requirements\n- **Node.js**: 18+ (built‑in `fetch` / `ReadableStream` / `duplex: \"half\"`)\n- **TypeScript**: 5+ (recommended)\n- **Runtime**: Browser or Node.js\n\n---\n\n## Installation\n```bash\nnpm i @hazbase/storage @hazbase/auth\n# or\npnpm add @hazbase/storage @hazbase/auth\n```\n\n---\n\n## Pre‑setup (Client key)\n`@hazbase/storage` does not read environment variables directly. Configure **@hazbase/auth** once at app start.\n\n```ts\n// All comments in English (project convention)\nimport { setClientKey } from '@hazbase/auth';\n\nsetClientKey(process.env.HAZBASE_CLIENT_KEY!);               // required for validation \u0026 logging\n```\n\n---\n\n## Quick start\n\n### A) Pin files from a browser (`\u003cinput type=\"file\"\u003e`)\n```ts\nimport { pinFile, gatewayUrl } from '@hazbase/storage';\n\nasync function onUpload(e: Event) {\n  const input = e.target as HTMLInputElement;\n  const files = Array.from(input.files ?? []);\n\n  // 1) Pin files to IPFS\n  const results = await pinFile(files, { name: 'my-assets', folder: 'v1' });\n\n  // 2) Show gateway URLs\n  for (const r of results) {\n    console.log('CID:', r.cid, 'URL:', gatewayUrl(r.cid));\n  }\n}\n```\n\n### B) Pin a buffer from Node.js\n```ts\nimport { readFile } from 'node:fs/promises';\nimport { pinFile } from '@hazbase/storage';\n\nconst buf  = await readFile('./image.png');\nconst res  = await pinFile([buf], { name: 'image.png', contentType: 'image/png' });\nconsole.log(res[0].cid);\n```\n\n### C) Unpin a CID (remove from storage)\n```ts\nimport { unpin } from '@hazbase/storage';\n\nawait unpin('bafybeigdyrzt...'); // Remove from Pinata (via HAZAMA BASE API)\n```\n\n---\n\n## Function reference\n\n### `pinFile(files, opts?) =\u003e Promise\u003cPinResult[]\u003e`\n- **What it does**: Accepts `File[] | Blob[] | Buffer[]`, posts to `/api/ipfs/pinFiles`, and returns **CIDs**.\n- **Params**\n  - `files`: `File[] | Blob[] | Buffer[]`\n  - `opts?`: `UploadOptions` (`name?: string`, `folder?: string`, `contentType?: string`)\n- **Returns**: `PinResult[]` (at minimum includes `{ cid: string }`)\n\n**Example**\n```ts\n// Pin multiple assets\nconst pinned = await pinFile([file1, file2], { name: 'batch-2025-09-11', folder: 'assets' });\n```\n\n---\n\n### `unpin(cid: CID) =\u003e Promise\u003cany\u003e`\n- **What it does**: **Unpins** an existing CID.\n- **Params**: `cid: string` (CIDv0/v1)\n- **Returns**: backend response object (Pinata `unpin` equivalent)\n\n**Example**\n```ts\nawait unpin('bafybeigdyrzt...');\n```\n\n---\n\n### `gatewayUrl(cid: CID, gateway?: string) =\u003e string`\n- **What it does**: Returns a public **gateway URL** by concatenating a base (default: `https://gateway.pinata.cloud/ipfs/`) with the CID.\n- **Example**\n```ts\nconst url = gatewayUrl('bafybeigdyrzt...'); \n// -\u003e https://gateway.pinata.cloud/ipfs/bafybeigdyrzt...\n```\n\n---\n\n## Types (summary)\n```ts\n// Basic aliases\nexport type CID = string;\n\nexport interface UploadOptions {\n  /** Optional logical name for the batch/file */\n  name?: string;\n  /** Optional folder tag (Pinata metadata keyvalues.folder) */\n  folder?: string;\n  /** Content-Type (used for Node Buffer uploads) */\n  contentType?: string;\n}\n\nexport interface PinResult {\n  /** Content identifier returned by IPFS/Pinata */\n  cid: CID;\n  /** Optional fields may be present (e.g., size, isDuplicate, name) */\n  [k: string]: any;\n}\n```\n\n\u003e The response can be extended by your backend. Design for at least a `cid` field.\n\n---\n\n## Error handling\n- On HTTP errors, `request()` throws `Error(status, statusText, body)` (e.g., `Pinata POST /pinFiles: 401 Unauthorized ...`).\n- `pinFile` / `unpin` propagate exceptions. In UIs, add **retry** and **user‑visible messages**.\n\n---\n\n## Best practices\n- **Key hygiene**: call `setClientKey()` at app startup. In browsers, persist as little as possible.\n- **CORS**: if you call the API directly from browsers, ensure environment‑appropriate CORS settings.\n- **Large files**: uploads \u003e100MB take longer. Provide progress UI and consider chunking/multipart strategies.\n- **Public URLs**: if you change the default gateway, consider CDN/LB in front of it.\n\n---\n\n## Troubleshooting\n- **`Client key not set`**: call `setClientKey()` first.\n- **`Nonce request failed`**: sign‑in/validation may be failing; recheck `@hazbase/auth` setup.\n- **`403/401`**: client‑key privileges or expiration; reissue or switch environment.\n- **`TypeError: fetch failed`**: network/proxy or server routing to `/api/ipfs` is broken.\n\n---\n\n## License\nApache-2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhazbase%2Fstorage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhazbase%2Fstorage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhazbase%2Fstorage/lists"}