Skip to content

Clone this broker template, or click "Use this template" below, for any new projects

License

Notifications You must be signed in to change notification settings

K2Documentation/K2Documentation.Samples.JavascriptBroker.Template

Repository files navigation

K2 TypeScript Broker Template

This is demonstrates best-practices for developing a K2 Broker using TypeScript.

Features

  • Full object model intellisense for making development easier
  • Sample broker code that accesses jsonplaceholder.
  • Sample unit tests with mocks and code coverage.
  • RollupJS configuration for TypeScript.

Getting Started

This template requires Node.js v12.14.1+ to run.

Install the dependencies and devDependencies:

npm install

Alternatively, use pnpm to reduce the size of the node_modules directory:

npm install -g pnpm # Only required once
pnpm install

See the documentation for @k2oss/k2-broker-core for more information about how to use the broker SDK package.

Running Unit Tests

To run the unit tests, run:

npm test
pnpm test # Alternative

You can also use a development build, for debugging and coverage gutters:

npm run test:dev
pnpm run test:dev # Alternative

You will find the code coverage results in coverage/index.html.

Building your bundled JS

When you're ready to build your broker, run the following command

npm run build
pnpm run build # Alternative

You will find the results in the dist/index.js.

Creating a service type

Once you have a bundled .js file, upload it to your repository (anonymously accessible) and register the service type using the system SmartObject located at System > Management > SmartObjects > SmartObjects > JavaScript Service Provider and run the Create From URL method.

License

MIT, found in the LICENSE file.

www.k2.com