Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/devgurusio/fastify-commercetools
Fastify commercetools plugin
https://github.com/devgurusio/fastify-commercetools
commercetools commercetools-sdk e-commerce e-commerce-api fastify fastify-commercetools fastify-plugin plugin
Last synced: 11 days ago
JSON representation
Fastify commercetools plugin
- Host: GitHub
- URL: https://github.com/devgurusio/fastify-commercetools
- Owner: Devgurusio
- Created: 2020-01-10T09:27:27.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-03-04T05:38:33.000Z (over 1 year ago)
- Last Synced: 2024-10-27T16:14:16.228Z (16 days ago)
- Topics: commercetools, commercetools-sdk, e-commerce, e-commerce-api, fastify, fastify-commercetools, fastify-plugin, plugin
- Language: TypeScript
- Homepage: https://www.fastify.io
- Size: 1.11 MB
- Stars: 5
- Watchers: 7
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# fastify-commercetools
commercetools fastify plugin that decorates fastify with commercetools key.
commercetoos decorator contains:- [requestBuilder](https://www.npmjs.com/package/@commercetools/platform-sdk) commercetools by project key request builder
## Install
```
npm i fastify-commercetools --save
```## Usage
### Register the plugin
Add it to your project with `register` and pass it some basic options.
#### JavaScript
```js
const fp = require("fastify-plugin")();
const fastifyCommercetools = require("fastify-commercetools");export default fp(async (fastify, opts) => {
fastify.register(fastifyCommercetools, {
auth: {
host: "https://auth.commercetools.co",
projectKey: "projectKey",
credentials: {
clientId: "clientId",
clientSecret: "clientSecret"
}
},
http: {
host: "https://api.commercetools.co",
enableRetry: true,
retryConfig: {
maxRetries: 3,
backoff = true,
retryDelay = 200,
retryCodes = [503, 504]
},
},
queue: { concurrency: 10 }
projectKey: "projectKey"
})
});
```#### TypeScript
```ts
import fp from "fastify-plugin";
import fastifyCommercetools, { FastifyCommercetoolsOptions } from "fastify-commercetools";export default fp(async (fastify, opts) => {
fastify.register(fastifyCommercetools, {
auth: {
host: "https://auth.commercetools.co",
projectKey: "projectKey",
credentials: {
clientId: "clientId",
clientSecret: "clientSecret"
}
},
http: {
host: "https://api.commercetools.co",
enableRetry: true,
retryConfig: {
maxRetries: 3
},
},
queue: { concurrency: 10 }
projectKey: "projectKey"
})
});
```Once you have register the plugin you can use the commercetools decorator to
perform actions### Using it
```js
fastify.post("/", schemas.signUp, async (request, reply) => {
const { commercetools: { requestBuilder } } = fastify;
const { body } = request;try {
const customerSignInResult = await requestBuilder()
.customers()
.post({ body })
.execute();reply.code(200).send(customerSignInResult.body.customer);
} catch (error) {
handleCTError(request, reply, error);
}
});
```## Warning
This version is not backward compatible with version 1.x.x