{"_id":"@buffalodark/profile-sdk","_rev":"1-736719affb9f1ee720180c42c7d5510a","name":"@buffalodark/profile-sdk","dist-tags":{"latest":"0.4.0"},"versions":{"0.4.0":{"name":"@buffalodark/profile-sdk","version":"0.4.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/buffalodark/buffalodark-toolkit/tree/master/packages/buffalodark-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 Pancakeswap Profile system.","_id":"@buffalodark/profile-sdk@0.4.0","dist":{"shasum":"dc1be4d2e730f5a089dfaf3511a0435792be5af6","integrity":"sha512-LribTTdshWQh2y/jf2kiGfcoOe9UvQkmCyfDrh8RNpPwvoYI7e1UsBA0Clunq32+JSZh0i62+krY6Wz0kGcIfA==","tarball":"https://registry.npmjs.org/@buffalodark/profile-sdk/-/profile-sdk-0.4.0.tgz","fileCount":105,"unpackedSize":1497878,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhIAeBCRA9TVsSAnZWagAA8eYP/RcfMfaaQtsKFd/7sDg0\nWwtCZjqRQiLac8gERXqZ/i1s5vJk7HUPcqDVl1pWu1JA2/v9m7J+9iDNxlST\narJKN0pLFfQqqVIJfMWuZW2tSw8u1Kz80OU/DB2KkRvkQ9B2amkus9nSRC8m\nlT3Es/3I0xxq+ohJEp3vra+sh9VL7PQoLIPspMHfBT4kFppcC1cA+6P7jDTi\n7tF+vd4XDkGTg/Kx8o1RyQcB7iotzGUh1wWpfSX3piCMpOBbSY6MplZIznad\nZGACmYfShSYDJ8tWqHfR82JG+s0rXyK3vtyuE+z1r6txcfBXxey1V6u2EfIp\nrKmAtLxDz2tAwGakcx1lFrTc2gk/+NR02Yn9FXYL60g1b4UbAhgfsAONW5dX\nNpXGlHHntDIYhaFi18olRTtv48epTVBlRuf01/IIGIKcGeiImJYCICJoq5If\nokg2cdcGVbSgVtv37A2b34twR0M/8YQjCaog73KFzzCvmRjNCv3/cPrN8h5+\n5FHsR+HlOxXMcOJrR++mEWJkJnMEYhTxM10QEzMQXa+hHArdgjitlRWF5uvR\nPPLvGPDnH4AxkaQGYYMgKYPZeGIn9uld6eRvvQwqngZv20RMbQkwfDqQ6P97\n2OOpU6BLkwcPKK0TuIfuiXDSEII2+HRTviXOmk47O7LDmXrp69zU+2k6P7Tf\n8Thk\r\n=dvd2\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD2pzR2xP8WnUOFagVnE2F5sTVI3WvWstVE06mAbgv5QAIgPbYc40DnCCpk/6vd5ZswqBl5FMaM9D/C7Bk3eKLS984="}]},"_npmUser":{"name":"buffalodark","email":"admin@buffalodark.games"},"directories":{},"maintainers":[{"name":"buffalodark","email":"admin@buffalodark.games"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/profile-sdk_0.4.0_1629489025576_0.4637162108021644"},"_hasShrinkwrap":false}},"time":{"created":"2021-08-20T19:50:25.537Z","0.4.0":"2021-08-20T19:50:25.725Z","modified":"2022-04-04T20:57:26.267Z"},"maintainers":[{"name":"buffalodark","email":"admin@buffalodark.games"}],"description":"This package provides some handy functions to retrieve data for Pancakeswap Profile system.","repository":{"type":"git","url":"https://github.com/buffalodark/buffalodark-toolkit/tree/master/packages/buffalodark-profile-sdk"},"license":"MIT","readme":"# Pancakeswap Profile SDK\n\nThis package provides some handy functions to retrieve data for Pancakeswap 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 `@pancakeswap/profile-sdk` into your project with npm:\n\n```bash\nnpm install @pancakeswap/profile-sdk --save\n```\n\nor yarn:\n\n```bash\nyarn add @pancakeswap/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 PancakeProfileSdk from \"@pancakeswap/profile-sdk\";\n\nconst pancakeSdk = new PancakeProfileSdk();\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 PancakeProfileSdk from \"@pancakeswap/profile-sdk\";\nimport { ethers } from \"ethers\";\n\nconst customProvider = new ethers.providers.JsonRpcProvider(\"https://example.com\");\n\nconst pancakeSdk = new PancakeProfileSdk(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 PancakeProfileSdk from \"@pancakeswap/profile-sdk\";\n\nconst pancakeSdk = new PancakeProfileSdk();\nconst username = pancakeSdk.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 PancakeProfileSdk from \"@pancakeswap/profile-sdk\";\n\nconst pancakeSdk = new PancakeProfileSdk();\nconst team = pancakeSdk.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 buffalodark.games domain, maybe configurable in future versions)\n\n```js\nimport PancakeProfileSdk from \"@pancakeswap/profile-sdk\";\n\nconst pancakeSdk = new PancakeProfileSdk();\nconst profile = pancakeSdk.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: 'pancake',\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 PancakeProfileSdk from \"@pancakeswap/profile-sdk\";\n\nconst pancakeSdk = new PancakeProfileSdk();\n\nconst achievements = pancakeSdk.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 \"@pancakeswap/profile-sdk\";\n\nconst team = pancakeSdk.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 [pancake-frontend](https://github.com/pancakeswap/pancake-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"}