Wondering what’s next for npm?Check out our public roadmap! »

    fastify-commercetools

    1.0.6 • Public • Published

    fastify-commercetools

    commercetools fastify plugin that decorates fastify with commercetools key. commercetoos decorator contains:

    Install

    npm i fastify-commercetools --save
    

    Usage

    Register the plugin

    Add it to your project with register and pass it some basic options.

    const fastify = require("fastify")();
    
    fastify.register(require("fastify-commercetools"), {
      commercetools: {
        host: "https://api.commercetools.co",
        oauthHost: "https://auth.commercetools.co",
        projectKey: "projectKey",
        clientId: "clientId",
        clientSecret: "clientSecret",
        concurrency: 5
      }
    });

    Once you have register the plugin you can use the commercetools decorator to perform actions

    Using it as commercetools sdk

    fastify.post("/", schemas.signUp, async (request, reply) => {
      const { client, requestBuilder } = fastify.commercetools;
      const { email, password } = request.body;
    
      try {
        const response = await client.execute({
          uri: requestBuilder().customers.build(),
          method: "POST",
          body: JSON.stringify({ email, password })
        });
    
        reply.code(200).send(esponse.body.customer);
      } catch (error) {
        handleCTError(request, reply, error);
      }
    });

    Using it as service

    fastify.post("/", schemas.signUp, async (request, reply) => {
      const { CustomerRepository } = fastify.commercetools.repositories;
      const { email, password } = request.body;
    
      try {
        const customer = await CustomerRepository.create({ email, password });
    
        reply.code(200).send(customer);
      } catch (error) {
        handleCTError(request, reply, error);
      }
    });

    Install

    npm i fastify-commercetools

    DownloadsWeekly Downloads

    325

    Version

    1.0.6

    License

    ISC

    Unpacked Size

    582 kB

    Total Files

    72

    Last publish

    Collaborators

    • avatar
    • avatar
    • avatar