{"bugs":{"url":"https://github.com/textileio/js-textile/issues"},"dist":{"shasum":"1e5b3e6cb90927cf5043fe66b276f8bfe3049a86","tarball":"https://registry.npmjs.org/@textile/hub/-/hub-2.0.0-alpha.0.tgz","fileCount":17,"integrity":"sha512-4FZsbE/Q2Mfzqsyqe7H7+sgzxOMDHyATFfsqL71p0K9ZaDGCB7Ls+4k1dTcxcqV1NwGpwMUScKSY7mnSQORuqA==","signatures":[{"sig":"MEUCIHVgb+mfbB4omsN2jBIoD55h1YiAYR3459Wey8rf/rb9AiEAl8+NiQ2xOnif5TxhBdu2xClK2FK0HCQ3emTWclNxzBQ=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":173779,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfwBFnCRA9TVsSAnZWagAA7XsP/iJrBu0PHvJYGqXqTfaN\nKuQuV24/BVc0SAH8EE9AU+XzbOQJlCAt4kG0Oo2WxQKJJB6gzZQmx3mlsnd3\ne2Ihf4v3dwc+vdetsxSo11EjplqqxGw7NkdlvI65hIkWpQAdJv7PNmw1M0w8\ncZGHRwZEZp12bQkBBl/vFy6p6XSCfpKpoAa8r5sB0Gs94M5lf6x46/i8IAVx\n5SswM7QhRU5+AmPcEoyFR6O6HlZQKlm5gxMLOZSCd8uDBvGbkFPuSBpZuwPu\nZAtREXStf7Hbmk80P81T2P/bdSxXzC528GCFKrbQPaClq+uT3phv5CwUa9IC\n27GpQ3H9HK6qi0JG3qJhu8xdkXg3rwNwR9grUXHnOY89xw5uc4xU96E/JfRS\ndgdmRq32cWjUy8cshEe+1RMOt3nCZ7cIpPbm05xCbL56eSudzRJlVweb0rFg\npImDdeOnA3F83S38OwiN9xj4+/yV6GCU0ui1DRuSwCTLyO58YsuWJ7Gx/87v\nDAEGJtWpqa94eoIusgZoi7osxYrGhH7SLA7mr/iXc80yv2C9pqeGzwknf0sP\nBhc3fiRxnhoHka7NYduHnlHe1Oe75VoS1g3veIHHpXSSYBee4UoFSb7nN3cN\nJtYRHRsSnO37D+dNtGvBFw6YvrEBP2L6Btq2yh/M6TGAuLkyouJAkKbp+YUy\npYrX\r\n=Xzwj\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index","name":"@textile/hub","types":"dist/index","author":{"name":"Textile"},"readme":"# Textile Hub\n\n> JS lib for interacting with Hub APIs\n\n## Introduction\n\n`@textile/hub` provides access to Textile APIs in apps based on Account Keys or User Group Keys. For details on getting keys, see [textileio/textile](https://docs.textile.io/hub/app-apis/) and for the full Textile documentation.\n\nJoin us on our [public Slack channel](https://slack.textile.io/) for news, discussions, and status updates. [Check out our blog](https://blog.textile.io/) for the latest posts and announcements.\n\n### Install\n\n```bash\nnpm install @textile/hub\n```\n\n## Usage\n\nThe Hub library contains three API clients: Users, Buckets, and Threads Client. You can use each of these to access the full set of APIs available on the Hub. To use any of them, you must first start by authenticating your app with the API.\n\n### Authentication & authorization\n\nAuthentication & authorization steps is the same no matter which API client you use, Users, Buckets or Threads Client. For most applications, this will happen in two parts.\n\n1. Authentication. In this step, you will use your User Group keys or Account keys to gain access to the Hub API.\n2. User token generation. In this step, you will assign a unique API token to a new user of your app, to grant them access to your resources on the Hub.\n\n[Read more on authenticating users here](https://docs.textile.io/tutorials/hub/web-app/).\n\nThere are two commonly used object types for passing authentication parameters to the Hub library: `UserAuth` and `KeyInfo`.\n\n#### UserAuth\n\n`UserAuth` objects can be generated to provide Hub API access to your users inside of your application. Review the tutorial linked above on setting up a UserAuth providing endpoint.\n\n```typescript\nimport { UserAuth } from '@textile/hub'\n\nconst auth: UserAuth = {\n  msg: '<api msg>',\n  sig: '<api sig>',\n  token: '<user msg>',\n  key: '<api key>',\n}\n```\n\n#### KeyInfo\n\nThe `KeyInfo` object holds your API secret and so should never be used in an insecure environment (such as in an application). You can use `KeyInfo` with an insecure key (signing not required) from the api by leaving `secret` off.\n\n```typescript\nimport { KeyInfo } from '@textile/hub'\n\nconst auth: KeyInfo = {\n  key: '<api key>',\n  secret: '<api secret>'\n}\n```\n\n#### Examples\n\n**Developer Account Auth**\n\nCreate a database client using the Textile Hub and account keys.\n\n```typescript\nimport { Client, KeyInfo } from '@textile/hub'\n\nasync function start () {\n  const keyInfo: KeyInfo = {\n    key: '<api key>',\n    secret: '<api secret>'\n  }\n  const client = await Client.withKeyInfo(keyInfo)\n}\n```\n\n**User Account Auth**\n\nCreate a database client using the Textile Hub and user group keys.\n\n```typescript\nimport { Client, UserAuth } from '@textile/hub'\n\nfunction start (callback: () => Promise<UserAuth>) {\n  const client = Client.withUserAuth(callback)\n  return client\n}\n```\n\n**Transfer Auth**\n\nYou can transfer authentication & authorization between Users and Buckets API clients below by using their respective `copyAuth` methods.\n\nFor example, copying a setup Users client to Buckets\n\n```typescript\nimport { Buckets, Users } from '@textile/hub'\n\nconst usersToBuckets = async (users: Users) => {\n  const buckets = Buckets.copyAuth(users)\n  return buckets\n}\n```\n\nAn inversely, copying a Bucket session to Users client.\n\n```typescript\nimport { Buckets, Users } from '@textile/hub'\n\nconst bucketsToUsers = async (buckets: Buckets) => {\n  const user = Users.copyAuth(buckets)\n  return user\n}\n```\n\n### Users client\n\nThe Users client allows you to access a local (in your app) user's account information, such as a list of all their threads in your app. It also gives you access to a per-user inboxing API for transferring messages between your users based on simple private key identities.\n\n[Read the full client docs here](https://textileio.github.io/js-textile/docs/hub.users).\n\n**List a user's threads**\n\n```typescript\nimport { Users } from '@textile/hub'\n\nasync function list (users: Users) {\n  const threads = await users.listThreads()\n}\n```\n\n**Setup a user's mailbox**\n\n```typescript\nimport { Users } from \"@textile/hub\"\n\nasync function example(users: Users) {\n   return await users.setupMailbox()\n}\n```\n\n**Send message to another user by public key**\n\n```typescript\nimport { Users, Identity, PublicKey  } from \"@textile/hub\"\n\nasync function example(users: Users, from: Identity, to: PublicKey, message: string) {\n  const encoder = new TextEncoder()\n  const body = encoder.encode(message)\n  return await users.sendMessage(from, to, body)\n}\n```\n\n### ThreadDB client\n\nThreads client to access remote threads, create new threads, add and remove data.\n\n[Read the full client docs here](https://textileio.github.io/js-textile/docs/hub.client).\n\n**Create a thread**\n\n```typescript\nimport { Client, ThreadID } from '@textile/hub'\n\nasync function start (client: Client, schema: any) {\n  /**\n   * Setup a new ThreadID and Database\n   */\n  const threadId = ThreadID.fromRandom();\n\n  /**\n   * Each new ThreadID requires a `newDB` call.\n   */\n  await client.newDB(threadId)\n\n  /**\n   * We add our first Collection to the DB for any schema.\n   */\n  await client.newCollection(threadId, { name: 'Astronaut', schema });\n}\n```\n\n**Insert data**\n\n```typescript\nimport { Client, ThreadID } from '@textile/hub'\n\nasync function createEntity (client: Client, threadId: ThreadID, jsonData: any) {\n  /**\n   * Add a new Astronaut\n   *\n   * Our Thread contains the Astronaut Collection, so you just need\n   * to add a new astronaut that matches the expected schema.\n   *\n   * If you run this app many times, you'll notice many Buzz Aldrin\n   * entries in your ThreadDB, each with a unique ID.\n   */\n  const ids = await client.create(threadId, 'Astronaut', [\n    jsonData,\n  ]);\n}\n```\n\n### Buckets client\n\nCreate, manage, and publish user and account Buckets.\n\n[Read the full client docs here](https://textileio.github.io/js-textile/docs/hub.buckets).\n\n**Create a new Bucket client**\n\n```typescript\nimport { Buckets, UserAuth } from '@textile/hub'\n\n/**\n * Create a Bucket client instance with the same auth\n * methods used for threads\n */\nasync function start (callback: () => Promise<UserAuth>) {\n  const buckets = Buckets.withUserAuth(callback)\n  return buckets\n}\n```\n\n**Read existing Buckets**\n\n```typescript\nimport { Buckets } from '@textile/hub'\n\nasync function run (buckets: Buckets) {\n  /**\n   * List existing Buckets\n   */\n  const roots = await buckets.list();\n  const existing = roots.find((bucket) => bucket.name === 'files')\n\n  /**\n   * If a Bucket named 'files' already existed for this user, use it.\n   * If not, create one now.\n   */\n  let bucketKey = ''\n  if (existing) {\n    bucketKey = existing.key;\n  } else {\n    const created = await buckets.create('files');\n    bucketKey = created.root ? created.root.key : ''\n  }\n  return bucketKey\n}\n```\n\n**Add files to Buckets**\n\n```typescript\nimport { Buckets, UserAuth } from '@textile/hub'\n\nasync function add (buckets: Buckets, webpage: string, bucketKey: string) {\n  /**\n   * Add a simple file Buffer\n   *\n   * Alternative formats are here: https://github.com/textileio/js-textile/blob/master/src/normalize.ts#L14\n   *\n   * We add the file as index.html so that we can render it right in the browser afterwards.\n   */\n  const file = { path: '/index.html', content: Buffer.from(webpage) }\n\n  /**\n   * Push the file to the root of the Files Bucket.\n   */\n  const raw = await buckets.pushPath(bucketKey, 'index.html', file)\n}\n```\n","gitHead":"37f028824ba54b49b1c5b53328c8e31d688f931d","license":"MIT","scripts":{"build":"tsc -b tsconfig.json","clean":"rimraf ./dist ./tsconfig.tsbuildinfo","prepare":"npm run build","prebuild":"npm run clean","test:browser":"polendina --cleanup --timeout 60 src/**/*.spec.ts --webpack-config ../../webpack.test.js","prepublishOnly":"npm run build"},"_npmUser":{"name":"carsonfarmer","email":"carson@textile.io"},"homepage":"https://github.com/textileio/js-textile#readme","references":[{"path":"../buckets"},{"path":"../users"},{"path":"../crypto"},{"path":"../hub-threads-client"},{"path":"../pow"}],"repository":{"url":"git+https://github.com/textileio/js-textile.git","type":"git"},"_npmVersion":"lerna/3.22.1/node@v13.10.1+x64 (darwin)","description":"web-gRPC wrapper client for communicating with Textile Hub.","directories":{},"maintainers":[{"name":"asutula","email":"aaron@textile.io"},{"name":"carsonfarmer","email":"carson@textile.io"},{"name":"andrewxhill","email":"andrew@textile.io"},{"name":"sanderpick","email":"sanderpick@gmail.com"},{"name":"textileio","email":"sander@textile.io"}],"_nodeVersion":"13.10.1","dependencies":{"loglevel":"^1.6.8","multihashes":"0.4.19","@textile/pow":"^2.0.0-alpha.0","@textile/users":"^2.0.0-alpha.0","@textile/crypto":"^1.0.0-alpha.0","@textile/buckets":"^2.0.0-alpha.0","@textile/hub-grpc":"2.1.7","@textile/security":"^0.5.0","@textile/threads-id":"^0.2.0","@textile/hub-threads-client":"^2.0.0-alpha.0","@textile/grpc-authentication":"^1.0.0-alpha.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"axios":"^0.20.0","delay":"^4.4.0","rimraf":"^3.0.2","multibase":"^3.1.0","typescript":"^3.9.3","fast-sha256":"^1.3.0","@textile/context":"^0.8.1","@textile/hub-grpc":"2.1.7","@textile/grpc-transport":"^0.1.0"},"_npmOperationalInternal":{"tmp":"tmp/hub_2.0.0-alpha.0_1606422887209_0.7880854447895753","host":"s3://npm-registry-packages"},"_id":"@textile/hub@2.0.0-alpha.0","version":"2.0.0-alpha.0"}