{"_id":"@demonswap/profile-sdk","_rev":"1-ae457b5395a4a51cef56b9936f243693","name":"@demonswap/profile-sdk","dist-tags":{"latest":"0.3.0"},"versions":{"0.3.0":{"name":"@demonswap/profile-sdk","version":"0.3.0","main":"dist/index.cjs.js","module":"dist/index.esm.js","types":"dist/index.d.ts","license":"MIT","repository":{"type":"git","url":"https://github.com/demonswap/demon-toolkit/tree/master/packages/demon-profile-sdk"},"scripts":{"build":"rm -rf ./dist && rollup -c && tsc -d --emitDeclarationOnly --declarationDir dist","start":"yarn build && node ./dist","test":"jest","test:coverage":"jest --collectCoverage","lint":"eslint 'src/**/*.{js,jsx,ts,tsx}'","format:check":"prettier --check --loglevel error 'src/**/*.{js,jsx,ts,tsx}'","format:write":"prettier --write 'src/**/*.{js,jsx,ts,tsx}'"},"devDependencies":{"@babel/preset-env":"^7.13.15","@babel/preset-typescript":"^7.13.0","@rollup/plugin-commonjs":"^18.0.0","@rollup/plugin-image":"^2.0.6","@rollup/plugin-node-resolve":"^11.2.1","@types/jest":"^26.0.22","@types/node":"^14.14.39","babel-jest":"^26.6.3","ethers":"^5.1.4","graphql":"^15.5.0","graphql-request":"^3.4.0","jest":"^26.6.3","msw":"^0.28.1","node-fetch":"^2.6.1","ts-jest":"^26.5.4"},"peerDependencies":{"ethers":"^5.1.4","graphql":"^15.5.0","graphql-request":"^3.4.0"},"dependencies":{"@types/js-cookie":"^2.2.6","js-cookie":"^2.2.1"},"description":"This package provides some handy functions to retrieve data for Demonswap Profile system.","_id":"@demonswap/profile-sdk@0.3.0","dist":{"shasum":"bc29ef9e76281f488356fc0f2148293e220945d9","integrity":"sha512-DpnUnr5wjFyZrGlyZdZ3lajSA++A/9VSx8LH+frUCmiorW8cobz5mr7GJw+E1XZ1lb3ztONEGgH0LL6IqrHWlQ==","tarball":"https://registry.npmjs.org/@demonswap/profile-sdk/-/profile-sdk-0.3.0.tgz","fileCount":84,"unpackedSize":461990,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhQAPJCRA9TVsSAnZWagAAYAAP/37O3oIU/VCfaAD1o6ZK\nW9spcPHoM0BxhHzCuLHjOTWCQlDaEMJOlDnxr/1foLICCGw8f8qWYAs4W9Mv\nY83e3atg9gSf0nFgOFV8I/+CAWEE+Qv6Jj4klmh2m0c54X20iJwThaNqAxnd\n54Q2V00gLpWqqzp7yFI7AqMNOl4JnOqOOgYeOmV6q5vlzlZCd8quEusAKNW3\nszz23kv+kKunjD6oOrQwj0nT/xEikd1aZj+/xDr2ZfG41JBrwY9mZcx0PR7u\nuZb3zaAfqkAE+a+QvdmlObJdJ+yE4SVvCuXrv9iUU/OshYgUWIJTCd+iQq49\nU+k5pesfrNPBltMLIhx8sstc+pcgi8GvLd7AB14ZV2sraY5NPGLTeUtdnlET\nrNf3Jcgdgn05rqvUtKa8jPjYJi0ESqW7OtCpxmgUwRILVJPkktO+RoCDqbEu\noPu4o3qkuSsdM1AvY5kWJl+eXLoCfr17zjtAJfRQBZwcta/qCeRxvmURNV3z\nCtBqS84NBIN5T6v/gYxiSj0MfRtZ9R/OBeSX3NcQ+55D4o3BVE9RCPcrMuZi\nm52K8S+URRHEvKYbhr+Awi3k5eEMVt+6HheW+4rSVSc5na4qlJcw7UQWlu6h\nYYAe2u8vn4WU0VMA1iOqgiO6TcyGd7TtjU6gz4/S/jQdpzKJH2tdg00J1j6T\n+/zx\r\n=XPSp\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDGCoOJKDQjIkrT7jfRAgrUoobu1HLw7hilGNtCYljpVAiBOF1A90XY0PCnvnXi5fgdeAujzO8WPpJCNmfrMYIcDcQ=="}]},"_npmUser":{"name":"0xquo","email":"0xstatuquo@gmail.com"},"directories":{},"maintainers":[{"name":"0xmysee","email":"0xmysee@protonmail.com"},{"name":"0xquo","email":"0xstatuquo@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/profile-sdk_0.3.0_1631585224787_0.041577673300075446"},"_hasShrinkwrap":false}},"time":{"created":"2021-09-14T02:07:04.702Z","0.3.0":"2021-09-14T02:07:05.003Z","modified":"2022-04-05T03:44:12.745Z"},"maintainers":[{"name":"0xmysee","email":"0xmysee@protonmail.com"},{"name":"0xquo","email":"0xstatuquo@gmail.com"}],"description":"This package provides some handy functions to retrieve data for Demonswap Profile system.","repository":{"type":"git","url":"https://github.com/demonswap/demon-toolkit/tree/master/packages/demon-profile-sdk"},"license":"MIT","readme":"# Demonswap Profile SDK\n\nThis package provides some handy functions to retrieve data for Demonswap Profile system.\n\n##### Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Initialization](#initialization)\n  - [getUsername](#getUsername)\n  - [getTeam](#getTeam)\n  - [getProfile](#getProfile)\n  - [getAchievements](#getAchievements)\n- [Roadmap](#roadmap)\n\n## Installation\n\nInstall `@demonswap/profile-sdk` into your project with npm:\n\n```bash\nnpm install @demonswap/profile-sdk --save\n```\n\nor yarn:\n\n```bash\nyarn add @demonswap/profile-sdk\n```\n\nThis package requires `ethers`, `graphql` and `graphql-request` to be installed in your project.\n\n```bash\n# npm\nnpm install ethers graphql graphql-request --save\n# yarn\nyarn add ethers graphql graphql-request\n```\n\n## Usage\n\n### Initialization\n\nFirst set is to initialize the SDK with the following:\n\n```js\nimport DemonProfileSdk from \"@demonswap/profile-sdk\";\n\nconst demonSdk = new DemonProfileSdk();\n```\n\nYou can pass optional arguments to the constructor:\n\n- `provider` - custom RPC Provider instance if you want to use custom configuration, if not provided defaults to provider with random node from the [list of RPC nodes](src/utils/getRpcUrl.ts)\n- `chainId` - what chain ID to use, if not provided defaults to `56`\n\n```js\nimport DemonProfileSdk from \"@demonswap/profile-sdk\";\nimport { ethers } from \"ethers\";\n\nconst customProvider = new ethers.providers.JsonRpcProvider(\"https://example.com\");\n\nconst demonSdk = new DemonProfileSdk(customProvider, 97);\n```\n\n### getUsername\n\nReturns username for a given address. If the address does not have a profile or there is an error - returns empty string `\"\"`.\n\n```js\nimport DemonProfileSdk from \"@demonswap/profile-sdk\";\n\nconst demonSdk = new DemonProfileSdk();\nconst username = demonSdk.getUsername(\"0x123456789\");\nconsole.log(username); // \"Matatabi\"\n```\n\n### getTeam\n\nReturns team information for the team ID. In case of network error returns null. Note that at the moment `points` will return `0` for all teams (total team points will be calculated soon).\n\n```js\nimport DemonProfileSdk from \"@demonswap/profile-sdk\";\n\nconst demonSdk = new DemonProfileSdk();\nconst team = demonSdk.getTeam(1);\nconsole.log(team);\n// {\n//   id: 1,\n//   name: \"Syrup Storm\",\n//   description: \"The storm's a-comin! Watch out! These bulls are stampeding in a syrupy surge!\",\n//   isJoinable: true,\n//   users: 55123;\n//   points: 182500;\n//   images: images: {\n//     lg: \"syrup-storm-lg.png\",\n//     md: \"syrup-storm-md.png\",\n//     sm: \"syrup-storm-sm.png\",\n//     alt: \"syrup-storm-alt.png\",\n//     ipfs: \"https://gateway.pinata.cloud/ipfs/QmXKzSojwzYjtDCVgR6mVx7w7DbyYpS7zip4ovJB9fQdMG/syrup-storm.png\",\n//   },\n//   background: syrup-storm-bg.svg;\n//   textColor: \"#191326\";\n// }\n```\n\n### getProfile\n\nReturns full profile data for a given address. Under the hood retrieves username and team data using `getUsername` and `getTeam` and combines it with data from the profile contract. If address does not have a profile - returns `{ hasRegistered: false, profile: null }`. At the moment does not retrieve achievements (see [getAchievements](#getAchievements)).\n\nIt also sets `profile_${address}` cookie containing username and avatar (now only for demonswap.fi domain, maybe configurable in future versions)\n\n```js\nimport DemonProfileSdk from \"@demonswap/profile-sdk\";\n\nconst demonSdk = new DemonProfileSdk();\nconst profile = demonSdk.getProfile(\"0x123456789\");\nconsole.log(profile);\n// {\n//   hasRegistered: true\n//   profile: {\n//     userId: 6173,\n//     points: 2500,\n//     teamId: 1,\n//     nftAddress: \"0x11111111\",\n//     tokenId: 15,\n//     isActive: true,\n//     username: \"Matatabi\",\n//     nft: {\n//       name: \"Hiccup\",\n//       description: \"Oopsie daisy! Hiccup's had a bit of an accident. Poor little fella.\",\n//       images: {\n//         lg: \"hiccup-lg.png\",\n//         md: \"hiccup-md.png\",\n//         sm: \"hiccup-sm.png\",\n//         ipfs: \"https://gateway.pinata.cloud/ipfs/QmQ6EE6gkVzAQUdQLLM7CyrnME6LZHCoy92ZERW8HXmyjw/hiccup.png\",\n//       },\n//       sortOrder: 999,\n//       identifier: 'hiccup'\n//       type: 'demon',\n//       variationId: 10\n//     },\n//     team: {\n//       id: 1,\n//       name: \"Syrup Storm\",\n//       description: \"The storm's a-comin! Watch out! These bulls are stampeding in a syrupy surge!\",\n//       isJoinable: true,\n//       users: 55123,\n//       points: 182500,\n//       images: images: {\n//         lg: \"syrup-storm-lg.png\",\n//         md: \"syrup-storm-md.png\",\n//         sm: \"syrup-storm-sm.png\",\n//         alt: \"syrup-storm-alt.png\",\n//         ipfs: \"https://gateway.pinata.cloud/ipfs/QmXKzSojwzYjtDCVgR6mVx7w7DbyYpS7zip4ovJB9fQdMG sy  rup-storm.png\",\n//       },\n//       background: syrup-storm-bg.svg,\n//       textColor: \"#191326\"\n//     },\n//     hasRegistered: true\n//   }\n// }\n```\n\n### getAchievements\n\nReturns array of achievements for a given address. If address has no achievements or no profile at all - returns empty array `[]`.\n\n```js\nimport DemonProfileSdk from \"@demonswap/profile-sdk\";\n\nconst demonSdk = new DemonProfileSdk();\n\nconst achievements = demonSdk.getAchievements(\"0x123456789\");\nconsole.log(achievements);\n// [\n//   {\n//     id: \"511080000\",\n//     type: \"ifo\",\n//     address: \"0x123456789\",\n//     title: {\n//       id: 999,\n//       fallback: `IFO Shopper: Belt`,\n//       data: {\n//         name: \"Belt\",\n//       },\n//     },\n//     description: {\n//       id: 999,\n//       fallback: `Committed more than $5 worth of LP in the Belt IFO`,\n//       data: {\n//         name: \"Belt\",\n//       },\n//     },\n//     badge: \"ifo-belt.svg\",\n//     points: 200,\n//   },\n//   {\n//     id: \"512010010\",\n//     type: \"teambattle\",\n//     address: \"0x123456789\",\n//     title: \"Easter Participant: Silver\",\n//     badge: \"easter-participant-silver.svg\",\n//     points: 500,\n//   },\n// ];\n```\n\n### Using images\n\nThis package bundles some images within itself, it exports `achievementBadges` and `teamImages` which are javascript objects with keys matching the image names returned by the API (e.g. `\"syrup-storm-md.png\"`) and values are Base64 encoded images:\n\n```JSX\nimport { Team, teamImages } from \"@demonswap/profile-sdk\";\n\nconst team = demonSdk.getTeam(1);\n// ...\nreturn <img src={teamImages[team.images.md]} alt={team.name} width=\"96px\" height=\"96px\" />\n```\n\nAlso `bunnyPlaceholder` image is exported to provide fallback for e.g. unregistered users.\n\n## Roadmap\n\nCurrent version of this SDK is 90% copy of existing from [demon-frontend](https://github.com/demonswap/demon-frontend) repo. There are several improvements to be made in the future versions of this SDK:\n\n- [ ] Better error handling (common bad status codes or broken internet connection)\n- [ ] Allow username & avatar cookie to be configurable or optional\n- [ ] Validate addresses and don't attempt to fetch data if address is not valid\n- [ ] NodeJS support. Currently it works out of the box only in browser. Need to research different options for cross-fetch and choose the one that provides less friction and increases bundle size the least.\n","readmeFilename":"README.md"}