Appearance
Codedraw Core
The codedraw-core
npm package is a set of utils and functions to power your Codedraw generated worker. The package is regularly maintained so make sure to checkout releases for the latest updates.
You can install it using npm or yarn:
sh
npm install @coderpunktech/codedraw-core
sh
yarn add @coderpunktech/codedraw-core
Installing the SDK
The Codedraw Core SDK is installed using the installSDK middleware.
Omitting Configurations
You can have your worker exposing a get configuration endpoint that allows to retrieve all your environment configurations. This endpoint is usually 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
app.use('*', installSDK({
/**
* 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 worker to any endpoint path you want. Here is an example on how to do so:
typescript
app.use('*', InstallSDK({
/**
* Configure the endpoint for this worker
*/
vulcan: {
endpointUri: '/your-custom-path',
},
...
}))
Add Custom Validators
A generic backend has its trades-offs. Codedraw Core 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
app.use('*', installSDK({
/**
* 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
You can find out more about how to create custom overrides here