{"_id":"@adamsoderstrom/react-centra-checkout","_rev":"1-aa9ccea080a8a1f8994b4152de35e61e","name":"@adamsoderstrom/react-centra-checkout","dist-tags":{"latest":"1.1.0"},"versions":{"1.1.0-test0":{"name":"@adamsoderstrom/react-centra-checkout","version":"1.1.0-test0","private":false,"author":{"name":"Adam Söderström"},"description":"React components and helpers for Centra checkout api","keywords":["react","react-component","typescript","centra"],"license":"MIT","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/noaignite/accelerator.git","directory":"packages/react-centra-checkout"},"bugs":{"url":"https://github.com/noaignite/accelerator/issues"},"scripts":{"build":"tsup","build:modern":"node ../../scripts/build.mjs modern","build:node":"node ../../scripts/build.mjs node","build:stable":"node ../../scripts/build.mjs stable","build:types":"tsc -p tsconfig.build.json","build:copy-files":"node ../../scripts/copy-files.mjs","build:docs":"typedoc","prebuild":"rimraf build","release:yalc":"yarn build && yalc publish ./build","test":"cd ../../ && cross-env NODE_ENV=test jest packages/react-centra-checkout","typecheck":"tsc -p tsconfig.json --noEmit"},"peerDependencies":{"react":"^17.0.0 || ^18.0.0","react-dom":"^17.0.0 || ^18.0.0","react-fast-compare":"^3.2.0"},"devDependencies":{"@noaignite/centra-types":"^1.1.0","@types/js-cookie":"^3.0.1","tsup":"^8.0.1"},"dependencies":{"js-cookie":"^3.0.1"},"sideEffects":false,"publishConfig":{"access":"public"},"engines":{"node":">=14.0.0"},"gitHead":"760a16885a796650a290e867dd1b6d4707e15eb5","homepage":"https://github.com/noaignite/accelerator#readme","_id":"@adamsoderstrom/react-centra-checkout@1.1.0-test0","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-iw73uFJNoRrX29tpKURJg7qmpXKv0f9ucCQuLSfqpXupx5Of40tKgTtqsAePgwt1OXd4Pepb9jMPe2sslXw4Fg==","shasum":"f00d953a5e0ac5ab3b5473e97425590826bee287","tarball":"https://registry.npmjs.org/@adamsoderstrom/react-centra-checkout/-/react-centra-checkout-1.1.0-test0.tgz","fileCount":26,"unpackedSize":247761,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDs4oFl1JTzIn7PP3aycpWOfr5Oj+WnTGnit1ekZzTe6QIhAOEqs7YS3LO17PyHvNr6lABy9RlwatqNFmdwB3k4C0UN"}]},"_npmUser":{"name":"adamsoderstrom","email":"adamsoderstrom@me.com"},"directories":{},"maintainers":[{"name":"adamsoderstrom","email":"adamsoderstrom@me.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/react-centra-checkout_1.1.0-test0_1708511589965_0.34721431140130044"},"_hasShrinkwrap":false},"1.1.0":{"name":"@adamsoderstrom/react-centra-checkout","version":"1.1.0","private":false,"author":{"name":"NoA Ignite"},"description":"React components and helpers for Centra checkout api","keywords":["react","react-component","typescript","centra"],"license":"MIT","main":"./node/index.js","repository":{"type":"git","url":"git+https://github.com/adamsoderstrom/accelerator.git","directory":"packages/react-centra-checkout"},"bugs":{"url":"https://github.com/noaignite/accelerator/issues"},"peerDependencies":{"react":"^17.0.0 || ^18.0.0","react-dom":"^17.0.0 || ^18.0.0","react-fast-compare":"^3.2.0"},"dependencies":{"js-cookie":"^3.0.1"},"sideEffects":false,"publishConfig":{"access":"public"},"engines":{"node":">=14.0.0"},"gitHead":"1c4803459a9058ee57a0ababda1c97ff2acd78e6","module":"./index.js","types":"./index.d.ts","homepage":"https://github.com/adamsoderstrom/accelerator#readme","_id":"@adamsoderstrom/react-centra-checkout@1.1.0","_nodeVersion":"18.17.1","_npmVersion":"lerna/5.3.0/node@v18.17.1+arm64 (darwin)","dist":{"integrity":"sha512-Jog+OQzpF2mrIOyE2jBp+mp5W1kXn2kRRNL39RoRc/jXNHn7Bd6CkEUOvaOhCw3iCliMVZVoUZ4YIX+QsLbmfA==","shasum":"5d8dffccb80cd8bdb30564e178818c0f867a40a4","tarball":"https://registry.npmjs.org/@adamsoderstrom/react-centra-checkout/-/react-centra-checkout-1.1.0.tgz","fileCount":36,"unpackedSize":116550,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCESBohXAetGVPwVRhhaObWg2y862LCT161mdRgMHl8ugIgLBvN9yVYSQkipKRj77Q8BpJb5P7Be75ovlhfPZ04zH8="}]},"_npmUser":{"name":"adamsoderstrom","email":"adamsoderstrom@me.com"},"directories":{},"maintainers":[{"name":"adamsoderstrom","email":"adamsoderstrom@me.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/react-centra-checkout_1.1.0_1712304998646_0.5296520234867601"},"_hasShrinkwrap":false}},"time":{"created":"2024-02-21T10:33:09.897Z","1.1.0-test0":"2024-02-21T10:33:10.169Z","modified":"2024-04-05T08:16:39.039Z","1.1.0":"2024-04-05T08:16:38.853Z"},"maintainers":[{"name":"adamsoderstrom","email":"adamsoderstrom@me.com"}],"description":"React components and helpers for Centra checkout api","homepage":"https://github.com/adamsoderstrom/accelerator#readme","keywords":["react","react-component","typescript","centra"],"repository":{"type":"git","url":"git+https://github.com/adamsoderstrom/accelerator.git","directory":"packages/react-centra-checkout"},"author":{"name":"NoA Ignite"},"bugs":{"url":"https://github.com/noaignite/accelerator/issues"},"license":"MIT","readme":"# @noaignite/react-centra-checkout\n\n[NoA Ignite](https://noaignite.se/) Centra helpers. Previously known as [@oakwood/accelerator](https://github.com/oakwood/accelerator).\n\n## Installation\n\nreact-centra-checkout is available as an [npm package](https://www.npmjs.com/package/@noaignite/react-centra-checkout).\n\n```sh\n// with npm\nnpm install @noaignite/react-centra-checkout\n\n// with yarn\nyarn add @noaignite/react-centra-checkout\n```\n\n## Why\nThis package exists to ease development of react frontend applications using the [Centra Checkout API](https://docs.centra.com/api-references/checkout-api/introduction).\n\nMost importantly, it exposes a `CentraProvider` that you wrap your application with (for Next.js projects, usually in _app.js), and a set of hooks to fetch api endpoints and update the user selection.\n\nIt does not attempt to abstract the Centra api, but rather exposes the endpoints in a React way of calling them.\n\n## Getting started\nStart by wrapping your applications root component with `CentraProvider` and supply it with `apiUrl` (the api url to your Centra checkout api), `paymentReturnPage` (url to the api route in your app which handles successful payments) and `paymentFailedPage` (url to the api route for failed payments) like so:\n```JSX\nimport { CentraProvider } from '@noaignite/react-centra-checkout'\n\n<CentraProvider\n  apiUrl={process.env.CHECKOUT_API}\n  paymentReturnPage={`${process.env.APP_URL}/api/centra/checkout-success`}\n  paymentFailedPage={`${process.env.APP_URL}/api/centra/checkout-failed`}\n>\n  <AppProvider>\n    <AppBase>\n      <Component {...pageProps} />\n    </AppBase>\n  </AppProvider>\n</CentraProvider>\n```\n\nBy default, the CentraProvider will handle fetching the initial selection for the user, so by wrapping your apps root component, you get access to the `useCentraSelection` and `useCentraHandlers` hooks.\n\n### Getting things from the selection\nTo get data from the current selection, simply destruct whatever you want from the `useCentraSelection` hook, like so:\n\n```JSX\nimport { useCentraSelection } from '@noaignite/react-centra-checkout'\n\nconst { selection, paymentMethods } = useCentraSelection()\nconst { items, currency, totals } = selection\n```\n\n### Updating the selection\nTo update the selection, call one of the update handlers from the `useCentraHandlers` hook:\n```JSX\nimport { useCentraHandlers } from '@noaignite/react-centra-checkout'\n\nconst { addItem } = useCentraHandlers()\n\naddItem(size, quantity)\n```\n\n### Calling endpoints server-side\nThe Centra selection and handlers will only be available client-side. To make api calls against Centra server-side (e.g when fetching products), you need to call the api directly using the Api client:\n```JSX\nimport { ApiClient } from '@noaignite/react-centra-checkout'\n\nconst response = await ApiClient.default.request('POST', 'products', { categories: ['15'] })\n```\n\n\n## Documentation\nhttps://react-centra-checkout-docs.vercel.app\n\n","readmeFilename":"README.md"}