0.0.6 • Published 1 year ago

@field123/client-mock-service v0.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

@field123/client-mock-service

NPM version NPM downloads

Description

EPCC for JavaScript mock-service Client for Node.js, Browser and React Native.

Installing

To install the this package, simply type add or install @field123/client-mock-service using your favorite package manager:

  • npm install @field123/client-mock-service
  • yarn add @field123/client-mock-service
  • pnpm add @field123/client-mock-service

Getting Started

Module imports

The EPCC SDK uses clients and commands. To send a request, you only need to import the client creator function createMockServiceClient and the command creator functions you need, for example createGetAllHierarchiesCommand:

Syntax

// ES5 example
const {
  createMockServiceClient,
  createGetAllHierarchiesCommand
} = require('@field123/client-mock-service')
// ES6+ example
import {
  createMockServiceClient,
  createGetAllHierarchiesCommand
} from '@field123/client-mock-service'

Usage

To send a request, you:

  • Create a client with configuration (e.g. credentials).
  • Create a command with any required input parameters.
  • Call send operation on client with command object as the first argument.
// a client can be shared by different commands.
// example using fromKeys credential provider
const client = createMockServiceClient({
  credentials: fromKeys({
    clientId: '...'
  })
})

const params = {
  /** commands input parameters */
}
const command = createGetAllHierarchiesCommand(params)

Sending command

try {
  const data = await client.send(command)
  // do something with response data.
} catch (error) {
  // handle any errors.
}

Support command creators for MockServiceClient

  • createGetAllHierarchiesCommand
  • createGetAllNodesCommand
  • createGetAllProductsCommand
  • createGetHierarchyByIdCommand
  • createGetHierarchyChildNodesCommand
  • createGetHierarchyNodesCommand
  • createGetHierarchyProductsCommand
  • createGetNodeByIdCommand
  • createGetNodeChildNodesCommand
  • createGetNodeProductsCommand
  • createGetProductByIdCommand
  • createGetShopperCatalogCommand