Skip to content

Vulcan Core SDK

The Vulcan core SDK is a set of utils and functions that power the Vulcan core worker. The sdk is regularly maintained so make sure to checkout releases for the latest updates.

You can install the Vulcan Core SDK using npm or yarn:

sh
npm install @coderpunktech/vulcan-sdk-core
sh
yarn add @coderpunktech/vulcan-sdk-core

Wiring the SDK

The SDK is initialized and configured in your index.ts file and it accepts a series of configuration options.

Omitting Configurations

The vulcan worker exposes a get configuration endpoint that allows to retrieve all your environment configurations. This endpoint is public and does not require any authentication. This is for the benefit of your client application. You can store your config on the backend and then return them to your client application.

There are instances where you may want to omit certain configurations from being returned to the client for security reasons. The SDK allows you to specify a list of configurations to omit from the response. This is done using the omits property in the config object.

typescript
const sdk: SDK = Sdk({
  /**
   * This will return all your environment variable exepct an environment variable called MY_SECRET
   * You can add as many environment variables as you want to omit in the omits array
   */
  config: {
    omits: ['MY_SECRET'],
  },
})

Set custom endpoint

You can map your vulcan worker to any endpoint path you want. Here is an example on how to do so:

typescript
const sdk: SDK = Sdk({
  /**
   * Configure the endpoint for this worker
   */
  vulcan: {
    endpointUri: '/your-custom-path',
  },
})

Add Custom Validators

A generic backend has its trades-offs. The Vulcan Core SDK allows you to add custom validators to your backend. This is useful when you want to add custom validation logic to your backend to prevent certain records from being created, updated, deleted or accessed unless your validation criteria are met.

Validators are entity specific so you can add a custom validator per http method and entity. For instance I have a job entity in my application, to configure it I would do the following:

typescript
const sdk: SDK = Sdk({
  /**
   * Configure your custom validators here
   */
  validators: {
    createRecord: {
      job: MyCreateJobRecordValidator,
    },
    updateRecord: {
      job: MyUpdateJobRecordValidator,
    },
    deleteRecord: {
      job: MyDeleteJobRecordValidator,
    },
    getRecord: {
      job: MyGetJobRecordValidator,
    }
  },
})

You can find out more about how to create custom validators here

Add Custom Decorators

Custom Decorators allow you to take in a record in an http method and modify it before it is processed by the Vulcan Core SDK. Like validators, decorators are per entity so you can configure them as follow:

typescript
const sdk: SDK = Sdk({
  recordDecorators: {
    updateRecord: {
      job: UpdateJobRecordDecorator,
    },
    getRecord: {
      job: GetJobRecordDecorator,
    },
    createRecord: {
      job: CreateJobRecordDecorator,
    },
  },
})

There is no decorator for deleteRecord as it is not necessary to modify a record before it is deleted. You can find out more about how to create custom decorators here