<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sidney Barrah on Medium]]></title>
        <description><![CDATA[Stories by Sidney Barrah on Medium]]></description>
        <link>https://medium.com/@sidneyb231?source=rss-9983385adb9e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Mpdgvq8Ikwd69BU55VXo2Q.jpeg</url>
            <title>Stories by Sidney Barrah on Medium</title>
            <link>https://medium.com/@sidneyb231?source=rss-9983385adb9e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 13:12:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sidneyb231/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Create a Serverless App on AWS using TypeScript]]></title>
            <link>https://levelup.gitconnected.com/creating-a-simple-serverless-application-using-typescript-and-aws-part-1-be2188f5ff93?source=rss-9983385adb9e------2</link>
            <guid isPermaLink="false">https://medium.com/p/be2188f5ff93</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Sidney Barrah]]></dc:creator>
            <pubDate>Sun, 07 Feb 2021 18:04:12 GMT</pubDate>
            <atom:updated>2021-02-17T23:59:20.694Z</atom:updated>
            <content:encoded><![CDATA[<h3>Create a Serverless App on AWS using TypeScript — Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DXZ6BwGUEDdgeAoJ" /><figcaption>Photo by <a href="https://unsplash.com/@kelvin1987?utm_source=medium&amp;utm_medium=referral">Kelvin Ang</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Serverless architecture and microservices have changed the way we think about applications. Now, we have server-side logic written by application developers that run in stateless compute containers which are event-triggered and fully managed by a third party cloud provider. Essentially, <a href="https://en.wikipedia.org/wiki/Function_as_a_service">Functions-as-a-Service (<strong>FaaS</strong>)</a>. There are currently many implementations of <a href="https://en.wikipedia.org/wiki/Function_as_a_service">FaaS</a> but <a href="https://aws.amazon.com/lambda/">AWS Lambda</a> is one of the most popular platforms.</p><h4>Why Serverless?</h4><p>There are many reasons why a lot of people favour <a href="https://martinfowler.com/articles/serverless.html">serverless applications</a> over traditional server hosted applications. Core among those reasons are:</p><ul><li>Lost cost and maintenance</li><li>Easy to scale</li></ul><p>It is cheaper to run <a href="https://martinfowler.com/articles/serverless.html">serverless applications</a> as we only effectively pay per request and we do not get charged when we are not using our application. We also only have to worry about our code and nothing else. We do not need to worry about servers to manage and as a result it is low maintenance. In addition, <a href="https://aws.amazon.com/lambda/">Lambda</a> scales up based on the demand and <a href="https://aws.amazon.com/dynamodb/">DynamoDB</a> gives us almost infinite scale.</p><p>For this article, we will be creating a simple <a href="https://www.redhat.com/en/topics/api/what-is-a-rest-api">REST API</a> for a to-do application using the following tools:</p><ul><li><a href="https://www.serverless.com/">Serverless Framework</a> with <a href="https://nodejs.org/en/">Node</a> and <a href="https://www.typescriptlang.org/">Typescript</a> on <a href="https://aws.amazon.com/">AWS</a>,</li><li>Testing using <a href="https://mochajs.org/">Mocha</a> and <a href="https://www.chaijs.com/">Chai</a> and</li><li>Access control using <a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html">API Gateway Lambda authorizers</a> — preventing unauthorized requests to our endpoints.</li></ul><h3>Development</h3><p>I have always found it easier when developing <a href="https://martinfowler.com/articles/serverless.html">serverless applications</a> to use the <a href="https://www.serverless.com/">Serverless Framework</a>. Configuring <a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html">Amazon API Gateway</a> and working with <a href="https://docs.aws.amazon.com/lambda/latest/dg/welcome.html">AWS Lambda</a> can be very cumbersome and this is where the <a href="https://www.serverless.com/">Serverless Framework</a> can be very useful. The <a href="https://www.serverless.com/">Serverless Framework</a> is an open source provider-agnostic framework, which provides great support with deployment to <a href="https://aws.amazon.com/">AWS</a>, <a href="https://azure.microsoft.com/en-gb/">Microsoft Azure</a>, <a href="https://cloud.google.com/">Google Cloud Platform</a>, or any cloud provider of choice. Using the <a href="https://www.serverless.com/">Serverless Framework</a> also means that as a developer, I am able to quickly construct, build, package, monitor and deploy my serverless applications. It removes most of the boilerplate required for serverless deployment while enabling <a href="https://en.wikipedia.org/wiki/Infrastructure_as_code">infrastructure as code</a>. The framework also gives me the ability to provision resources and infrastructure required by my applications such as databases, object stores and queues while also enabling me to build multiple types of applications. You can read more about how the <a href="https://www.serverless.com/learn/comparisons/">Serverless Framework compares with other software</a>.</p><p><a href="https://aws.amazon.com/">AWS</a> has always been my cloud provider of choice as I find it the most developer-friendly platform for <a href="https://aws.amazon.com/serverless/">serverless development</a>. Also, <a href="https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/billing-free-tier.html">AWS Free Tier</a> allows developers to try out a range of AWS services for free. I am able to try out various services to see how they work without worrying about cost.</p><p>For development, you need to have <strong>serverless</strong>, <strong>npm</strong> and/or <strong>yarn</strong> globally installed. See how to <a href="https://classic.yarnpkg.com/en/docs/install/">install YARN</a> and <a href="https://docs.npmjs.com/downloading-and-installing-node-js-and-npm">NPM</a>. I also prefer using <a href="https://github.com/nvm-sh/nvm#installing-and-updating">NVM</a> to manage my Node versions.</p><pre>// Install serverless framework CLI<br>$ <strong>npm install -g serverless</strong></pre><h4>Step 1. Configure AWS</h4><p>Setup AWS CLI if you have not already. I have included my article on how to <a href="https://sidneyb231.medium.com/configure-aws-for-development-and-deployment-ad822097fc22">create and configure AWS credentials</a>. Next, we need to set up our application.</p><h4>Step 2. Setup Project</h4><p>Create and set up a serverless project with typescript:</p><pre>$ sls create --template aws-nodejs-typescript --path &lt;PROJECT-NAME&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-M1XhNRCGg64mUzdbEbX7g.png" /></figure><p>Where <strong>&lt;PROJECT-NAME&gt;</strong> is the name of your project.</p><p>This generates a serverless boilerplate for our application. Next, we need to navigate to our new project cd &lt;PROJECT-NAME&gt;and install our dependencies by running <strong>yarn install</strong>.</p><p>The most important files we will be updating as we develop our application are the <strong>handler.ts</strong> and <strong>serverless.ts</strong> . The <strong>handler.ts</strong> file handles our lambda functions or references to our lambda functions. It should look like this:</p><pre>import { APIGatewayProxyHandler } from &#39;aws-lambda&#39;;<br>import &#39;source-map-support/register&#39;;<br><br>export const <em>hello</em>: APIGatewayProxyHandler = async (event, _context) =&gt; {<br>  return {<br>    statusCode: 200,<br>    body: JSON.stringify({<br>      message: &#39;Go Serverless Webpack (Typescript) v1.0! Your function executed successfully!&#39;,<br>      input: event,<br>    }, null, 2),<br>  };<br>}</pre><p>The <strong>serverless.ts</strong> file provides us with a template to model and provision our application resources for <a href="https://aws.amazon.com/cloudformation/">AWS CloudFormation</a> by treating infrastructure as code. This helps us create, update and even delete resources easily. It should look like this:</p><pre>import type { Serverless } from &#39;serverless/aws&#39;;<br><br>const serverlessConfiguration: Serverless = {<br>  service: {<br>    name: &#39;serverless-todo&#39;,<br>    <em>// app and org for use with dashboard.serverless.com<br>    // app: your-app-name,<br>    // org: your-org-name,<br>  </em>},<br>  frameworkVersion: &#39;&gt;=1.72.0&#39;,<br>  custom: {<br>    webpack: {<br>      webpackConfig: &#39;./webpack.config.js&#39;,<br>      includeModules: true<br>    }<br>  },<br>  <em>// Add the serverless-webpack plugin<br>  </em>plugins: [&#39;serverless-webpack&#39;],<br>  provider: {<br>    name: &#39;aws&#39;,<br>    runtime: &#39;nodejs12.x&#39;,<br>    apiGateway: {<br>      minimumCompressionSize: 1024,<br>    },<br>    environment: {<br>      AWS_NODEJS_CONNECTION_REUSE_ENABLED: &#39;1&#39;,<br>    },<br>  },<br>  functions: {<br>    hello: {<br>      handler: &#39;handler.hello&#39;,<br>      events: [<br>        {<br>          http: {<br>            method: &#39;get&#39;,<br>            path: &#39;hello&#39;,<br>          }<br>        }<br>      ]<br>    }<br>  }<br>}<br><br>module.exports = serverlessConfiguration;</pre><p>Also, due to <a href="https://www.serverless.com/framework/docs/deprecations/">deprecations</a> you will need to set the service property directly to service name:</p><pre>{ <br>  service: &#39;serverless-todo&#39;,</pre><pre>  ...<br>}</pre><p>And update the <strong>provider.apiGateway</strong> object as follows:</p><pre>provider: {<br>  ...<br>  apiGateway: {<br>    shouldStartNameWithService: true,<br>    ...<br>  },<br>  ...<br>},</pre><p>We can run our function in our project root <strong>$ serverless invoke local --function hello</strong> and you should see the response:</p><pre>{<br>    &quot;statusCode&quot;: 200,<br>    &quot;body&quot;: &quot;{\n  \&quot;message\&quot;: \&quot;Go Serverless Webpack (Typescript) v1.0! Your function executed successfully!\&quot;,\n  \&quot;input\&quot;: \&quot;\&quot;\n}&quot;<br>}</pre><p>The serverless framework locally invokes the hello function and runs the exported <strong>hello</strong> method in the <strong>handler.ts</strong> file. The serverless invoke local command allows us to run our Lambda functions locally before they are deployed.</p><p>Next, we need to install a few dependencies for our application:</p><pre>$ yarn add -D serverless-offline serverless-dotenv-plugin serverless-bundle<br>$ yarn add aws-sdk uuid @types/uuid</pre><ul><li><a href="https://www.npmjs.com/package/aws-sdk"><strong>aws-sdk</strong></a> — allows us to communicate with AWS services</li><li><a href="https://www.npmjs.com/package/uuid"><strong>uuid</strong> </a>— generates unique ids for our database entries</li><li><a href="https://www.npmjs.com/package/serverless-offline"><strong>serverless-offline</strong></a><strong> </strong>— this plugin enables us to run our application and Lambda functions locally</li><li><a href="https://www.npmjs.com/package/serverless-dotenv-plugin"><strong>serverless-dotenv-plugin</strong></a> — to enable us load <strong>.env</strong> variables into our Lambda environment</li><li><a href="https://www.npmjs.com/package/serverless-bundle"><strong>serverless-bundle</strong> </a>— this plugin optimally packages our Typescript functions and ensures that we don’t need to worry about installing <a href="https://babeljs.io/"><strong>Babel</strong></a>, <a href="https://www.typescriptlang.org/"><strong>Typescript</strong></a>, <a href="https://webpack.js.org/"><strong>Webpack</strong></a>, <a href="https://eslint.org/"><strong>ESLint</strong></a> and a host of other packages. This means that we don’t need to maintain our own webpack configs. So we can go ahead and delete the <strong>webpack.config.js</strong> file and the reference to it in serverless.ts custom property:</li></ul><pre>// FROM<br>custom: {<br>  webpack: {<br>    webpackConfig: &#39;./webpack.config.js&#39;,<br>    includeModules: true<br>  }<br>}</pre><pre>// TO<br>custom: {<br>  <br>}</pre><p>And also removed from the <strong>plugins</strong> array. You can also remove the following default dependencies from the project:</p><ul><li><strong>source-map-support</strong></li><li><strong>fork-ts-checker-webpack-plugin</strong></li><li><strong>ts-loader</strong></li><li><strong>ts-node</strong></li><li><strong>typescript</strong></li><li><strong>serverless-webpack</strong></li><li><strong>webpack</strong></li><li><strong>webpack-node-externals</strong></li></ul><h4><strong>Performance</strong></h4><p>Also important to note is that by default the Serverless framework creates a single package for all your Lambda functions. This means that every time a Lambda function is invoked, it loads all other Lambda functions and code in your app. This will negatively affect performance as the application gets bigger and also make <a href="https://dzone.com/articles/dealing-with-serverless-cold-starts-once-and-for-a">cold starts</a> longer.</p><p>This feature can be turned off and will ensure that our functions are packaged individually by adding the following to our <strong>serverless.ts</strong>:</p><pre>// serverless.ts  </pre><pre>package: {<br>  individually: true,<br>},</pre><p>This enabled option will also allow <strong>serverless-bundle</strong> to use Webpack to generate optimized packages using a <a href="https://webpack.js.org/guides/tree-shaking/">tree shaking algorithm</a>.</p><h4>Step 3. Setup Resources</h4><p>The next step in building a <a href="https://en.wikipedia.org/wiki/Create,_read,_update_and_delete">CRUD</a> application is deciding how we store data. In this case, we will be using <a href="https://aws.amazon.com/dynamodb/">DynamoDB</a> as our database of choice. DynamoDB is a serverless database and thus scales automatically and we only pay for what we use. We will also be adding a few Lambda functions.</p><p>So our new application architecture will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aDlZHXpZOcC4g_lHG02sWg.png" /><figcaption>Application Architecture</figcaption></figure><p>You will notice that our database is not publicly exposed and only invoked by our Lambda functions.</p><p>In setting up our resources, it is important that we do everything in code and avoid using the AWS console. That way, it is easier, quicker and consistent to configure, deploy and maintain infrastructure components. We will be updating the <strong>serverless.ts</strong> file with the resources we need.</p><p>First, we need to set up our <strong>custom</strong> property as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd533727fa38558431d260836975ffde/href">https://medium.com/media/fd533727fa38558431d260836975ffde/href</a></iframe><p>This sets up the <strong>region</strong>, <strong>stage</strong>, <strong>table_throughputs</strong>, <strong>table_throughput</strong> and tables <strong>list_table</strong> and <strong>tasks_table</strong> variables. It also configures <strong>dynamodb</strong> and <strong>serverless-offline</strong> for local development.</p><p>Next, we need to update the <strong>provider.environment</strong> property in the<strong>serverless.ts</strong> file as follows:</p><pre>// serverless.ts</pre><pre>provider: {<br>  ...<br>  environment: {<br>    ...<br>    REGION: &#39;${self:custom.region}&#39;,<br>    STAGE: &#39;${self:custom.stage}&#39;,<br>    LIST_TABLE: &#39;${self:custom.list_table}&#39;,<br>    TASKS_TABLE: &#39;${self:custom.tasks_table}&#39;,<br>  },<br>  ...<br>},</pre><p>The environment section defines environmental variables for our Lambda function and will be available under the process.env Node.js variable. This defines <strong>REGION</strong>, <strong>STATE</strong>, <strong>LIST_TABLE</strong> and <strong>TASKS_TABLE</strong> as environmental variables.</p><p>We also need to provide <a href="https://aws.amazon.com/iam/"><strong>AWS Identity and Access Management</strong></a> (IAM) access to allow to read and write against our DynamoDB tables. To do this, we need to add the <strong>iamRoleStatements</strong> property to the <strong>provider</strong> object. This section tells AWS what resources we want our Lambda functions to have access to:</p><pre>provider: {<br>  ...<br>  iamRoleStatements: [<br>    {<br>      Effect: &#39;Allow&#39;,<br>      Action: [<br>          &#39;dynamodb:DescribeTable&#39;,<br>          &#39;dynamodb:Query&#39;,<br>          &#39;dynamodb:Scan&#39;,<br>          &#39;dynamodb:GetItem&#39;,<br>          &#39;dynamodb:PutItem&#39;,<br>          &#39;dynamodb:UpdateItem&#39;,<br>          &#39;dynamodb:DeleteItem&#39;<br>      ],<br>      Resource: [<br>        {&quot;Fn::GetAtt&quot;: [ &#39;ListTable&#39;, &#39;Arn&#39; ]},<br>        {&quot;Fn::GetAtt&quot;: [ &#39;TasksTable&#39;, &#39;Arn&#39; ]}<br>      ]<br>    }<br>  ]<br>},</pre><p>There are three permission blocks noted above, namely <strong>Effect</strong>, <strong>Action</strong> and <strong>Resource</strong> . The Effect set to Allow grants the listed actions on the listed resources. The Action block contains a list of needed DynamoDB actions, such as <strong>DescribeTable</strong>, <strong>Query</strong>, <strong>Scan</strong>, <strong>GetItem</strong>, <strong>PutItem</strong>, <strong>UpdateItem</strong> and <strong>DeleteItem</strong>. These are the only permissions our application requires. Finally, the Resource block has our table’s ARN and limits the scope of our applications permissions to the table’s listed and cannot query any other tables not listed.</p><p>Next, we need to add <strong>resources</strong> which are added into your CloudFormation stack when our application is deployed. We need to define AWS resources in a property titled <strong>resources</strong> as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/155a64a7ee5562902dddfb5be10d3fee/href">https://medium.com/media/155a64a7ee5562902dddfb5be10d3fee/href</a></iframe><p>Where <strong>ListTable</strong> and <strong>TasksTable</strong> are references to our DynamoDB tables.</p><ul><li><strong>Type</strong>: describes the AWS resource type.</li><li><strong>DeletionPolicy</strong>: describes the DeletionPolicy for all resources which by default is set to <strong>Delete</strong>. <strong>Retain</strong> ensures our table is not deleted whenever our stack is deleted.</li><li><strong>Properties</strong>: describe the table properties</li><li><strong>TableName</strong>: name of the table to be created</li><li><strong>AttributeDefinitions</strong>: an array of attributes that describe the key schema for our tables and indexes.</li><li><strong>KeySchema</strong>: specifies the attributes that make up the primary key for our tables. The attributes in KeySchema must also be defined in the AttributeDefinitions array.</li><li><strong>ProvisionedThroughput</strong>: this defines the provisioned throughput for our tables</li></ul><p>You can read more about <a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.html">working with tables and data in DynamoDB</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3Fx0RUqFuqvEUSQq" /><figcaption>Photo by <a href="https://unsplash.com/@dhamp15?utm_source=medium&amp;utm_medium=referral">Dominic Hampton</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Using the power of Javascript, we can avoid large service definition files by splitting into files and using dynamic imports. This is important because as our application grows, separate definition files makes it easier to maintain.</p><p>For this project, we will be organizing our resources separately and importing into <strong>serverless.ts</strong>. To do this, we need to first create a <strong>resources</strong> directory in our root directory and then create a <strong>dynamodb-tables.ts</strong> file for our DynamoDB tables:</p><pre>// At project root<br>$ mkdir resources<br>$ touch resources/dynamodb-tables.ts </pre><p>Next, we update the <strong>dynamodb-tables.ts</strong> file as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c8071602de7411d750062cf9cf2d4a3/href">https://medium.com/media/1c8071602de7411d750062cf9cf2d4a3/href</a></iframe><p>And import into <strong>serverless.ts</strong> — see Line 4 and use on Line 98:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b25ec229c14a9011e645831506a1ea8/href">https://medium.com/media/5b25ec229c14a9011e645831506a1ea8/href</a></iframe><p>Next, we need to define our project structure.</p><h4>Step 4. Define Project Structure and Create Functions</h4><p>The next step is for us to create our a <a href="https://en.wikipedia.org/wiki/Create,_read,_update_and_delete">CRUD</a> APIs for our to-do app.</p><p>First, we need create a <strong>src</strong> directory in our root directory and define how we structure the rest of our project:</p><pre>// At project root<br>$ mkdir src<br>$ mkdir src/actions src/interfaces src/enums src/models src/services src/constraints src/utils</pre><ul><li><strong>actions</strong> — for our functions</li><li><strong>interfaces</strong> — for our application interfaces</li><li><strong>enums</strong> — for our application enums</li><li><strong>models</strong> — for our models</li><li><strong>services</strong> — for our application services</li><li><strong>constraints</strong> — for request parameter validations</li><li><strong>utils</strong> — for our utility functions</li></ul><h4>- Models</h4><p>Next, we need to create our models:</p><pre>$ touch src/models/response.model.ts src/models/list.model.ts src/models/task.model.ts</pre><p>Our Response model will handle our API responses and ensure that we always maintain a consistent format. Update <strong>response.model.ts</strong> as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd6d1930e5f7781fcac07069c7b854a7/href">https://medium.com/media/fd6d1930e5f7781fcac07069c7b854a7/href</a></iframe><p>We also need to update our <strong>list.model.ts</strong> and <strong>task.model.ts</strong> files to handle our data inputs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/218b88ced4d7822f653bc81823a7e0c5/href">https://medium.com/media/218b88ced4d7822f653bc81823a7e0c5/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/766393feaba5dd1cee5154f77f564ee4/href">https://medium.com/media/766393feaba5dd1cee5154f77f564ee4/href</a></iframe><p>Next, we create a few enums for our application:</p><pre>$ touch src/enums/response-message.enum.ts src/enums/status.enum.ts src/enums/status-code.enum.ts</pre><p>And we update as follows:</p><pre>// src/enums/status.enum.ts<br>export enum Status {<br>    <em>SUCCESS </em>= &#39;success&#39;,<br>    <em>ERROR </em>= &#39;error&#39;,<br>    <em>BAD_REQUEST </em>= &#39;bad request&#39;,<br>}</pre><pre>// src/enums/status-code.enum.ts<br>export enum StatusCode {<br>    <em>OK </em>= 200,<br>    <em>ERROR </em>= 500,<br>    <em>BAD_REQUEST </em>= 400,<br>}</pre><p>And replace the enums in<strong>response.model.ts</strong>.</p><h4>- Services</h4><p>Next, we need to create our Database service to handle our application CRUD processes.</p><pre>$ touch src/services/database.service.ts</pre><p>We also need to create a few interfaces for our Database service:</p><pre>$ touch src/interfaces/config.interface.ts</pre><p>And we update as follows:</p><pre>// src/interfaces/config.interface.ts<br>export default interface IConfig {<br>    region: string;<br>    accessKeyId?: string;<br>    secretAccessKey?: string;<br>    endpoint?: string;<br>}</pre><p>Next, we need update <strong>database.service.ts</strong> as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f59b6a6e539a0901247c92a669469633/href">https://medium.com/media/f59b6a6e539a0901247c92a669469633/href</a></iframe><ul><li><strong>create</strong> — function to put item in DynamoDB table</li><li><strong>batchCreate</strong> — function to batch write items into DynamoDB table</li><li><strong>update</strong> — function to update item in DynamoDB table</li><li><strong>query</strong> — function to run a query on DynamoDB table</li><li><strong>get</strong> — function to get item from DynamoDB table</li><li><strong>delete</strong> — function to delete item an from DynamoDB table</li></ul><p>We need to add support for local development by adding local DynamoDB environmental variables in our .<strong>env</strong> file and update our AWS config:</p><pre>const config: IConfig = { region: &quot;eu-west-1&quot; };<br>if (process.env.STAGE === process.env.DYNAMODB_LOCAL_STAGE) {<br>    config.accessKeyId = process.env.DYNAMODB_LOCAL_ACCESS_KEY_ID; <em><br>    </em>config.secretAccessKey = process.env.DYNAMODB_LOCAL_SECRET_ACCESS_KEY; <em><br>    </em>config.endpoint = process.env.DYNAMODB_LOCAL_ENDPOINT;<em><br></em>}<br>AWS.config.<em>update</em>(config);</pre><p>To run DynamoDB locally, we need to first install the <strong>serverless-dynamodb-local</strong> plugin:</p><pre>$ yarn add -D serverless-dynamodb-local </pre><p>Next, we need to update <strong>serverless.ts</strong> plugins array:</p><pre>plugins: [<br>    &#39;serverless-bundle&#39;,<br>    &#39;serverless-dynamodb-local&#39;,<br>    &#39;serverless-offline&#39;,<br>    &#39;serverless-dotenv-plugin&#39;,<br>],</pre><p>To use the plugin, we need to install DynamoDB Local by running <strong>sls dynamodb install</strong> at the project root. Running<strong>sls dynamodb start</strong> will start it locally:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rj9ycV_mTSVDKD8h80Iskw.png" /><figcaption>DynamoDB Local</figcaption></figure><p>Now that we have DynamoDB set up, we need to create our CRUD functions — to create, read, update and delete our to-do lists and tasks.</p><h4>- Functions</h4><p>First, we need to create directories to store our Lambda functions:</p><pre>$ mkdir src/actions/list src/actions/task</pre><ul><li><strong>list</strong> — for our list functions</li><li><strong>task</strong> — for our task functions</li></ul><p>— <strong>Request Validation</strong></p><p>We cannot rely on client side validation, so it is also important that we validate all requests to our endpoints.</p><p>For this, I will be installing the<a href="https://www.npmjs.com/package/validate.js"><strong>validate.js</strong></a> library as it provides a declarative way of validating objects in Javascripts. At the project root, run <strong>yarn add validate.js</strong> to install as a dependency in our project.</p><p>Next, we need to create a <strong>util</strong> validation function to implement this dependency:</p><pre>$ touch src/utils/util.ts</pre><p>And update as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d2c61f0769bc9273f86a3e327098a524/href">https://medium.com/media/d2c61f0769bc9273f86a3e327098a524/href</a></iframe><p>Next, we need to create request constraints for our Lambda functions:</p><pre>// Create directories for our constraints<br>$ mkdir src/constraints/list src/constraints/task</pre><pre>// List constraints<br>$ touch src/constraints/list/create.constraint.json src/constraints/list/get.constraint.json src/actions/list/update.constraint.json</pre><pre>// Task constraints<br>$ touch src/constraints/task/create.constraint.json src/constraints/task/update.constraint.json src/constraints/task/get.constraint.json</pre><p>It is important to note that to dynamically import and use JSON files in our typescript project, we need to update <strong>tsconfig.json</strong> compilerOptions and set <strong>resolveJsonModule</strong> to <strong>true</strong>. Replace the contents of <strong>tsconfig.json </strong>as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3223615f3060feddfdde7303d6d2724e/href">https://medium.com/media/3223615f3060feddfdde7303d6d2724e/href</a></iframe><p>Next, we also need to create separate files for our Lambda functions:</p><pre>// List functions<br>$ touch src/actions/list/create-list.action.ts src/actions/list/get-list.action.ts src/actions/list/update-list.action.ts src/actions/list/delete-list.action.ts</pre><pre>// Task functions<br>$ touch src/actions/task/create-task.action.ts src/actions/task/update-task.action.ts src/actions/task/delete-task.action.ts</pre><p>Now we can start creating our functions.</p><h4>- List Functions</h4><p>We start with our <strong>createList</strong> function . First, we need to define the constraints for our request by updating <strong>create.constraint.json</strong>:</p><pre>// src/constraints/list/create.constraint.json<br>{<br>  &quot;name&quot;: {<br>    &quot;presence&quot;: {<br>      &quot;allowEmpty&quot;: false<br>    },<br>    &quot;type&quot;: &quot;string&quot;<br>  }<br>}</pre><p>This ensures that the <strong>createList</strong> function expects a request object which includes the <strong>name</strong> property and is a string. If it doesn’t match then the validation fails:</p><pre>{<br>    &quot;data&quot;: {<br>        &quot;validation&quot;: {<br>            &quot;name&quot;: [<br>                &quot;Name can&#39;t be blank&quot;<br>            ]<br>        }<br>    },<br>    &quot;message&quot;: &quot;required fields are missing&quot;,<br>    &quot;status&quot;: &quot;bad request&quot;<br>}</pre><p>Next, we need to update <strong>create-list.action.ts</strong> as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b80280c5e03925f6170b00f9b58c8bf/href">https://medium.com/media/3b80280c5e03925f6170b00f9b58c8bf/href</a></iframe><p>First, we initialise our response variable and then parse the input from the event.body that represents the HTTP request body. We also read the name of the DynamoDB table from the environment variable using <strong>process.env.LIST_TABLE</strong> which we set in <strong>serverless.ts</strong>.</p><p>Next, we validate the request parameters against our defined constraints. Our defined constraints requires a request object which can look like:</p><pre><em>// Request-Example:<br>{<br>   &quot;name&quot;: &quot;My To-do list&quot;,<br>}</em></pre><p>If the request is valid, then we create a new list item in the DynamoDB table and generate a response message:</p><pre>// <em>Example </em>Success Response<br><em>{<br>  &quot;data&quot;: { &quot;listId&quot;: &quot;468c8094-a756-4000-a919-example&quot; },<br>  &quot;message&quot;: &quot;To-do List successfully created&quot;<br>  &quot;status&quot;: &quot;success&quot;<br>}</em></pre><p>Next, we move on the <strong>updateList</strong> function and create the update constraints in <strong>update.constraint.json</strong>:</p><pre>// src/constraints/list/update.constraint.json<br>{<br>  &quot;listId&quot;: {<br>    &quot;presence&quot;: {<br>      &quot;allowEmpty&quot;: false<br>    },<br>    &quot;type&quot;: &quot;string&quot;<br>  },<br>  &quot;name&quot;: {<br>    &quot;presence&quot;: {<br>      &quot;allowEmpty&quot;: false<br>    },<br>    &quot;type&quot;: &quot;string&quot;<br>  }<br>}</pre><p>As with our previous constraint definition, this also ensures that our <strong>updateList</strong> API expects a request object with <strong>listId</strong> and <strong>name</strong> properties which are both strings. An example request:</p><pre><em>// Request-Example:<br>{<br>  &quot;listId&quot;: &quot;468c8094-a756-4000-example&quot;,<br>  &quot;</em>name<em>&quot;: &quot;My Wednesday List&quot;,<br>}</em></pre><p>An invalid request such as:</p><pre><em>// Invalid request<br>{<br>  &quot;listId&quot;: &quot;468c8094-a756-4000-example&quot;,<br>  &quot;</em>name<em>&quot;: 54647,<br>}</em></pre><p>Next, we also need to update <strong>update-list.action.ts</strong> :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/223db1c710c58d2153b43b2d77015370/href">https://medium.com/media/223db1c710c58d2153b43b2d77015370/href</a></iframe><p>The <strong>updateList</strong> function simply updates an existing list item in the DynamoDB table and generate a response message:</p><pre><em>// Success Response<br>{<br>  &quot;data&quot;: {},<br>  &quot;message&quot;: &quot;To-do List successfully updated&quot;<br>  &quot;status&quot;: &quot;success&quot;<br>}</em></pre><p>Next, we create our <strong>getList</strong> function and constraints. First we update <strong>get.constraint.json</strong>:</p><pre>// src/constraints/list/get.constraint.json<br>{<br>  &quot;listId&quot;: {<br>    &quot;presence&quot;: {<br>      &quot;allowEmpty&quot;: false<br>    },<br>    &quot;type&quot;: &quot;string&quot;<br>  }<br>}</pre><p>This ensures that the request object to the <strong>getList</strong> function must include a <strong>listId</strong> property and of type <strong>string</strong>.</p><p>Next we update <strong>get-list.action.ts</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b0b6f060b816ba2e7b9139f1fd1b130/href">https://medium.com/media/4b0b6f060b816ba2e7b9139f1fd1b130/href</a></iframe><p>In the <strong>getList</strong> function, we also read the name of the DynamoDB tables from the environment variables. In the function, we first retrieve a list item from the DynamoDB table and then query another DynamoDB table for all task items with the requested <strong>listId</strong> and return the data in our API response:</p><pre>{<br>    &quot;data&quot;: {<br>        &quot;name&quot;: &quot;My To do List&quot;,<br>            &quot;createdAt&quot;: 1609475930597,<br>            &quot;id&quot;: &quot;ae47940e-5bf3-45d6-a390-example&quot;,<br>            &quot;updatedAt&quot;: 1609475930597,<br>            &quot;taskCount&quot;: 2,<br>            &quot;tasks&quot;: [<br>            {<br>                &quot;id&quot;: &quot;566e06a7-a9e9-449f-9e19-example&quot;,<br>                &quot;description&quot;: &quot;Task 1&quot;,<br>                &quot;completed&quot;: false,<br>                &quot;createdAt&quot;: 1609533804820,<br>                &quot;updatedAt&quot;: 1609534302597<br>            },<br>            {<br>                &quot;id&quot;: &quot;263a3617-4a65-4879-b522-example&quot;,<br>                &quot;description&quot;: &quot;Task 2&quot;,<br>                &quot;completed&quot;: false,<br>                &quot;createdAt&quot;: 1609533804820,<br>                &quot;updatedAt&quot;: 1609534302597            <br>            }<br>          <br>        ]<br>    },<br>    &quot;message&quot;: &quot;To-do list successfully retrieved&quot;,<br>    &quot;status&quot;: &quot;success&quot;<br>}</pre><p>Next, we create our <strong>deleteList</strong> function and use the previous <strong>get.constraint.json</strong> as it requires the same request parameters:</p><pre>// src/constraints/list/get.constraint.json<br>{<br>  &quot;listId&quot;: {<br>    &quot;presence&quot;: {<br>      &quot;allowEmpty&quot;: false<br>    },<br>    &quot;type&quot;: &quot;string&quot;<br>  }<br>}</pre><p>The <strong>deleteList</strong> function is a lot more complex because every List item has a one-to-many relationship with tasks. This means that every list can have one or more tasks. So when we delete a list, we also want to make sure we delete the tasks associated with that list.</p><p>DynamoDB provides the <strong>batchWrite</strong> function for inserting or deleting multiple items from a DynamoDB table. However, it is restricted to a limit of 25 items per transaction. Unless we restrict the amount of tasks that can be assigned to a list to less than 25, we need to provide a way for handling lists with more than 25 tasks. I have chosen to create a util function <strong>createChunks</strong> in the <strong>util.ts</strong>:</p><pre>// src/utils/util.ts</pre><pre>export const <em>createChunks </em>= (data: any[], chunkSize: number) =&gt; {<br>    const urlChunks = [];<br>    let batchIterator = 0;<br>    while (batchIterator &lt; data.length) {<br>        urlChunks.push(data.slice(batchIterator, (batchIterator += chunkSize)));<br>    }<br>    return urlChunks;<br>}</pre><p>This function simply breaks a large array into an array of chunks. This will be implemented in <strong>get-list.action.ts</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/987a2e2b189d2ba925060feddc6adb37/href">https://medium.com/media/987a2e2b189d2ba925060feddc6adb37/href</a></iframe><p>As previously, we first validate our request data but we also need to check if the item does exist in the DynamoDB table and only then process the delete transaction. We also need to delete all tasks linked the list. The function then returns an API response, successful or not:</p><pre>// Example Success response<br><em>{<br>  &quot;data&quot;: {},<br>  &quot;message&quot;: &quot;To-do list successfully deleted&quot;<br>  &quot;status&quot;: &quot;success&quot;<br>}</em></pre><pre>// Example Error response<br>{<br>    &quot;data&quot;: {<br>        &quot;id&quot;: &quot;468c8094-a756-4000-a919-example&quot;<br>    },<br>    &quot;message&quot;: &quot;Item does not exist&quot;,<br>    &quot;status&quot;: &quot;bad request&quot;<br>}</pre><h4><strong>- Task Functions</strong></h4><p>Next, we create <strong>createTask</strong>, <strong>updateTask</strong>, <strong>deleteTask</strong> and <strong>getTask</strong> functions. As every task has a one-to-one relationship with a List item, as defined by the <strong>listId</strong> RANGE_KEY in the AttributeDefinitions and KeySchema of the <strong>TASKS_TABLE</strong>:</p><pre>TasksTable: {<br>    ...<br>    Properties: {<br>        TableName: &#39;${self:provider.environment.TASKS_TABLE}&#39;,<br>        AttributeDefinitions: [<br>            ...<br>            { AttributeName: &#39;listId&#39;, AttributeType: &#39;S&#39; }<br>        ],<br>        KeySchema: [<br>            ...<br>            { AttributeName: &#39;listId&#39;, KeyType: &#39;RANGE&#39; }<br>        ],<br>        ...<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*4oTZb4vepySH9DM-92vpDw.png" /><figcaption>Task Table structure</figcaption></figure><p>In creating the <strong>createTask</strong> function, we also need to define constraints for the request object:</p><pre>// src/constraints/task/create.constraint.json<br>{<br>  &quot;listId&quot;: {<br>    &quot;presence&quot;: {<br>      &quot;allowEmpty&quot;: false<br>    },<br>    &quot;type&quot;: &quot;string&quot;<br>  },<br>  &quot;description&quot;: {<br>    &quot;presence&quot;: {<br>      &quot;allowEmpty&quot;: false<br>    },<br>    &quot;type&quot;: &quot;string&quot;<br>  }<br>}</pre><p>So we run a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all">Promise.all()</a> to validate our request parameters (Line 36) and also that there is an associated List item with the <strong>listId</strong> (Line 38) before we insert the task into the DynamoDB table (Line 61). We do not want to create tasks for list that don’t exist. See <strong>create-task.action.ts</strong> below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3efb472d40895cfd208b58d754c9643c/href">https://medium.com/media/3efb472d40895cfd208b58d754c9643c/href</a></iframe><pre><em>// Request-Example:</em><br>{<br>    &quot;listId&quot;: &quot;ae47940e-5bf3-45d6-a390-example&quot;,<br>    &quot;description&quot;: &quot;Buy milk&quot;<br>}</pre><pre><em>// Response-Example:</em><br>{<br>    &quot;data&quot;: {<br>        &quot;taskId&quot;: &quot;6cdff49d-a883-443b-87b2-example&quot;<br>    },<br>    &quot;message&quot;: &quot;Task successfully added&quot;,<br>    &quot;status&quot;: &quot;success&quot;<br>}</pre><p>The next step is to set up the <strong>updateTask</strong> function which updates a task item by first defining the constraints for request parameters:</p><pre>// src/constraints/task/update.constraint.json<br>{<br>  &quot;listId&quot;: {<br>    &quot;presence&quot;: {<br>      &quot;allowEmpty&quot;: false<br>    },<br>    &quot;type&quot;: &quot;string&quot;<br>  },<br>  &quot;taskId&quot;: {<br>    &quot;presence&quot;: {<br>      &quot;allowEmpty&quot;: false<br>    },<br>    &quot;type&quot;: &quot;string&quot;<br>  },<br>  &quot;description&quot;: {<br>    &quot;type&quot;: &quot;string&quot;<br>  },<br>  &quot;completed&quot;: {<br>    &quot;type&quot;: &quot;boolean&quot;<br>  }<br>}</pre><p>This ensures that the request parameters must include the associated <strong>listId</strong>, a <strong>taskId</strong>, and optional <strong>description</strong> and <strong>completed</strong> properties. The optional properties however are type-checked to ensure validity. Next, we update <strong>update-task.action.ts</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/450112ffa19275d3e22a72e5d87cfe5e/href">https://medium.com/media/450112ffa19275d3e22a72e5d87cfe5e/href</a></iframe><p>In the <strong>updateTask</strong> function above, we need to validate the request parameters and also validate that a List item with the request <strong>listId</strong> exists in the DynamoDB table before we proceed to update the task. Also, as the <strong>description</strong> and <strong>completed</strong> properties are both optional and may not be present in the request parameter, we need to conditionally set the <strong>UpdateExpression</strong> and <strong>ExpressionAttributeValues</strong> .</p><p>This means that we can update either property for every task item. However, if neither parameters are present, then we should not update the item and instead throw an error as the request is not valid:</p><pre><em>// Request-Example:</em><br>{<br>    &quot;listId&quot;: &quot;ae47940e-5bf3-45d6-a390-example&quot;,<br>    &quot;taskId&quot;: &quot;7aa35acc-9a20-4cce-9191-example&quot;<br>}</pre><pre>// Error Response<br>{<br>    &quot;data&quot;: {},<br>    &quot;message&quot;: &quot;Invalid Request!&quot;,<br>    &quot;status&quot;: &quot;bad request&quot;<br>}</pre><p>We also need to set up the <strong>deleteTask</strong> function which simply deletes a task from the DynamoDB table. First, we define the constraints for our request:</p><pre>// src/constraints/task/delete.constraint.json<br>{<br>  &quot;listId&quot;: {<br>    &quot;presence&quot;: {<br>      &quot;allowEmpty&quot;: false<br>    },<br>    &quot;type&quot;: &quot;string&quot;<br>  },<br>  &quot;taskId&quot;: {<br>    &quot;presence&quot;: {<br>      &quot;allowEmpty&quot;: false<br>    },<br>    &quot;type&quot;: &quot;string&quot;<br>  }<br>}</pre><p>As with previous constraints, requests to the <strong>deleteTask</strong> function must include the associated <strong>listId</strong> and the id of the task to be deleted <strong>taskId</strong> as properties. So we update <strong>delete-task.action.ts</strong> accordingly:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af26bba0e4d3056eb81c32b8e9029fb0/href">https://medium.com/media/af26bba0e4d3056eb81c32b8e9029fb0/href</a></iframe><p>We start first by validating the request, then retrieving the task item if it exists and finally deleting the item.</p><p>The final function is the getTask function, which does exactly that — gets a task for the database. The request constraints are exactly the same as for the getTask function, as both require both the HASH and RANGE keys to retrieve the item from the DynamoDB table:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e8821042a435a44bd07bfd256eef755/href">https://medium.com/media/6e8821042a435a44bd07bfd256eef755/href</a></iframe><p>It validates the request, ensuring both keys exists and then checks the database for the item, then retrieving the task item if it exists or returning an error response if it does not.</p><h4>— Export Functions</h4><p>Now that we have created all our functions, we need to export our new functions in <strong>handler.ts</strong>. We need update <strong>handler.ts</strong> with the following:</p><pre><em>// List functions<br></em>export { <em>createList </em>} from &#39;./src/actions/list/create-list.action&#39;;<br>export { <em>deleteList </em>} from &#39;./src/actions/list/delete-list.action&#39;;<br>export { <em>getList </em>} from &#39;./src/actions/list/get-list.action&#39;;<br>export { <em>updateList </em>} from &#39;./src/actions/list/update-list.action&#39;;<br><br><em>// Task functions<br></em>export { <em>createTask </em>} from &#39;./src/actions/task/create-task.action&#39;;<br>export { <em>deleteTask </em>} from &#39;./src/actions/task/delete-task.action&#39;;<br>export { <em>updateTask </em>} from &#39;./src/actions/task/update-task.action&#39;;<br>export { <em>getTask </em>} from &#39;./src/actions/task/get-task.action&#39;;</pre><p>We also need to define the API endpoints for our functions in <strong>serverless.ts</strong> however, it is important that we avoid large service definition by separating our function definitions and using dynamic imports. To do this, we to create a <strong>functions.ts</strong> file in our <strong>resources</strong> directory:</p><pre>// At project root<br>$ touch resources/functions.ts</pre><p>Next, we update the <strong>functions.ts</strong> file as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c80f1da811aae696e5024a680fea36c/href">https://medium.com/media/1c80f1da811aae696e5024a680fea36c/href</a></iframe><ul><li><strong>createList</strong> — specifies how we handle post requests to the /list/create endpoint.</li><li><strong>deleteList</strong> — specifies how we handle post requests to the /list/delete endpoint.</li><li><strong>getList</strong> — specifies how we handle post requests to the /list endpoint.</li><li><strong>updateList</strong> — specifies how we handle post requests to the /list/update endpoint.</li><li><strong>createTask</strong> — specifies how we handle post requests to the /task/create endpoint.</li><li><strong>deleteTask</strong> — specifies how we handle post requests to the /task/delete endpoint.</li><li><strong>updateTask</strong> — specifies how we handle post requests to the /task/update endpoint.</li><li><strong>getTask</strong> — specifies how we handle post requests to the /task endpoint.</li></ul><p>This is the pattern of using a single Lambda function to respond to a single HTTP event</p><p>And import into <strong>serverless.ts</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04f40aedf55e0f3ac094bbe4a0517182/href">https://medium.com/media/04f40aedf55e0f3ac094bbe4a0517182/href</a></iframe><p>Above, we are simply importing our new functions into our serverless configuration.</p><h4>- Local Development</h4><p>We can now test our functions locally by using the previous installed plugin <a href="https://www.npmjs.com/package/serverless-offline">serverless-offline</a>. This plugin emulates <a href="https://aws.amazon.com/lambda">AWS Lambda</a> and <a href="https://aws.amazon.com/api-gateway">API Gateway</a> on your local machine and helps speed up development. It does this by starting a HTTP server that handles the request’s lifecycle and invokes our handlers just like <a href="https://aws.amazon.com/api-gateway">API Gateway</a>.</p><p>Running serverless offline start at the root of our project will bundle our application and invoke our handlers locally:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8c08IxsAWPcAAK8XKG0rFg.png" /><figcaption>Serverless Offline — starting server</figcaption></figure><p>It also exposes our endpoints locally:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4J17wgRpCPzx2lyZqraVvg.png" /><figcaption>Serverless Offline — local endpoints</figcaption></figure><p>And we can send requests, for example to create a new list. To do this, I will be using Postman to send a request to the endpoint http://localhost:3000/dev/list/create:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0AF25v43cGDQk9jrotwhmg.png" /><figcaption>Postman — Create List</figcaption></figure><p>When we click on the Send button, we should receive a response as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jQTzDULl_sjPsXflhIC53A.png" /><figcaption>Create List — valid request</figcaption></figure><p>We can also test our validation response by for example sending an empty object in our request. We should receive a validation response as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DbbqLsM9K1MWt5HMRymC2A.png" /><figcaption>Create List — Invalid request</figcaption></figure><p>Now we need to add some tests to our project.</p><h3>Testing</h3><p>To add tests to our application, we need to install some dependencies, namely <a href="https://mochajs.org/">Mocha</a> and <a href="https://www.chaijs.com/">Chai</a>:</p><pre>$ yarn add -D mocha @types/mocha chai @types/chai</pre><p>And add <strong>types</strong> in compilerOptions in <strong>tsconfig.json</strong>:</p><pre>{<br>  &quot;compilerOptions&quot;: {<br>    ....<br>    &quot;types&quot; : [ &quot;node&quot;, &quot;mocha&quot;]<br>  },<br>  ....<br>}</pre><p>We also need to create a <strong>tests</strong> directory at the root of our application:</p><pre>$ mkdir tests</pre><p>I also like to organise my tests into <strong>unit</strong> and <strong>feature</strong> and create the directories for our unit and feature tests respectively.</p><pre>$ mkdir tests/feature tests/feature/list tests/feature/task tests/unit tests/unit/model tests/unit/util</pre><ul><li><strong>feature</strong> — the feature directory will contain feature tests for our Lambda endpoints; feature/list for list features and feature/task for tasks</li><li><strong>unit</strong> — the unit directory will handle unit tests for our models, utils and services.</li></ul><p>We also need a <strong>lib</strong> directory for our handler functions and <strong>mocks</strong> for our mock entities and requests:</p><pre>$ mkdir tests/lib tests/lib/actions tests/mocks </pre><h4>Unit Tests</h4><p>We start by creating our Unit tests for our application. The purpose is to ensure that every unit of our application performs as expected. For this, we will be testing our models and util functions. We need to create the following files:</p><pre>$ touch tests/unit/model/response.model.test.ts tests/unit/model/list.model.test.ts tests/unit/model/task.model.test.ts tests/unit/util/util.test.ts</pre><p>And update <strong>tests/unit/model/list.model.test.ts</strong> as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3ef16c90e2b05f88cf1406cc0b84633/href">https://medium.com/media/f3ef16c90e2b05f88cf1406cc0b84633/href</a></iframe><p>Next update <strong>tests/unit/model/response.model.test.ts:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2750b06e5a938a1c10eef8240806623/href">https://medium.com/media/e2750b06e5a938a1c10eef8240806623/href</a></iframe><p>We also need to update <strong>tests/unit/model/task.model.test.ts</strong> as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/520a108aff83b48c012fe59ddcafc5f2/href">https://medium.com/media/520a108aff83b48c012fe59ddcafc5f2/href</a></iframe><p>And finally, we need tests for our <strong>util</strong> functions and update <strong>tests/unit/util/util.test.ts</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0d7ec5db61be0b4f30d392ba666b2f2/href">https://medium.com/media/d0d7ec5db61be0b4f30d392ba666b2f2/href</a></iframe><p>Now we have created our unit tests, we need to update the <strong>scripts</strong> property in our <strong>package.json</strong> with our <strong>test</strong> command:</p><pre><strong>// </strong>package.json</pre><pre><strong>&quot;scripts&quot;: {<br>  &quot;unit-test&quot;: &quot;./node_modules/.bin/mocha \&quot;tests/unit/**/*.ts\&quot; --require ts-node/register&quot;<br>},</strong></pre><p>We run the test using Node CLI arguments — Mocha requiring <strong>ts-node</strong> so we can execute the Typescript test file without needing to compile them. We also specify the path to our unit test files . It will run every test file within path matching the pattern. On the command line run <strong>yarn run unit-test</strong> to start the unit test. The output should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*exnwOqVIHsOnpko3-DxfFA.png" /><figcaption>Unit testing with Mocha and Chai</figcaption></figure><h4>Feature Tests</h4><p>Next, we also need to test our CRUD features and ensure that requests to our endpoints are handled as they should and accurate responses are sent back to the client. We also validate that the entries are created, updated or deleted from the DynamoDB tables.</p><p>We will be making requests to our endpoints, so first we need to install the <a href="https://www.npmjs.com/package/node-fetch">node-fetch</a> dependency to help with that:</p><pre>$ yarn add -D node-fetch</pre><p>Next, we need to create our test handler file:</p><pre>$ touch tests/lib/actions/handler.ts</pre><p>And update as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d437c5dcd51f4d2bb321553aac68c8e/href">https://medium.com/media/7d437c5dcd51f4d2bb321553aac68c8e/href</a></iframe><p>We have a <strong>post</strong> function which simply makes requests using the <strong>fetch</strong> library to all the endpoints we need to test.</p><p>We also need to create separate directories for each API function:</p><pre>// List functions<br>$ mkdir tests/feature/list/create-list tests/feature/list/delete-list tests/feature/list/get-list tests/feature/list/update-list</pre><pre>// Task functions<br>$ mkdir tests/feature/task/create-task tests/feature/task/delete-task tests/feature/task/get-task tests/feature/task/update-task</pre><p>Each of the API functions has a valid.test.ts which tests the API endpoint with a valid request and expects a valid response and the invalid.test.ts which tests the endpoints with an invalid request and expects the defined error handling response.</p><p>I have included a sample of the create-list/valid.test.ts :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60793e7eac348247090317111abac7c0/href">https://medium.com/media/60793e7eac348247090317111abac7c0/href</a></iframe><p>It runs the <strong>createList</strong> function to create a new list and ensures the expected response is received. Next, it runs the <strong>getList</strong> function to confirm that the item is stored in the database.</p><p>We also need to ensure that our endpoints handle unexpected requests and error responses accordingly. See below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6ecb11dd542c811dc78241ba0c158d4/href">https://medium.com/media/a6ecb11dd542c811dc78241ba0c158d4/href</a></iframe><p>You can view all other tests in the repository.</p><h3>Deployment</h3><p>Now that we have our APIs and tests, we can deploy them to AWS. Please read my article on how to <a href="https://sidneyb231.medium.com/configure-aws-for-development-and-deployment-ad822097fc22">create and configure AWS credentials and profiles for deployment</a>.</p><p>To deploy, we can either use the default AWS profile by running the following in your working directory:</p><pre>$ serverless deploy </pre><p>Or if you have multiple profiles and wish to deploy with a specific profile, then you have to run the following command:</p><pre>$ serverless deploy --stage dev</pre><p>And it will deploy using the profile set for the dev stage. The Service Information at the bottom should look like this:</p><pre>Service Information<br>service: serverless-todo<br>stage: dev<br>region: eu-west-1<br>stack: serverless-todo-dev<br>resources: 63<br>api keys:<br>  None<br>endpoints:<br>  POST - https://&lt;API-GATEWAY-ID&gt;.execute-api.eu-west-1.amazonaws.com/dev/list/create<br>  POST - https://&lt;API-GATEWAY-ID&gt;.execute-api.eu-west-1.amazonaws.com/dev/list/delete<br>  POST - https://&lt;API-GATEWAY-ID&gt;.execute-api.eu-west-1.amazonaws.com/dev/list<br>  POST - https://&lt;API-GATEWAY-ID&gt;.execute-api.eu-west-1.amazonaws.com/dev/list/update<br>  POST - https://&lt;API-GATEWAY-ID&gt;.execute-api.eu-west-1.amazonaws.com/dev/task/create<br>  POST - https://&lt;API-GATEWAY-ID&gt;.execute-api.eu-west-1.amazonaws.com/dev/task/delete<br>  POST - https://&lt;API-GATEWAY-ID&gt;.execute-api.eu-west-1.amazonaws.com/dev/task<br>  POST - https://&lt;API-GATEWAY-ID&gt;.execute-api.eu-west-1.amazonaws.com/dev/task/update<br>functions:<br>  createList: serverless-todo-dev-createList<br>  deleteList: serverless-todo-dev-deleteList<br>  getList: serverless-todo-dev-getList<br>  updateList: serverless-todo-dev-updateList<br>  createTask: serverless-todo-dev-createTask<br>  deleteTask: serverless-todo-dev-deleteTask<br>  getTask: serverless-todo-dev-getTask<br>  updateTask: serverless-todo-dev-updateTask<br>layers:<br>  None</pre><p>This has a list of the API endpoints that were created. Also note that in our case, <strong>eu-west-1</strong> is our API Gateway Region and <strong>&lt;API-GATEWAY-ID&gt;</strong> our API Gateway ID.</p><p>You may encounter a few issues while deploying your app. The team at <a href="https://seed.run/"><strong>Seed</strong></a> has created a <a href="https://seed.run/docs/serverless-errors/"><strong>compilation of the most common Serverless errors</strong></a> and how to fix them.</p><p>And when we make changes to our functions, we can also use the serverless deploy function command to deploy an individual function and avoid going through the entire deployment cycle. As an example, we can run the following to deploy the <strong>createList</strong> function again:</p><pre>$ serverless deploy function -f createList</pre><h4>Public API Architecture</h4><p>For reference, this is our API so far:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pHXAHcJ12Ium372IwQb8Og.png" /><figcaption>Application Architecture</figcaption></figure><p>Put simply, a user makes a request to our Serverless API, it starts by hitting our API Gateway endpoints, and depending on which endpoint is requested, the request is then forwarded to the appropriate Lambda function.</p><p>Our API Gateway endpoint is allowed to invoke the listed Lambda functions defined in our <strong>serverless.ts</strong>. Also, our Lambda functions are allowed to connect to our DynamoDB tables due to permissions also defined in the <strong>iamRoleStatements</strong> block in <strong>serverless.ts</strong>.</p><p>One of the things you may have noticed is that our APIs are publicly accessible and therefore insecure, which means that anyone can send requests to our endpoints. One way we can solve this problem is by extending our application to handle users and authentication. This will ensure that users need to sign up and then log in to be authenticated. And only then can they create and manage their to-do lists. We can do this using a few security mechanisms including <a href="https://aws.amazon.com/cognito/"><strong>AWS Cognito</strong></a> and <a href="https://auth0.com/"><strong>Auth0</strong></a>. For this application, I have chosen to use a custom <a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html"><strong>API Gateway Lambda authorizer</strong></a> to authenticate requests to our endpoints.</p><p><a href="https://sidneyb231.medium.com/creating-a-simple-serverless-application-using-typescript-and-aws-part-2-2f9192717015">Continue on to the second part of this article to see how we can control access to our APIs, accept and reject requests to our endpoints.</a></p><p><a href="https://github.com/s-barrah/serverless-todo">s-barrah/serverless-todo</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be2188f5ff93" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/creating-a-simple-serverless-application-using-typescript-and-aws-part-1-be2188f5ff93">Create a Serverless App on AWS using TypeScript</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a Serverless App on AWS using TypeScript]]></title>
            <link>https://levelup.gitconnected.com/creating-a-simple-serverless-application-using-typescript-and-aws-part-2-2f9192717015?source=rss-9983385adb9e------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f9192717015</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Sidney Barrah]]></dc:creator>
            <pubDate>Sun, 07 Feb 2021 18:02:01 GMT</pubDate>
            <atom:updated>2021-02-17T23:59:14.883Z</atom:updated>
            <content:encoded><![CDATA[<h3>Create a Serverless App on AWS using TypeScript — Part 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7lRFOL4KsktJxHLj" /><figcaption>Photo by <a href="https://unsplash.com/@fantasyflip?utm_source=medium&amp;utm_medium=referral">Philipp Katzenberger</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Continuing on from where we stopped in the first part of <a href="https://sidneyb231.medium.com/creating-a-simple-serverless-application-using-typescript-and-aws-part-1-be2188f5ff93"><strong>how to create a simple serverless application</strong></a>, we will be focusing on how we implement authorization in API Gateway and ensure only authenticated requests can access our Lambda functions. To learn more about authorization mechanisms and established practices, see <a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-control-access-to-api.html">Controlling and Managing Access to a REST API in API Gateway</a>. For this application, I have chosen to use a Lambda authorizer to control access to our Lambda functions created in the previous part of this article.</p><h4>API Gateway Lambda Authorizers</h4><p><a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html">API Gateway Lambda Authorizers</a> are Lambda functions which are called by APIGateway to control access to our functions. With a Lambda authorizer, we can allow a request to continue to our API or reject the request as unauthorised. This means that we can control who can access our APIs.</p><p>One of the advantages of using a Lambda authorizer is then we can centralize our authentication logic in a single function instead of packaging in each individual function. This means that we are able to easily update and deploy our single auth function without needing to redeploy each function that uses authentication. Another advantage with using Lambda authorizers is that we are able to cache responses with auth logic that make remote calls. Making such remote calls can add unnecessary latency with every function running a check. Lambda authorizers also allow us to integrate third-party identity providers to control access to resources in API Gateway without having to configure services such as <a href="https://aws.amazon.com/cognito/">Amazon Cognito</a>. It also gives us a flexibility in customising our authorization logic.</p><p>However, there are a few downsides with using Lambda authorizers which includes the added latency in API Gateway calls. AWS Lambda has a <a href="https://hackernoon.com/cold-starts-in-aws-lambda-f9e3432adbf0"><strong>cold start problem</strong></a> and using a Lambda authorizer means we may have to pay the penalty twice — in our authorizer function and our core function. Also, without caching strategies we will have to deal with the additional network hop in our request flow. Another downside with using Lambda authorizers is that every endpoint which uses the authorizer must include the authorization information. This can prove to be inflexible for certain situations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*JcANmAzXDnePkDZYY6nJnQ.png" /><figcaption>Lambda authorizer Auth workflow — AWS</figcaption></figure><h4>Implementation</h4><p>In terms of access control and securing our infrastructure, we’ll be implementing an architecture that looks like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*COn8KJsXz7VQPNEm2foJpg.png" /><figcaption>Authenticated API Architecture</figcaption></figure><p>Simply put, when a user makes a HTTP request to our API Gateway endpoint, the request must include the access token in the HTTP Authorization header. This is forwarded to the Lambda Authorizer function, which authenticates the token with the third-party identity provider. It then executes the authorization logic and returns an identity management policy to API Gateway. API Gateway uses this policy to evaluate if the user is allowed to invoke the API requested and either allows or denies the request. If allowed, API Gateway forwards the request to the Lambda function. You can find out more about how to <a href="https://aws.amazon.com/blogs/security/use-aws-lambda-authorizers-with-a-third-party-identity-provider-to-secure-amazon-api-gateway-rest-apis/">use AWS Lambda authorizers with third party identity providers to secure API Gateway REST APIs</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ccqmmAJbbsTHkzQa" /><figcaption>Photo by <a href="https://unsplash.com/@tolga__?utm_source=medium&amp;utm_medium=referral">Tolga Ulkan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Now for our application, we need to create a token-based Lambda authorizer using the third-party identity provider <a href="https://auth0.com/">Auth0</a>.</p><p><a href="https://auth0.com/signup?&amp;signUpData=%7B%22category%22%3A%22docs%22%7D">Sign up to Auth0 for free</a> and on the Dashboard, click on APIs on the left sidebar menu and then the <strong>CREATE API</strong> button on the dashboard to setup the api for a new project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iovUUcfl7BkuFZtWdRQM0w.png" /><figcaption>Auth0 Dashboard</figcaption></figure><p>Next, we need to enter a Name and Identifier for our API</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vK9yNgivdmn06AkyQxd9JA.png" /><figcaption>New API Form — Auth0</figcaption></figure><p>Click on the CREATE button to create a new API.</p><p>Next, in the API Quick Start tab, scroll down and make a note of the <strong>jwksUri</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j19LmEFlxCD1wcisi8bJ6A.png" /><figcaption>Auth0 API page</figcaption></figure><p>And also the issuer and audience values</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Ra48ynCDhe8y5k5lN4bwQ.png" /></figure><p>We need to also get the <strong>Client ID</strong> and <strong>Client Secret</strong> from our API page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EKfzVthXTrprX6K7Ujeqig.png" /></figure><p>Next, we need to add these values as environmental variables in our project. Modify the <strong>.env</strong> file and add the following:</p><pre><strong>// </strong>.env</pre><pre><strong>JWKS_URI</strong>=&quot;&lt;JWKS-VA&gt;&quot;<br><strong>AUDIENCE</strong>=&quot;&lt;AUDIENCE-VALUE&gt;&quot;<br><strong>TOKEN_ISSUER</strong>=&quot;&lt;ISSUER-VALUE&gt;&quot;<br><strong>AUTH0_CLIENT_ID</strong>=&quot;&lt;CLIENT-ID&gt;&quot;<br><strong>AUTH0_CLIENT_SECRET</strong>=&quot;&lt;CLIENT-SECRET&gt;&quot;</pre><p>Next, we need to create our authentication service. First, we install a few dependencies:</p><pre>$ yarn add jsonwebtoken @types/jsonwebtoken jwks-rsa</pre><p>Next, we create our <strong>auth.service.ts</strong> :</p><pre>$ touch src/services/auth.service.ts</pre><p>And update as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b06e120fd05c70e3d979fe3aa50e569/href">https://medium.com/media/2b06e120fd05c70e3d979fe3aa50e569/href</a></iframe><p>The <strong>authenticate</strong> method above handles all the logic for our token authentication. First, it retrieves the token from the request using the <strong>_getToken</strong> method. This token is then decoded by <strong>jwt</strong> and then we retrieve the <strong>kid</strong> . This <strong>kid</strong> is then used to retrieve the Auth0 signing key using the <strong>_getSigningKey</strong> method. This <strong>key</strong> is verified and then we return the policy document.</p><p>We also need to create our Lambda authorizer function:</p><pre>$ mkdir src/actions/auth<br>$ touch src/actions/auth/jwt-auth.action.ts</pre><p>And update as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7345ada91b2d572c0d3f94fded018144/href">https://medium.com/media/7345ada91b2d572c0d3f94fded018144/href</a></iframe><p>This function calls our Auth service <strong>authenticate</strong> method. We wrap it around a try catch block so that any error is returned as an <strong>Unauthorized </strong>request.</p><p>To implement our new Lambda authorizer, we need to export our function in our <strong>handler.ts </strong>file:</p><pre>// handler.ts</pre><pre><em>// Custom API Gateway Authorizer<br></em>export { <em>jwtAuth </em>} from &#39;./src/actions/auth/jwt-auth.action&#39;;</pre><p>And then update <strong>functions.ts</strong> :</p><pre>// resources/functions.ts</pre><pre>export default {<br>    jwtAuth: {<br>        handler: &#39;handler.jwtAuth&#39;,<br>    },<br>    ..........<br>}</pre><p>To use the authorizer in a function, we need to update the <strong>http</strong> object by adding the <strong>authorizer</strong> property with a value of our authorizer:</p><pre>http: {<br>    method: &#39;&lt;METHOD&gt;&#39;,<br>    path: &#39;&lt;ENDPOINT-URI&gt;&#39;,<br>    authorizer: {<br>        name: &#39;jwtAuth&#39;<br>    },<br>    cors: true<br>}</pre><p>Next, we update all our endpoints to use the authorizer so our endpoints will no longer accept requests without the right authorization token:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de0aacabb11dc2801ebcc99ffecba3db/href">https://medium.com/media/de0aacabb11dc2801ebcc99ffecba3db/href</a></iframe><p>Sending a request to our endpoint without a valid authentication TOKEN should returned an <strong>Unauthorized</strong> response:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mXA6Rp03MV-icfBhx3Qssg.png" /><figcaption>Postman — Failed Unauthorized request</figcaption></figure><p>We need to include a valid token in our request headers.</p><p>To obtain a valid token to test our endpoints, go to Application page in Auth0 and click on the <strong>Quick Start</strong>tab:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5jklvk0VgeL6FSxVnrvGeQ.png" /></figure><p>Scroll down to the <strong>Sending the token API </strong>section and copy the value of the header <strong>authorization</strong> property including <em>Bearer</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jH53CEHKlwYmSh3jjYASHQ.png" /></figure><p>We need to use this <strong>Bearer token</strong> value in our request <strong>Authorization</strong> header:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RAVctEkI1MhXd4JPv9HL4A.png" /></figure><p>Ensure there is a space between <strong>Bearer</strong> and the <strong>access_token</strong> . Click the Send button and we should receive a successful response:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cMIrCMUsjCEWkZXLVCH2wA.png" /></figure><p>Now, we have secure endpoints, we also need to update our <strong>feature</strong> tests.</p><p>We start by first installing <a href="https://www.npmjs.com/package/dotenv"><strong>dotenv</strong></a> so we can load environment variables from our <strong>.env</strong> file into <a href="https://nodejs.org/docs/latest/api/process.html#process_process_env"><strong>process.env</strong></a> and use in our test handler</p><pre>$ yarn add dotenv @types/dotenv</pre><p>And then we update our <strong>package.json</strong> script :</p><pre>&quot;scripts&quot;: {<br>  ....<br>  &quot;feature-test&quot;: &quot;./node_modules/.bin/mocha \&quot;tests/feature/**/*.ts\&quot; --require ts-node/register  --require dotenv/config &quot;<br>},</pre><p>We need to also update our <strong>.env</strong> file with our <strong>BASE_URL</strong> variable:</p><pre>BASE_URL=”http://localhost:3000/dev/&quot;</pre><p>Next, we update our test handler <strong>tests/lib/actions/handler</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b96a635d2ffdf89cdf01c6e458abd129/href">https://medium.com/media/b96a635d2ffdf89cdf01c6e458abd129/href</a></iframe><p>Our <strong>post</strong> function starts by making a client credentials request to Auth0 and if successful, returns an <strong>access_token</strong>. With this <strong>access_token</strong>, we then make another request our endpoint. I have added an <strong>authorized</strong> parameter in the post function so we can also test <strong>Unauthorized</strong> requests to our APIs.</p><p>Next, we create a test for <strong>Unauthorized</strong> requests:</p><pre>$ touch tests/feature/list/create-list/unauthorized.test.ts</pre><p>And add our test:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40e7368c9a207ec48d4d71aee27662cf/href">https://medium.com/media/40e7368c9a207ec48d4d71aee27662cf/href</a></iframe><p>Now we run our tests <strong>yarn run feature-test</strong> again:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QlUOsg7huUf-BwyLXsNJGQ.png" /><figcaption>Feature Tests</figcaption></figure><p>Next, we need to deploy our updated application to the default AWS profile by running the following in your working directory:</p><pre>$ serverless deploy</pre><p>Or to a specific profile by running:</p><pre>$ serverless deploy --stage dev</pre><p>You can refer to my article on <a href="https://sidneyb231.medium.com/configure-aws-for-development-and-deployment-ad822097fc22">how to create AWS credentials for local development and deployment</a>. And that is it.</p><h3>Conclusion</h3><p>Serverless allows developers to quickly create and deploy microservice applications that scale on demand and are cheaper to run. This means that we gain efficiency; however, there are trade-offs in control and visibility. Serverless shortens development time, which means that we fail faster. Failing fast means we also learn faster.</p><p>Now that we have deployed our application, we can create a client-side application to use our APIs. However, I will not be covering that in this post.</p><p>This article aimed to demonstrate how to create and deploy a simple serverless application which uses <a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html"><strong>DynamoDB</strong></a>, <a href="https://docs.aws.amazon.com/lambda/latest/dg/welcome.html"><strong>AWS Lambda</strong></a><strong> </strong>and <a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html"><strong>API Gateway</strong></a>. We have also learned how to manage and control access to our resources using <a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html"><strong>API Gateway Lambda authorizers</strong></a>. We can also improve our application further by implementing a few features such as monitoring, continuous integration and deployment using platforms such as <a href="https://travis-ci.com/"><strong>TravisCI</strong></a>, <a href="https://app.circleci.com/"><strong>CircleCI</strong></a> or <a href="https://concourse-ci.org/"><strong>ConcourseCI</strong></a> and even adding a custom domain using a service such as <a href="https://aws.amazon.com/route53/"><strong>Amazon Route 53</strong></a>. AWS also provides <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html"><strong>Cloudwatch</strong></a>, which monitors the resources and applications we run on the platform in real time.</p><p>I hope this article helps in your understanding of how to get started creating simple serverless applications and managing control to these services. I also hope it inspires you in some way as we continue to push the limits of what is possible in designing solutions for the future.</p><p>I have included a link to the GitHub repository below. Feel free to clone, fork or star it if it helps you:</p><p><a href="https://github.com/s-barrah/serverless-todo">s-barrah/serverless-todo</a></p><h3>Further Reading</h3><ul><li><a href="https://www.serverless.com/framework/docs/getting-started/">Getting started with the Serverless Framework</a></li><li><a href="https://www.serverless.com/learn/manifesto/">Serverless Manifesto</a></li><li><a href="https://www.serverless.com/learn/comparisons/">Serverless Framework vs Others</a></li><li><a href="https://serverless.com/learn/">Serverless architectures primer</a></li><li><a href="https://read.acloud.guru/our-serverless-journey-part-2-908d76d03716">How we migrated our startup to serverless</a></li><li><a href="https://serverless.com/blog/why-we-switched-from-docker-to-serverless/">Why we switched from Docker to Serverless</a></li><li><a href="https://serverless.com/blog/serverless-faas-vs-containers/">Serverless (FaaS) vs. Containers — when to pick which?</a></li><li><a href="https://www.serverless.com/framework/docs/providers/aws/guide/intro/">Serverless Framework Guide to AWS</a></li><li><a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html">Security best practices in IAM</a></li><li><a href="https://www.serverless.com/blog/abcs-of-iam-permissions">The ABCs of IAM: Managing permissions with Serverless</a></li><li><a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-control-access-to-api.html">Controlling and managing access to a REST API in API Gateway</a></li><li><a href="https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools.html">Amazon Cognito user pools</a></li><li><a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html">What Is Amazon DynamoDB?</a></li><li><a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.html">Working with Tables and Data in DynamoDB</a></li><li><a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html">Use API Gateway Lambda authorizers</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f9192717015" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/creating-a-simple-serverless-application-using-typescript-and-aws-part-2-2f9192717015">Create a Serverless App on AWS using TypeScript</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configure AWS for Development and Deployment]]></title>
            <link>https://levelup.gitconnected.com/configure-aws-for-development-and-deployment-ad822097fc22?source=rss-9983385adb9e------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad822097fc22</guid>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-services]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Sidney Barrah]]></dc:creator>
            <pubDate>Sun, 07 Feb 2021 11:51:06 GMT</pubDate>
            <atom:updated>2021-02-16T15:22:05.643Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to configure AWS for development and deployment</h3><h4>Step by step guide on how to create and configure AWS credentials</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Tafyb4V9ixTVWrpg" /><figcaption>Photo by <a href="https://unsplash.com/@cgower?utm_source=medium&amp;utm_medium=referral">Christopher Gower</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>Set up AWS</strong></h3><p>The first step is to create an AWS free-tier account if you don’t already have one at <a href="https://portal.aws.amazon.com/billing/signup#/start">https://portal.aws.amazon.com/billing/signup#/start</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BaqxrzG8BhxH4iv1viHrUQ.png" /><figcaption>AWS Sign up page</figcaption></figure><p>Once you have a registered account, sign in by clicking on the <strong>Sign in to an existing AWS account</strong> link and enter your username and password:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s__3uBzaZ9nonHyNYlPxDA.png" /><figcaption>AWS Login page</figcaption></figure><p>After you are logged in, you will be redirected to the AWS Management Console page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K4A8Cn7KfoxfdGhuKiXcMw.png" /><figcaption>AWS Management Console</figcaption></figure><p>For security reasons, I suggest going to the security credentials page at <a href="https://console.aws.amazon.com/iam/home?#/security_credentials">https://console.aws.amazon.com/iam/home?#/security_credentials</a> to set up multi-factor authentication (MFA) for your account:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ahZLxy3eYa4h4Da7IddW9A.png" /><figcaption>IAM Page</figcaption></figure><p>User passwords can be easily compromised. By enabling MFA, you immediately increase your account security by requiring multiple forms of verification to prove your identity when signing in. You can read more about <a href="https://searchsecurity.techtarget.com/definition/multifactor-authentication-MFA">multifactor authentication</a>.</p><p>Next, we need to create an <strong>IAM</strong> user. An IAM (AWS Identity and Access Management) user gives permissions to people to perform interactive tasks or make programmatic requests to AWS services using the API or CLI. You can read more about <a href="https://aws.amazon.com/iam/">AWS Identity and Access Management (IAM)</a> and <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id.html">IAM Identities</a>. Click on <strong>Users</strong> on the left sidebar of the <strong>IAM</strong> page or click on <strong>Services</strong> on the top menu and search for <strong>IAM.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lbsUjJaqRc1_klkUueO2Mw.png" /><figcaption>AWS Console</figcaption></figure><p>Clicking on IAM will take you to the IAM Page Dashboard.</p><p>Next, create a user by clicking on <strong>Add User</strong> which opens up the form below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jsMgrlfyWbkFS1FLUoTg8Q.png" /><figcaption>Add user — IAM</figcaption></figure><p>You need to choose a username and select the access type. Select <strong>Programmatic access</strong> as we require access to the AWS API, CLI and development tools. This creates an access key for each new user. Click next to set permissions for the user</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IcvI57ypbA2WCVcONNUCcA.png" /><figcaption>Set permissions — IAM</figcaption></figure><p>I usually prefer setting up a Permission group and then adding the user to a group. We can use groups to specify permissions for a collection of users, which makes it easier to manage permissions for those users. With groups, we can attach policies to multiple users at once.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RDIfMMQX_o44_FI1OBk40A.png" /><figcaption>Example IAM groups in a small company — AWS</figcaption></figure><p>In the example above, each user belongs to a single group. However, users can added to multiple groups. Also, every user in a group automatically has all the permissions assigned to the group.</p><p>Clicking continue takes you to the optional tags setting. Leave the default settings and click next to go to the review page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s1U19YP_wDRCoFlG33jsgg.png" /><figcaption>Add Tags — IAM</figcaption></figure><p>On the review page, you can review your choices and go back previous steps if you need to make changes. Click on Create user to complete the process and create your user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ZJlADmVO9JjSQk5yJgk2w.png" /><figcaption>Review — IAM</figcaption></figure><p>You can view or download the access keys when you get to the <strong>Final</strong> page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xD5Yyhlm1tlVZ2ScvbKZ3w.png" /></figure><p>It is important to save the <strong>Access key ID</strong> and <strong>Secret access Key </strong>as we will need it. More details on <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html">how to create an IAM user</a>.</p><p>Next, we also need to install the AWS-SDK on our local machine:</p><pre>$ <strong>npm install -g aws-sdk</strong></pre><p>We also need to install <a href="https://aws.amazon.com/cli/">AWS CLI</a>. On macOS we can install by running as following on the command line:</p><pre>$ <strong>brew install awscli</strong></pre><p>AWS CLI however has a dependency of <a href="https://www.python.org/downloads/">Python</a> or <a href="https://pypi.python.org/pypi/pip">Pip</a>. Please find more information on how to <a href="https://www.python.org/downloads/">install Python</a> or <a href="https://pip.pypa.io/en/stable/installing/">Pip</a> or <a href="https://serverless-stack.com/chapters/configure-the-aws-cli.html">AWS CLI</a>.</p><p>Next, we need to configure our settings for the AWS Command Line Interface (AWS CLI) to enable us to interact with AWS. We need the previously saved <strong>Access Key ID</strong> and <strong>Secret Access Key. </strong>Run the following on the command line:</p><pre>$ <strong>aws configure</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fPwyvPT8_RFjtYHlGCbIgg.png" /><figcaption>AWS Configure — <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html">Configuration basics</a></figcaption></figure><p>And enter your <strong>Access Key ID, Secret Access Key, Region </strong>and preferred <strong>output format.</strong></p><p>When you run the command <strong>aws configure</strong>, the <strong>credentials</strong> and <strong>config</strong> files get updated. The <strong>credentials</strong> file is located at <strong>~/.aws/credentials</strong> and config at <strong>~/.aws/config</strong> on Linux or macOS, or at <strong>C:\Users\</strong><strong><em>USERNAME</em></strong><strong>\.aws\credentials</strong> and <strong>C:\Users\</strong><strong><em>USERNAME</em></strong><strong>\.aws\config</strong> on Windows. These files can contain the credential details and configuration settings respectively for the <strong>default</strong> profile and any named profiles. You can manually update the files by adding additional profiles. See <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html">Configuration basics</a> and how to <a href="https://www.serverless.com/framework/docs/providers/aws/guide/credentials/"><strong>set up AWS — Credentials</strong></a>.</p><p>What then happens is that behind-the-scenes Serverless uses these credentials and the AWS SDK to create the necessary resources in the AWS account specified in the credentials.</p><h3>Deployment</h3><p>There are instances where we may want to specify a different AWS profile per project/stage/environment. This allows each environment in our project to have its own API endpoints, database tables and IAM policies. We can do this by keeping environments in separate AWS accounts using <a href="https://aws.amazon.com/organizations/"><strong>AWS Organizations</strong></a>.</p><h4><strong>Create a New AWS Profile</strong></h4><p>This is only necessary if you intend to use a different profile or multiple profiles during deployment.</p><p>To create a new AWS profile, follow the steps outlined at the beginning of this article — <strong>Set up AWS</strong> and take note of the <strong>Access key ID</strong> and <strong>Secret access key</strong>. Next, configure the new profile in your AWS CLI as follows:</p><pre>$ <strong>aws configure --profile &lt;NEW-PROFILE&gt;</strong></pre><p>Where <strong>&lt;NEW-PROFILE&gt;</strong> is the new of your new AWS profile. You don’t need to change the <strong>Default region name</strong> and <strong>Default output format</strong>.</p><p>At the start of this article, we used the <strong>serverless invoke local</strong> command to run our undeployed Lambda function locally using the default AWS profile in <strong>~/.aws/credentials</strong> under the <strong>[default]</strong> tag. We can switch profiles in the command as follows:</p><pre>$ AWS_PROFILE<strong>=</strong>&lt;NEW-PROFILE&gt; serverless invoke local --function hello</pre><p>By adding <strong>AWS_PROFILE=&lt;NEW-PROFILE&gt;</strong> at the beginning of our <strong>serverless invoke local</strong> command, we are setting the variable that the AWS SDK will use to figure out what your default AWS profile is.</p><p>We can also export this profile so we don’t need to specify on the command line every time:</p><pre>$ export AWS_PROFILE<strong>=</strong>&lt;NEW-PROFILE&gt;</pre><h4><strong>Set Profiles per Stage on Deploy</strong></h4><p>We can deploy using multiple profiles per stage using the following command:</p><pre>$ serverless deploy --stage &lt;STAGE&gt; --aws-profile &lt;PROFILE&gt;</pre><p>Where <strong>&lt;STAGE&gt;</strong> can be <strong>dev</strong> or <strong>prod</strong> and <strong>&lt;PROFILE&gt;</strong> is the name of the AWS profile.</p><p>To simplify this process and save us needing to specify these variables in our deploy commands, we can add the profiles to <strong>serverless.ts</strong> by first modifying our <strong>custom</strong> object as follows:</p><pre>custom: {<br>  region: &#39;${opt:region, self:provider.region}&#39;,<br>  stage: &#39;${opt:stage, self:provider.stage}&#39;,<br>  ......<br>  profile: {<br>    prod: &#39;prodAccount&#39;,<br>    dev: &#39;devAccount&#39;<br>  }<br>},</pre><p>And then the<strong>profile</strong> property of the <strong>provider</strong> object as follows:</p><pre>provider: {<br>  name: &#39;aws&#39;,<br>  runtime: &#39;nodejs12.x&#39;,<br>  ...<br>  profile: &#39;${self:custom.profile.${self:custom.stage}}&#39;<br>},</pre><p>This assigns the value of our profile based on the current stage defined in <strong>custom.stage</strong>.</p><p>This means that when we deploy to staging or production, the Serverless Framework will use the assigned profile and provision the resources inside the profile user’s AWS account. Now we can do this:</p><pre>$ serverless deploy --stage &lt;STAGE&gt;</pre><p>Where <strong>&lt;STAGE&gt;</strong> is the environment stage. We no longer have to set the <strong>--aws-profile</strong> option.</p><h4>Deploy to AWS</h4><p>To deploy, we can use either the default AWS profile by running the following in your working directory:</p><pre>$ serverless deploy</pre><p>Or if you have multiple profiles and wish to deploy with a specific profile, then you have to run the following command:</p><pre>$ serverless deploy --stage dev</pre><p>And it will deploy using the profile set for the dev stage.</p><h3>Further Reading</h3><ul><li><a href="https://aws.amazon.com/iam/">AWS Identity and Access Management (IAM)</a></li><li><a href="https://www.serverless.com/blog/abcs-of-iam-permissions">The ABCs of IAM: Managing permissions with Serverless</a></li><li><a href="https://serverless-stack.com/chapters/configure-the-aws-cli.html">Configure AWS CLI</a></li><li><a href="https://www.python.org/downloads/">Install Python</a></li><li><a href="https://pip.pypa.io/en/stable/installing/">Install Pip</a></li><li><a href="https://serverless-stack.com/chapters/configure-multiple-aws-profiles.html">Configure Multiple AWS Profiles</a></li><li><a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html">Security best practices in IAM</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad822097fc22" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/configure-aws-for-development-and-deployment-ad822097fc22">Configure AWS for Development and Deployment</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Simple encryption library in Node.js with Typescript]]></title>
            <link>https://javascript.plainenglish.io/a-simple-encryption-library-in-node-js-with-typescript-d72c294998bf?source=rss-9983385adb9e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d72c294998bf</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Sidney Barrah]]></dc:creator>
            <pubDate>Wed, 16 Sep 2020 20:26:10 GMT</pubDate>
            <atom:updated>2020-09-18T06:33:14.097Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to encode and encrypt simple data</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aTg3fjQ6uUQwHXRj" /><figcaption>Photo by <a href="https://unsplash.com/@fifernando?utm_source=medium&amp;utm_medium=referral">Fidel Fernando</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In a project that I worked on a while ago, I was presented with a problem that wasn’t very unique. It involved how we could safely pass identifiable user information such as phone numbers encoded and encrypted by a third party service in Ruby, to be decrypted and decoded into our application for the user.</p><pre>//Link with encrypted token<br>https://example.com?token=XXXXX</pre><p>Ruby provides straightforward handling for signed and unsigned big endians using <a href="https://apidock.com/ruby/Array/pack"><strong>pack()</strong></a> and <a href="https://apidock.com/ruby/String/unpack"><strong>unpack()</strong></a> methods for accessing underlying bits and bytes. However, Javascript has the problem of not properly handling large integers, as it can only store signed or unsigned integers of up to 53 bits. See <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER">Number.MAX_SAFE_INTEGER</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ykk7W3E9eCXEQuXw" /><figcaption>Photo by <a href="https://unsplash.com/@austindistel?utm_source=medium&amp;utm_medium=referral">Austin Distel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this case, we both shared the same encryption key, a process known as <a href="https://en.wikipedia.org/wiki/Symmetric-key_algorithm">Symmetric Encryption</a>. This means that the same encryption key must be used to decrypt the data.</p><p>In that project and some applications, where we want to encode and encrypt sensitive data, we also need to be able to decode and decrypt this information, when we need it, anywhere in our application, as such that the decrypted value is not altered during the process ensuring <a href="https://digitalguardian.com/blog/what-data-integrity-data-protection-101">Data Integrity</a>. Essentially:</p><pre>const value = 0123456789 // Initial value</pre><pre>const token = encrypt(value) // Encrypted token</pre><pre>const decryptedValue = decrypt(token) // Decrypted value</pre><pre>value === decryptedValue // Must be TRUE</pre><p>Simply using Base64 encoding, which will obfuscate and create short tokens is not a reliable security solution as Base64 strings can be easily decoded. For this article, I will demonstrate how you can create a simple, secure and fast <a href="https://en.wikipedia.org/wiki/Symmetric-key_algorithm">symmetric encryption</a> solution to encrypt data, and applied across any application even as short, SEO-friendly URL parameters using the following tools:-</p><ul><li><a href="https://www.typescriptlang.org/">Typescript</a> — adds static typed definitions to JavaScript</li><li><a href="https://en.wikipedia.org/wiki/Symmetric-key_algorithm">Symmetric Encryption</a> — cryptographic encryption technique which uses the same encryption keys for both encryption and decryption of data</li><li><a href="https://nodejs.org/api/crypto.html">Crypto</a> — built-in Node.js module which provides cryptographic functionality</li><li><a href="https://nodejs.org/api/buffer.html">Buffer</a> — subclass of JavaScript’s <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array"><strong>Uint8Array</strong></a> class used for character encoding and decoding</li><li>Testing using <a href="https://mochajs.org/">Mocha</a> and <a href="https://www.chaijs.com/">Chai</a></li><li>Automated testing, version management and package publishing using <a href="https://github.com/">GitHub</a>, <a href="https://circleci.com/">CircleCI</a> and <a href="https://github.com/semantic-release/semantic-release">Semantic release</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*702OHWe79gL-thYX" /><figcaption>Photo by <a href="https://unsplash.com/@ffstop?utm_source=medium&amp;utm_medium=referral">Fotis Fotopoulos</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Development</h3><p>You also need to have <strong>npm</strong> and/or <strong>yarn</strong> globally installed. See how to <a href="https://classic.yarnpkg.com/en/docs/install/">install YARN</a> and <a href="https://docs.npmjs.com/downloading-and-installing-node-js-and-npm">NPM</a>. I also prefer using <a href="https://github.com/nvm-sh/nvm#installing-and-updating">NVM</a> to manage my Node versions.</p><p>Next, we create our project folder and set up typescript:</p><pre>$ mkdir encrypt-decrypt-library<br>$ cd encrypt-decrypt-library</pre><p>Initialize <strong>package.json</strong> for the project:</p><pre>$ yarn init -y</pre><p>Next, we need to install Typescript as a dev dependency. This is because we will be compiling our Typescript code into JavaScript for our production build.</p><pre>$ yarn add -D typescript</pre><p>Next, we need to install <strong>ts-node</strong> to enable us execute Typescript files without needing to compile them and also <strong>@types/node</strong> .</p><pre>// TypeScript execution for node<br>$ yarn add -D ts-node @types/node</pre><p>Next, we need to add a <strong>tsconfig.json</strong> file to the root of our project for our Typescript configuration. We initialize a <strong>tsconfig.json</strong> file as follows:</p><pre>$ yarn tsc --init --rootDir src --outDir dist</pre><p>This will generate an initial <strong>tsconfig.json</strong> file at the root of the project with possible configuration options, with non-essential options commented out. I have updated this file as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e2b318c869e6198f5111556df51f57b/href">https://medium.com/media/2e2b318c869e6198f5111556df51f57b/href</a></iframe><p>Next, we need to install some additional packages for our library. Note that the NPM’s <a href="https://www.npmjs.com/package/crypto"><strong>crypto</strong></a> module has been deprecated as it is now a built-in Node module. This module provides us cryptographic functionalities like OpenSSL’s hash, cipher, decipher, sign, verify and HMAC functions.</p><p>We will be using the <a href="https://nodejs.org/api/buffer.html">Buffer</a> class to write and read unsigned 64-bit integers because JavaScript has a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER">maximum safe integer</a> of 53 bits and our library must be able to handle 64-bit big endian especially when we need to encrypt and decrypt large integers such as phone numbers.</p><p>We also need to install <a href="https://www.npmjs.com/package/dotenv">dotenv</a> to load environment variables from an <strong>.env</strong> file into <strong>process.env</strong> .</p><pre>$ yarn add -D dotenv</pre><p>Next, we need create our <strong>src</strong> directory and then our library file as follows:</p><pre>$ mkdir src<br>$ touch src/encryption.ts</pre><p>We also need to create an <strong>.env</strong> file to store our environmental variables and <a href="https://gist.github.com/s-barrah/a85649c4660bf5adfc6b5ecb110661ad"><strong>.env.example</strong></a> file to place all the keys of the <a href="https://gist.github.com/s-barrah/7503fd5bd92b182f62c549243da3656e"><strong>.env</strong></a> variables. The <strong>.env</strong> file must be ignored in a <a href="https://gist.github.com/s-barrah/333a4ea0c8e47e8f53bc0a99b9a3bb17"><strong>.gitignore</strong></a> file to prevent our environmental variables from getting into source control for security reasons.</p><pre>$ touch .env .env.example .gitignore</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/832d334a353a1055eb066a5a07c10586/href">https://medium.com/media/832d334a353a1055eb066a5a07c10586/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3de04298a098d203af376d188af6be36/href">https://medium.com/media/3de04298a098d203af376d188af6be36/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/194cdadb81576cb5ee3c6268f0b42d8c/href">https://medium.com/media/194cdadb81576cb5ee3c6268f0b42d8c/href</a></iframe><p>Next we create our encryption class by updating <strong>encryption.ts</strong> as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6eb85bdafaea9bf2c475a66f461bc0d3/href">https://medium.com/media/6eb85bdafaea9bf2c475a66f461bc0d3/href</a></iframe><p>On the browser, Javascript offers two functions for decoding and encoding base64 strings, <strong>btoa()</strong> and <strong>atob()</strong>, see <a href="https://developer.mozilla.org/en-US/docs/Glossary/Base64">Base64</a>. As our code runs outside of a browser and due to the problems associated with encoding and decoding UTF-16-bit <a href="https://developer.mozilla.org/en-US/docs/Web/API/DOMString">DOMString</a>, we will be encoding and decoding 64-bit Big Integers to Big endian bytes and vice versa using the <a href="https://nodejs.org/api/buffer.html">Buffer</a> class including <a href="https://nodejs.org/api/buffer.html#buffer_buf_writebiguint64be_value_offset"><strong>writeBigUInt64BE()</strong></a> and <a href="https://nodejs.org/api/buffer.html#buffer_buf_readbiguint64be_offset"><strong>readBigUInt64BE()</strong></a> methods:</p><pre><em>// allocate Buffer instance</em><br>const buf = Buffer.<em>allocUnsafe</em>(8);</pre><pre><em>// Write value to Buffer instance at the specified offset as big-endian.<br></em>buf.writeBigUInt64BE(BigInt(value));</pre><pre><em>// Read an unsigned, big-endian 64-bit integer from the Buffer instance at the specified offset<br>// and returns as a string<br></em>buf.readBigUInt64BE(0).toString();</pre><p>Next, we also need to implement cryptographic functionalities in our <strong>encrypt()</strong> and <strong>decrypt()</strong> functions. I have updated the <strong>Encryption </strong>class<strong> </strong>as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80ec5c8b73b32b01b87847e9d00b893b/href">https://medium.com/media/80ec5c8b73b32b01b87847e9d00b893b/href</a></iframe><p>For this, we use the built-in Node <a href="https://nodejs.org/api/crypto.html">Crypto library</a> and implement the <a href="https://nodejs.org/api/crypto.html#crypto_crypto_createcipheriv_algorithm_key_iv_options"><strong>crypto.createCipheriv()</strong></a>and <a href="https://nodejs.org/api/crypto.html#crypto_crypto_createdecipheriv_algorithm_key_iv_options"><strong>crypto.createDecipheriv()</strong></a> methods to create and return a <strong>Cipher</strong>and <strong>Decipher</strong> instance respectively using the following parameters:</p><ul><li><strong>algorithm</strong> — underlying algorithm being used, which is based on OpenSSL</li><li><strong>key</strong> — the raw key used by the algorithm</li><li><strong>iv</strong> — <a href="https://en.wikipedia.org/wiki/Initialization_vector">initialization vector</a></li></ul><p>To encrypt data, we use the <a href="https://nodejs.org/api/crypto.html#crypto_crypto_createcipheriv_algorithm_key_iv_options"><strong>crypto.createCipheriv()</strong></a> method to create a <strong>Cipher</strong> instance and then <a href="https://nodejs.org/api/crypto.html#crypto_cipher_update_data_inputencoding_outputencoding">cipher.update()</a> and <a href="https://nodejs.org/api/crypto.html#crypto_cipher_final_outputencoding">cipher.final()</a> methods to produce the encrypted data. To decrypt the data, we use the <a href="https://nodejs.org/api/crypto.html#crypto_crypto_createdecipheriv_algorithm_key_iv_options"><strong>crypto.createDecipheriv()</strong></a> method to create a <strong>Decipher</strong> instance and <a href="https://nodejs.org/api/crypto.html#crypto_decipher_update_data_inputencoding_outputencoding">decipher.update()</a> and <a href="https://nodejs.org/api/crypto.html#crypto_decipher_final_outputencoding">decipher.final()</a> methods to produce the unencrypted data. See <a href="https://nodejs.org/api/crypto.html#crypto_crypto_createcipheriv_algorithm_key_iv_options">CreateCipherIV</a> and <a href="https://nodejs.org/api/crypto.html#crypto_crypto_createdecipheriv_algorithm_key_iv_options">CreateDecipherIV</a> for more on <strong>crypto</strong> methods and options.</p><p>Both our <strong>encrypt()</strong> and <strong>decrypt()</strong> methods use <a href="https://en.wikipedia.org/wiki/Symmetric-key_algorithm">symmetric encryption</a> algorithms, ensuring that the same encryption key used in encrypting the data must be used in decrypting it. <a href="https://www.cryptomathic.com/news-events/blog/symmetric-encryption-algorithms-their-strengths-and-weaknesses-and-the-need-for-crypto-agility">Learn more about Symmetric Encryption Algorithms.</a> Next, we need to add some tests to our library.</p><h4>Tests</h4><p>To add tests to our library, we need to install some dependencies namely <a href="https://mochajs.org/">Mocha</a> and <a href="https://www.chaijs.com/">Chai</a>:</p><pre>$ yarn add -D mocha @types/mocha chai @types/chai</pre><p>We need to add some tests for our <strong>encrypt</strong> and <strong>decrypt</strong> methods. First, we need to create a <strong>tests</strong> folder in the root of our project. This folder will contain our test files. Next, we create a test file, <strong>encryption.test.ts</strong>:</p><pre>$ mkdir tests<br>$ touch tests/encryption.test.ts</pre><p>Update the <strong>encryption.test.ts</strong> file as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60265d947f548d38e4c77f7441eedabe/href">https://medium.com/media/60265d947f548d38e4c77f7441eedabe/href</a></iframe><p>The <strong>ALGORITHM</strong>, <strong>ENCRYPTION_KEY</strong> and <strong>SALT</strong> are environmental variables set in our .env file.</p><p>Next, we need to update the <strong>scripts</strong> property in our <strong>package.json</strong> with our <strong>test</strong> command:</p><pre><strong>// </strong>package.json</pre><pre><strong>&quot;scripts&quot;: {<br>  &quot;test&quot;: &quot;./node_modules/.bin/mocha \&quot;tests/**/*.ts\&quot; --require ts-node/register --require dotenv/config&quot;<br>},</strong></pre><p>We are able to define node scripts to run within the <strong>scripts</strong> property of our <strong>package.json</strong> file.</p><p>We run the test using Node CLI arguments — Mocha requiring <strong>ts-node</strong> so we can execute the Typescript test file without needing to compile them. We register the <strong>ts-node</strong> loader by using <strong>ts-node/register</strong>. We also specify the path to the test files. It will run every test file within the <strong>tests</strong> folder matching the pattern. It also requires <strong>dotenv/config</strong>, which allows us to use variables set in our <strong>.env</strong> file.</p><p>To start the test, we simply run in the command line <strong>yarn run test</strong>.</p><pre>$ yarn run test</pre><pre><strong>yarn run v1.22.4</strong></pre><pre>$ ./node_modules/.bin/mocha &quot;tests/**/*.ts&quot; --require ts-node/register --require dotenv/config</pre><pre>Encryption<br>    Ensuring encrypting and decrypting of string and number<br>      ✓ should encrypt and decrypt the string correctly<br>      ✓ should encrypt and decrypt the number as a big integer correctly<br>      ✓ should encrypt and decrypt the number as a string correctly<br>    Ensure decrypting of Big Integer token into a valid number<br>      ✓ should decrypt the encoded slug to a Big Integer correctly<br>    Ensure decrypting of string token into a valid string or number<br>      ✓ should decrypt the encoded slug to a valid string correctly<br>    Ensure decrypting of an 8-byte Big integer token into a valid number<br>      ✓ should decrypt the encoded slug to a Big Integer correctly<br>    Ensure validation of encrypt or decrypt methods <br>      ✓ should return an error message if encrypt has no value<br>      ✓ should return an error message if decrypt has no value<br>    Ensure validation of library with no configuration<br>      ✓ should fail to encrypt the string correctly<br>      ✓ should fail to decrypt the string correctly</pre><pre>10 passing (25ms)</pre><h4>Linting</h4><p>To ensure we have a clear and consistent coding convention in our library, it is important to add linting. Linting helps development by enforcing code style, identifying, reporting and fixing any inconsistencies and bugs in our code. For our Encryption library, I have opted to use <a href="https://eslint.org/"><strong>ESLint</strong></a> because it supports both JavaScript and TypeScript.</p><p>First, install all the required dev dependencies:</p><ul><li><a href="https://www.npmjs.com/package/eslint"><strong>eslint</strong></a> — ESLint linting library</li><li><a href="https://www.npmjs.com/package/@typescript-eslint/parser"><strong>@typescript-eslint/parser</strong></a> — TypeScript parser for ESLint</li><li><a href="https://www.npmjs.com/package/@typescript-eslint/eslint-plugin"><strong>@typescript-eslint/eslint-plugin</strong></a> — A plugin with TypeScript specific ESLint rules</li></ul><pre>// Install ESLint and plugins<br>$ yarn add -D eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin</pre><p>We also need to install <a href="https://www.npmjs.com/package/prettier">Prettier</a>, which works very well with <a href="https://eslint.org/">ESLint</a> and is great at handling code formatting.</p><ul><li><a href="https://www.npmjs.com/package/prettier"><strong>prettier</strong></a> — the core prettier library</li><li><a href="https://www.npmjs.com/package/eslint-config-prettier"><strong>eslint-config-prettier</strong></a><strong> </strong>— disables ESLint rules that might conflict with prettier</li><li><a href="https://www.npmjs.com/package/eslint-plugin-prettier"><strong>eslint-plugin-prettier</strong></a> — runs Prettier as an ESLint rule</li></ul><pre>// Install Prettier and plugins<br>$ yarn add -D prettier eslint-config-prettier eslint-plugin-prettier</pre><pre>// Installs husky and lint<br>$ yarn add -D husky lint-staged</pre><p>We also installed <a href="https://github.com/okonet/lint-staged#readme"><strong>lint-staged</strong></a> which ensures that linting is run on files before they are committed. This ensures that all files committed to GIT don’t have any linting or formatting errors. <a href="https://github.com/typicode/husky#readme"><strong>Husky</strong></a> used in combination with lint-staged enables us to run specified linting commands on pre-commit and helps make git hooks easier. You can read more about <a href="https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks">Git Hooks here</a>.</p><p>We then need to set up a configuration file for ESLint:</p><pre>$ npx eslint --init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vxOnxk-DN5hBQ_F2p8OrvQ.png" /><figcaption>ESLint init</figcaption></figure><p>This generates a configuration file .<strong>eslintrc.js</strong>. I have added some modifications with our plugins and rules:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2530ce193301bbf63f01d9ffb5e76ff6/href">https://medium.com/media/2530ce193301bbf63f01d9ffb5e76ff6/href</a></iframe><p>Next, create an .<strong>eslintignore</strong> file that tells ESLint the directories or files to ignore and add the following:</p><pre>node_modules<br>dist<br>tests<br>coverage<br>styleguide.config.js</pre><pre>src/**/*.test.tsx<br>src/**/*.md<br>src/serviceWorker.ts</pre><p>Update our <strong>package.json</strong>by adding our lint command to the <strong>scripts</strong> property:</p><pre>// <strong>package.json</strong></pre><pre><strong>&quot;scripts&quot;: {<br>  ...<br>  &quot;lint&quot;: &quot;eslint &#39;src/**/*.{js,ts}&#39; --quiet --fix&quot;<br>},</strong></pre><p>The above script can be run from the command line using <strong>npm run lint</strong> or <strong>yarn lint</strong>. This command will run ESLint through all the .js and .ts files. It will automatically fix any ESLint errors, but any other errors will be printed out in the command line.</p><p>To configure <strong>lint-staged</strong> and <strong>husky</strong>, we also add the following configuration to the <strong>package.json</strong> :</p><pre>// package.json</pre><pre><strong>&quot;husky&quot;: {<br>  &quot;hooks&quot;: {<br>    &quot;pre-commit&quot;: &quot;lint-staged&quot;<br>  }<br>},<br>&quot;lint-staged&quot;: {<br>  &quot;src/**/*.{js,ts}&quot;: [<br>    &quot;prettier --single-quote --write&quot;,<br>    &quot;eslint --fix&quot;<br>  ]<br>},</strong></pre><p>With the configuration above, anytime a commit is made to git, <strong>lint-staged</strong> will run Prettier and ESLint on any staged files with matching extensions. It will automatically fix any errors that can be amended and add them to the current commit. However, it will fail if there are linting errors that cannot be fixed automatically. These errors will need to be fixed manually before trying to commit the code again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ozUqXJG8rsR2HI6HyzgKVA.png" /><figcaption>Husky -pre-commit</figcaption></figure><h3>Production</h3><p>To use our Encryption library as an NPM module, we need to export our Encryption class and then compile our Typescript files into JavaScript.</p><p>First, we create our export file <strong>index.ts</strong> in our <strong>src</strong> folder as follows:</p><pre>$ touch src/index.ts</pre><p>and export our Encryption class as follows:</p><pre>import Encryption from &quot;./encryption&quot;;<br><br>export default Encryption;</pre><p>For production, we add a <strong>build</strong> script to the <strong>scripts</strong> property of our <strong>package.json</strong>:</p><pre>// package.json</pre><pre><strong>&quot;scripts&quot;: {<br>  ...<br>  &quot;build&quot;: &quot;NODE_ENV=production tsc&quot;<br>},</strong></pre><p>The <strong>rootDir</strong> and <strong>outDir</strong> properties of the compiler options in the <strong>tsconfig.json</strong> file specifies the root directory of the input files and the output directory for the compiled files. Running <strong>yarn build</strong> will compile the TypeScript files into JavaScript files in the <strong>dist</strong> folder.</p><p>We also need to install <a href="https://www.npmjs.com/package/rimraf"><strong>rimraf</strong></a> dev dependency, which acts like the <strong>rm -rf</strong> command.</p><pre>$ yarn add -D rimraf</pre><p>Next we update <strong>package.json</strong> by updating our build script and adding <strong>main</strong> and <strong>module</strong> properties to set the entry point for our library, which is our compiled Javascript file and the <strong>types</strong> property to points to our Typescript declaration entry file:</p><pre>// package.json</pre><pre><strong>&quot;scripts&quot;: {<br>  ...<br>  &quot;build&quot;: &quot;</strong><strong>rimraf ./dist &amp;&amp; NODE_ENV=production tsc&quot;<br>},<br>......<br>&quot;main&quot;: &quot;dist/index.js&quot;,<br>&quot;module&quot;: &quot;dist/index.js&quot;,<br>&quot;types&quot;: &quot;dist/index.d.ts&quot;</strong></pre><p>Now, when we run <strong>yarn build</strong>, <strong>rimraf</strong> will remove our old <strong>dist</strong> folder before the TypeScript compiler emits new code to <strong>dist</strong>.</p><h4>Documentation</h4><p>It is always important to include reliable documentation to help us keep track of the various aspects of an application. It helps improve on the quality of the code and makes it easier for further development, maintenance and knowledge transfer.</p><p>Next, we need to create a <strong>README.md</strong> file at the root of our project:</p><pre>$ touch README.md</pre><p>And update as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/70e800272f56d0534fdc15f31ac83c44/href">https://medium.com/media/70e800272f56d0534fdc15f31ac83c44/href</a></iframe><h4>Publishing</h4><p>Before we can publish our library, we want to exclude certain files from our final package. We will be doing this by adding a <strong>files</strong> property to our <strong>package.json</strong> , which tells <a href="https://www.npmjs.com/">NPM</a> which <strong>files</strong> and/or <strong>directories</strong> to include in our package:</p><pre>// package.json</pre><pre><strong>&quot;files&quot;: [ &quot;dist&quot; ],</strong></pre><p>We also create an .<strong>npmignore</strong> file at the root of our project, which also specifies which directories or files for <a href="https://www.npmjs.com/">NPM</a> to ignore:</p><pre>// .<strong>npmignore</strong></pre><pre>src<br>node_modules<br>tests<br>.idea<br>coverage</pre><p>Next, we publish our package to <a href="https://www.npmjs.com/">NPM</a> by running <strong>npm publish</strong> in the command line. You need to have an account on <a href="https://www.npmjs.com/">NPM</a> and may need to run <strong>npm login</strong> to log into your <a href="https://www.npmjs.com/">NPM</a> account before you can publish. Accounts on NPM are free. NPM also requires that the name of your package is unique.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LM7FvbNgHG2Nl2gyIv-XPQ.png" /><figcaption>npm publish CLI</figcaption></figure><h4>Automated Workflow</h4><p>It is important that we automate the release process as this saves time and improves code quality. It allows us to be able to automate the various steps above, such as installing dependencies, linting, testing, versioning and publishing our library to NPM.</p><p>Please see my article, <a href="https://medium.com/@sidneyb231/how-to-automate-continuous-integration-and-development-versioning-and-publishing-a7d4b3311f3"><strong>How to Automate Continuous Integration and Development, Versioning and Publishing</strong></a> for a step by step guide on how to setup CI/CD using Github, CircleCI and Semantic Release to automate your workflows including test automation, linting, versioning, deployment and publishing to NPM.</p><h4>Status Badges</h4><p>We may need to include build badges in our project to provide public access to the build status of our package. Status badges can be embedded at the top of the project’s README file.</p><p>We will be adding CircleCI and Semantic Release status badges at the top of our project’s README file. See <a href="https://circleci.com/docs/2.0/status-badges/"><strong>CircleCI — Adding Status Badges</strong></a>.</p><pre># <strong>CircleCI Template:</strong> <br>[![CircleCI](https://circleci.com/&lt;VCS&gt;/&lt;ORG_NAME&gt;/&lt;PROJECT_NAME&gt;.svg?style=svg)](&lt;LINK&gt;)</pre><pre># <strong>Semantic Release Template</strong>: <br>[![semantic-release](https://badge.fury.io/js/&lt;PROJECT_NAME&gt;.svg?style=svg)](&lt;NPM-PACKAGE-LINK&gt;)</pre><pre>// <strong>CircleCI Build Status</strong><br>[![CircleCI](https://circleci.com/gh/s-barrah/encrypt-decrypt-library.svg?style=svg)](<em>https://app.circleci.com/pipelines/github/s-barrah/encrypt-decrypt-library</em>)</pre><pre>// <strong>Semantic Release </strong><br>[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](<em>https://github.com/semantic-release/semantic-release</em>)</pre><pre>// <strong>NPM Status</strong><br>[![semantic-release](https://badge.fury.io/js/encrypt-decrypt-library.svg)](<em>https://www.npmjs.com/package/encrypt-decrypt-library</em>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LAj7zj02vk_BUHOTD7tXpA.png" /><figcaption>Status Badges</figcaption></figure><h4>Usage</h4><p>To use our library in any project, install using YARN or NPM:</p><pre>// Via Yarn<em><br></em>$ yarn add encrypt-decrypt-library</pre><pre>// Via NPM<em><br></em>$ npm install --save encrypt-decrypt-library</pre><p>And we can import and use anywhere in the project:</p><pre>import Encryption from &quot;encrypt-decrypt-library&quot;;</pre><pre>const config = {<br>   algorithm: process.env.ALGORITHM,<br>   encryptionKey: process.env.ENCRYPTION_KEY,<br>   salt: process.env.SALT,<br>} <br>const encryption = new Encryption(config);</pre><pre>// Encrypt a string<br>encryption.encrypt(&#39;Hello world&#39;)</pre><pre>// Encrypted as an unsigned 64-bit Integer<br>encryption.encrypt(123, true)</pre><pre>// Encrypted as string<br>encryption.decrypt(&#39;gmmBh17Q4QA=&#39;)<br><br>// Encrypted as an integer<br>encryption.decrypt(&#39;NF1r855MimY=&#39;, true)</pre><h3>Conclusion</h3><p>There are various reasons why we may need to encrypt and decrypt data. We may want to pass sensitive information as URL parameters and want it obfuscated from users. Base64 encoding can create short and SEO-friendly URL tokens and in Node, libraries such as<a href="https://www.npmjs.com/package/atob"><strong>atob</strong></a> and <a href="https://www.npmjs.com/package/btoa"><strong>btoa</strong></a> can emulate the browsers functionality, however, Base64 encoding is not secure. You can read more about <a href="https://developer.mozilla.org/en-US/docs/Glossary/Base64">JavaScript Base64</a>.</p><p>The aim of this article was to demonstrate how to create a simple and easy-to-use encryption library that can be imported and used in any of our projects to encode and encrypt simple strings and numbers into short, secure and SEO-friendly URL parameters.</p><p>There are a few NPM libraries that provide encryption and encoding such as <a href="https://www.npmjs.com/package/crypto-js">CryptoJS</a>. You can also explore this <a href="https://gist.github.com/jo/8619441">list of JavaScript Crypto libraries</a> and decide what fits your use case.</p><p>Feel free to clone, fork or star my Simple Encryption library GitHub repository below if it helps you:</p><p><a href="https://github.com/s-barrah/encrypt-decrypt-library">s-barrah/encrypt-decrypt-library</a></p><h3>Further Reading</h3><ul><li><a href="https://www.cryptomathic.com/news-events/blog/symmetric-key-encryption-why-where-and-how-its-used-in-banking">Symmetric Key Encryption — why, where and how it’s used in banking</a></li><li><a href="https://www.cryptomathic.com/news-events/blog/differences-between-hash-functions-symmetric-asymmetric-algorithms">Differences between Hash functions, Symmetric &amp; Asymmetric Algorithms</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Crypto">Crypto — Web API interface</a></li><li><a href="https://github.com/typescript-eslint/typescript-eslint">TypeScript ESLint</a></li><li><a href="https://www.robertcooper.me/using-eslint-and-prettier-in-a-typescript-project">Using ESLint and Prettier in a TypeScript Project</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/DOMString/Binary">Binary Strings</a></li><li><a href="https://blog.bigbinary.com/2011/07/20/ruby-pack-unpack.html">Ruby pack and unpack</a></li><li><a href="https://medium.com/sharenowtech/high-speed-public-key-cryptography-in-javascript-part-1-3eefb6f91f77">High speed, public-key cryptography in JavaScript</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d72c294998bf" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/a-simple-encryption-library-in-node-js-with-typescript-d72c294998bf">A Simple encryption library in Node.js with Typescript</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Automate Continuous Integration and Development, Versioning and Publishing]]></title>
            <link>https://medium.com/swlh/how-to-automate-continuous-integration-and-development-versioning-and-publishing-a7d4b3311f3?source=rss-9983385adb9e------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7d4b3311f3</guid>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[circleci]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Sidney Barrah]]></dc:creator>
            <pubDate>Wed, 16 Sep 2020 20:17:34 GMT</pubDate>
            <atom:updated>2020-09-17T21:36:23.644Z</atom:updated>
            <content:encoded><![CDATA[<h4>Using GitHub, CircleCI and Semantic Release</h4><p>One of the most important tools in developing great software is the ability to automate. Imagine every time you need to release code to production, you have to repeat the same manual steps such as running tests, tagging/versioning your code changes and then manually provisioning or updating software or the configuration of your infrastructure, which can easily become the stuff of nightmares and create several horrific scenarios.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_Xmvw4Kww0JwA600" /><figcaption>Photo by <a href="https://unsplash.com/@spacexuan?utm_source=medium&amp;utm_medium=referral">Crystal Kwok</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Imagine the cost in developer time, resources and also the fact that manual testing can become very complicated as code becomes more complex which can increase the chances of bugs and errors slipping through into production. Automating the process will save time and improve code quality, as you only need to focus on the quality of your code and errors can be detected before they get into production. Running automated tests every time code is deployed, ensures that bugs are caught quickly and fixed promptly.</p><p>An automated process also ensures that we can implement and test new features quickly and also fix bugs multiple times. An automated build process allows us to have a single source of truth in terms of how our code looks and how it works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*V_HDZzVU6c9zmtGN" /><figcaption>Photo by <a href="https://unsplash.com/@jessbaileydesigns?utm_source=medium&amp;utm_medium=referral">Jess Bailey</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When we create and publish packages to NPM, we want to be able to automate how we track GIT changes and publishing of our package. This saves time from manually managing versions of the package.</p><p>There are a few tools that help simplify this process and I will be focusing on how I use the following tools:</p><ul><li><a href="https://github.com/">GitHub</a> and <a href="https://circleci.com/">CircleCI</a> — to automate deployment and work flow</li><li><a href="https://github.com/semantic-release/semantic-release">Semantic release</a> — to automate version management and package publishing to <a href="https://www.npmjs.com/">NPM</a>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cM1f6OIwaaLKKOj3" /><figcaption>Photo by <a href="https://unsplash.com/@ripato?utm_source=medium&amp;utm_medium=referral">Ricardo Gomez Angel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Continuous Integration and Development, Versioning and Publishing</h4><p>Being able to automate how we track GIT changes, versioning and publishing of our package aids our Continuous Integration and Continuous Development process.</p><p><a href="https://github.com/semantic-release/semantic-release">Semantic Release</a> provides us with the ability to automate version management and the publishing of our package to <a href="https://www.npmjs.com/">NPM</a>.</p><p>Installing <a href="https://www.npmjs.com/package/semantic-release-cli"><strong>semantic-release-cli</strong></a> as a dev dependency and running <strong>semantic-release-cli setup</strong> to configure our CI/CD process allows us to automate the Semantic release setup process and sets up all default configurations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XoKZss2kWB4eZfszylZeLw.png" /><figcaption>semantic-release-cli setup</figcaption></figure><p>With <a href="https://www.npmjs.com/package/semantic-release-cli"><strong>semantic-release-cli</strong></a><strong> , </strong>we can do the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x_FGD3p2aSVBzoV4uwCZVg.png" /><figcaption>semantic-release-cli<strong> </strong>steps</figcaption></figure><p>Next, we can use an existing an GitHub repository or create a remote repository in GitHub and push our project to the remote repository. You can read more about <a href="https://docs.github.com/en/github/getting-started-with-github">getting started with GitHub</a> and <a href="https://docs.github.com/en/github/getting-started-with-github/create-a-repo">how to create a repository</a>.</p><p>I usually opt to manually setup my CI by setting up a new project in the <strong>CircleCI Dashboard</strong>. You can read more about how to <a href="https://circleci.com/docs/2.0/getting-started/#setting-up-circleci">set up CircleCI</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xmMX0arYAhGLycZuWRjY0w.png" /><figcaption>CircleCI Project setup</figcaption></figure><p>Next, CircleCI requires a configuration file in the project. We have to create a <strong>.circleci</strong> folder and <strong>config.yml</strong> which will include our jobs and workflows:</p><pre>// Create CircleCI configuration folder<br>$ mkdir .circleci</pre><pre>// Create configuration file<br>$ touch .circleci/config.yml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*9Z_fpYEtX_KvLJ4K76DpuA.png" /><figcaption>CircleCI Project setup</figcaption></figure><p>Set up all authentication tokens and environmental variables for your project such as GH_TOKEN/ GITHUB_TOKEN and NPM_TOKEN in the CI or in this case, <a href="https://circleci.com/">CircleCI</a>. Read <a href="https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token">Creating a personal access token</a> on how to create an access token on <a href="https://github.com/">GitHub</a>. Also, you must have an account on <a href="https://www.npmjs.com/">NPM</a> to create an access token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7br8o4FvFInBGtgOvwrm-w.png" /><figcaption>CircleCI Project settings</figcaption></figure><p>To add environmental variables, click on the Add Variable button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*guTWfVDorziHNT4oGLaP-w.png" /><figcaption>Adding Environmental variables in CircleCI</figcaption></figure><p>Install <a href="https://www.npmjs.com/package/semantic-release"><strong>semantic-release</strong></a> as a dev dependency, which automates the package release workflow including: determining the next version number, generating the release notes and publishing the package to NPM.</p><pre>// Install Semantic release <br>$ yarn add -D semantic-release</pre><p><a href="https://github.com/semantic-release/semantic-release">Semantic Release</a> expects commits to be in the conventional GIT commit format like<strong>feat: add feature X</strong> or <strong>fix: fix bug Y</strong> that perform <strong>minor</strong> and <strong>patch</strong> version bumps respectively.</p><p>Next, because Semantic Release will set the version automatically, we set the <strong>version</strong> property to <strong>0.0.0-development</strong> and add a <strong>semantic-release</strong> command to the <strong>scripts</strong> property in <strong>package.json</strong></p><pre>// package.json</pre><pre><strong>&quot;version&quot;: &quot;0.0.0-development&quot;,<br>...<br>&quot;scripts&quot;: {<br>  ...<br>  &quot;</strong><strong>semantic-release&quot;: &quot;</strong><strong>semantic-release&quot;<br>},</strong></pre><p>All the manual steps above can be set up automatically running <strong>semantic-release-cli setup</strong> command.</p><p>Next, you update your CircleCI <strong>config.yml</strong> file as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52e388763a0114449a01a395706fffaf/href">https://medium.com/media/52e388763a0114449a01a395706fffaf/href</a></iframe><p>The <a href="https://circleci.com/">CircleCI</a> configuration is triggered on every push to our remote repository on <a href="https://github.com/">GitHub</a>. These steps are run in sequence, so this means that every time we trigger a deploy it runs the following steps as part of our workflow -</p><ul><li><strong>yarn install</strong> — installs our dependencies;</li><li><strong>yarn lint </strong>—<strong> </strong>lints and tests our code style;</li><li><strong>yarn test </strong>—<strong> </strong>runs feature tests</li><li><strong>yarn build </strong>—<strong> </strong>runs the build process of compiling our code from Typescript to JavaScript</li><li><strong>yarn semantic-release </strong>—<strong> </strong>creates a version tag and publishes the code to NPM</li></ul><p>If any of the steps fail, then the entire build process will fail and nothing is released to production.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*7PvvX4w-Zn1GVx08Z52uBg.png" /><figcaption>CircleCI Build Error</figcaption></figure><p>You can also drill down on the error to identify what caused the build to fail</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jxX7eor-xkIf6UXXF-ul3Q.png" /></figure><p>To trigger a deployment, create a GIT commit and push to the master branch:</p><pre>$ git commit -m &quot;fix: xxx&quot;</pre><pre>$ git push origin master</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qBuKDfh69TeGQVL2SCBzsQ.png" /><figcaption>CircleCI Workflow Success</figcaption></figure><p>This will trigger a new release in NPM:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ftm2ag-Z4GAsDT9TTuW9wQ.png" /><figcaption>CircleCI</figcaption></figure><p>To use, import the latest version of the library into any of your projects.</p><h4>Wrap Up</h4><p>Automating our code release process ensures that we ship quickly, save on costs and time, and improve our code quality and it should always be our core focus when architecting a new system / product.</p><p>I hope this article gives you a good foundation to automate your workflow, manage versioning and publish your package to NPM using the tools outlined above.</p><p>I have included a <a href="https://github.com/s-barrah/encrypt-decrypt-library">Github repository</a> with the implementation described in this article. Feel free to clone, fork or star it if it helps you.</p><p><a href="https://github.com/s-barrah/encrypt-decrypt-library">s-barrah/encrypt-decrypt-library</a></p><h3>Further Reading</h3><ul><li><a href="https://circleci.com/blog/what-is-continuous-integration/">What is Continuous Integration?</a></li><li><a href="https://thetrampery.com/2016/08/02/automation-king-stages-software-development/#:~:text=If%20your%20developers%20use%20automation,do%20what%20they%20do%20best.">Why Automation is King — at All Stages of Software Development</a></li><li><a href="https://circleci.com/docs/2.0/getting-started/#setting-up-circleci">Getting started with CircleCI</a></li><li><a href="https://blog.greenkeeper.io/introduction-to-semantic-release-33f73b117c8">Introduction to Semantic Release</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7d4b3311f3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/how-to-automate-continuous-integration-and-development-versioning-and-publishing-a7d4b3311f3">How to Automate Continuous Integration and Development, Versioning and Publishing</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a React Component Library With Typescript Using Styleguidist]]></title>
            <link>https://medium.com/swlh/creating-a-react-component-library-with-typescript-using-styleguidist-67e33f5e712a?source=rss-9983385adb9e------2</link>
            <guid isPermaLink="false">https://medium.com/p/67e33f5e712a</guid>
            <category><![CDATA[semantic-versioning]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Sidney Barrah]]></dc:creator>
            <pubDate>Sun, 12 Jul 2020 23:44:20 GMT</pubDate>
            <atom:updated>2021-05-07T21:35:12.021Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to build a reusable component library, publish and automate the release flow</h4><p>One of the beauties of React is component reusability, which is a huge time saver. Most times, creating new components for a project may mean that you may have to do the same for every new project which will ultimately result in unavoidable code duplication.</p><p>Having a component library ensures that reusable components can be packaged and shared across multiple applications, meaning that you do not have to worry about code duplication, makes it faster to build new applications and helps speed up scalable application development. Components can easily be customised at the project level for each application they belong to. It also means that issues such as bug fixes and adding new features can be done at source and pulled through on every project that needs it.</p><p>In this post, I explain how to create a React component library using the following tools:-</p><ul><li><a href="https://create-react-app.dev/docs/adding-typescript/">Create React App with Typescript</a></li><li><a href="https://react-styleguidist.js.org/">React styleguidist</a> — to help with component development</li><li><a href="https://styled-components.com/">Styled-components </a>— allows you to style your components by utilising the power of CSS and tagged template literals.</li><li><a href="https://bradfrost.com/blog/post/atomic-web-design/">Atomic Design</a> — introduced by Brad Frost and helps in designing systems of components</li><li><a href="https://blog.sapegin.me/all/react-jest/">Testing using Jest with Enzyme</a></li><li>Automated deployment using <a href="https://github.com/">GitHub</a>, <a href="https://circleci.com/">CircleCI</a> and <a href="https://www.netlify.com/">Netlify</a></li><li><a href="https://github.com/semantic-release/semantic-release">Semantic release</a> - automates version management and package publishing.</li></ul><h3>Development</h3><p>Create a new React project with CRA using npx for the latest version</p><pre>// Using npx<br>$ npx create-react-app react-component-library --template typescript</pre><pre>$ cd react-component-library</pre><pre>// Start app<br>$ yarn start</pre><p>The next step is to install dependencies required by our project:</p><pre>// Install babel compiler  and plugins<br>$ yarn add @babel/cli @babel/node<br>$ yarn add -D @babel/core @babel/preset-env @babel/preset-typescript babel-plugin-styled-components </pre><pre>// Install styled components and dependencies<br>$ yarn add styled-components @types/styled-components <br>$ yarn add -D typescript-plugin-styled-components</pre><pre>// Install react styleguidist and dependencies<br>$ yarn add react-styleguidist</pre><pre>// Generates styleguidist documentation from Typescript <br>$ yarn add -D react-docgen-typescript</pre><pre>// Adds documentation to components<br>$ yarn add prop-types</pre><h4>Configuration</h4><p>After installing all dependencies, you should create a configuration file for babel babel.config.js at the root of your project and add the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/414e7cbc72ed7d4e8a9c544c9cff1da8/href">https://medium.com/media/414e7cbc72ed7d4e8a9c544c9cff1da8/href</a></iframe><p>Next, we need to add a configuration file for <a href="https://react-styleguidist.js.org/">React-styleguidist</a>, styleguide.config.js at the root of your project and add the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c204714424d5813468d650d8b9273ccc/href">https://medium.com/media/c204714424d5813468d650d8b9273ccc/href</a></iframe><p>You can find out more about <a href="https://react-styleguidist.js.org/docs/configuration/">React-Styleguidist configuration</a>.</p><h4>Documentation</h4><p>We need to add some documentation for our library. In this case, I create a docs folder at the project root and create an introduction.md file</p><pre>// At project root<br>$ mkdir docs<br>$ cd docs<br>$ touch introduction.md</pre><p>And added some content about our library:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20bf87b623ef437479cb704a375b308f/href">https://medium.com/media/20bf87b623ef437479cb704a375b308f/href</a></iframe><h4>Theme</h4><p>The next step is for us to create a theme for our project. You can create as many project specific themes as you want, especially if your have multiple projects that need to use different styles.</p><p>For this demo, I will be creating a theme for a project1 with specific and shared theme functions.</p><p>First we create our theme folder, then create files for our theme functions and our ThemeProvider high order component:</p><pre>// At project root, create the theme folder<br>$ mkdir src/theme </pre><pre>// Create a project folder<br>$ mkdir src/theme/project1 </pre><pre>// Create a shared utils folder<br>$ mkdir src/theme/shared</pre><pre>// Add Colour theme <br>$ touch src/theme/project1/color.ts</pre><pre>// Add Font Sizes theme<br>$ touch src/theme/project1/fontSize.ts</pre><pre>// Exports themes<br>$ touch src/theme/project1/theme.ts</pre><pre>// Add Font family theme<br>$ touch src/theme/shared/fontFamily.ts</pre><pre>// Add breakpoint theme<br>$ touch src/theme/shared/breakpoint.ts</pre><pre>// Theme Provider HOC<br>$ touch src/theme/ThemeProvider.ts</pre><p>Modify the <strong>color.ts</strong> file</p><pre>// src/theme/project1/color.ts</pre><pre><strong>const </strong>colors: {[<strong>index</strong>: <strong>string</strong>]: <strong>string </strong>} = {<br>  <strong>red</strong>: <strong>&#39;#e94b35&#39;</strong>,<br>  <strong>blue</strong>: <strong>&#39;#337ab7&#39;</strong>,<br>  <strong>blueHover</strong>: <strong>&#39;#286090&#39;</strong>,<br>  <strong>green</strong>: <strong>&#39;#3c763d&#39;</strong>,<br>  <strong>greenHover</strong>: <strong>&#39;#2b542c&#39;</strong>,<br>  <strong>orange</strong>: <strong>&#39;#ff9900&#39;</strong>,<br>  <strong>white</strong>: <strong>&#39;#FFFFFF&#39;</strong>,<br>};<br><br><br><strong>const </strong><em>color </em>= (colorName: <strong>string</strong>): <strong>string </strong>=&gt; {<br>  <strong>return </strong>colorName ? colors[colorName] : <strong>&#39;inherit&#39;</strong>;<br>};<br><br><strong>export default </strong><em>color</em>;</pre><p>Next, modify the <strong>fontSize.ts</strong> file</p><pre>// src/theme/project1/fontSize.ts</pre><pre><strong>export const <em>fontSizes</em></strong>: {[<strong>index</strong>: <strong>string</strong>]: <strong>string </strong>} = {<br>  <strong>xs</strong>: <strong>&#39;0.83125rem&#39;</strong>,<br>  <strong>s</strong>: <strong>&#39;1rem&#39;</strong>,<br>  <strong>m</strong>: <strong>&#39;1.2rem&#39;</strong>,<br>  <strong>l</strong>: <strong>&#39;1.44rem&#39;</strong>,<br>  <strong>xl</strong>: <strong>&#39;1.725rem&#39;</strong>,<br>  <strong>super</strong>: <strong>&#39;6.25rem&#39;</strong>,<br>};<br><br><strong>const </strong><em>fontSize </em>= (size: <strong>string</strong>): <strong>string </strong>=&gt; {<br>  <strong>return </strong>size ? <strong><em>fontSizes</em></strong>[size] : <strong>&#39;&#39;</strong>;<br>};<br><br><strong>export default </strong><em>fontSize</em>;</pre><p>Also, modify the shared fonts <strong>fontFamily.ts</strong> file</p><pre>// src/theme/shared/fontFamily.ts<strong><br>interface </strong>IFontFamilies {<br>  [<strong>index</strong>: <strong>string</strong>]: {<br>    <strong>font</strong>: <strong>string</strong>;<br>    <strong>fallback</strong>: <strong>string</strong>;<br>  }<br>}<br><br><strong>const </strong>fontFamilies: IFontFamilies = {<br>  <strong>Montserrat</strong>: { <strong>font</strong>: <strong>&#39;Montserrat&#39;</strong>, <strong>fallback</strong>: <strong>&#39;Helvetica, Arial&#39; </strong>},<br>  <strong>Anton</strong>: { <strong>font</strong>: <strong>&#39;Anton&#39;</strong>, <strong>fallback</strong>: <strong>&#39;Helvetica, Arial&#39; </strong>},<br>  <strong>Trebuchet</strong>: { <strong>font</strong>: <strong>&#39;Trebuchet MS&#39;</strong>, <strong>fallback</strong>: <strong>&#39;Helvetica, Arial&#39; </strong>},<br>};<br><br><strong>export default </strong>(family: <strong>string</strong>) =&gt; {<br>  <strong>return </strong>family ? <strong>`&#39;</strong>${fontFamilies[family].<strong>font</strong>}<strong>&#39;, </strong>${fontFamilies[family].<strong>fallback</strong>}<strong>, sans-serif` </strong>: <strong>&#39;inherit&#39;</strong>;<br>};</pre><p>And, add some custom breakpoints in breakpoint.ts</p><pre>// src/theme/shared/breakpoint.ts<br><strong>export const <em>ScreenSizes</em></strong>: {[<strong>index</strong>: <strong>string</strong>]: <strong>number </strong>} = {<br>    <strong>small</strong>: 740,<br>    <strong>medium</strong>: 1024,<br>    <strong>large</strong>: 1440,<br>};<br><br><strong>export default </strong>(size: <strong>string</strong>): <strong>string </strong>=&gt; {<br>    <strong>return </strong>size ? <strong>`(min-width: </strong>${<strong><em>ScreenSizes</em></strong>[size]}<strong>px)` </strong>: <strong>&#39;inherit&#39;</strong>;<br>};</pre><p>We need to export our project themes:</p><pre>// // src/theme/project1/theme.ts</pre><pre><strong>import </strong><em>color </em><strong>from &#39;./color&#39;</strong>;<br><strong>import </strong><em>fontSize </em><strong>from &#39;./fontSize&#39;</strong>;<br><strong>import </strong><em>fontFamily </em><strong>from &#39;../shared/fontFamily&#39;</strong>;<br><strong>import </strong><em>breakpoint </em><strong>from &#39;../shared/breakpoint&#39;</strong>;<br><br><br><strong>export default </strong>{<br>  <em>color</em>,<br>  <em>fontSize</em>,<br>  <em>fontFamily</em>,<br>  <em>breakpoint<br></em>};</pre><p>We can specify and customise which themes we want for each project.</p><p>Next, we export our ThemeProvider.ts</p><pre>// src/theme/ThemeProvider.ts</pre><pre><strong>import </strong>{ <strong><em>ThemeProvider </em></strong>} <strong>from &#39;styled-components&#39;</strong>;<br><strong>export default <em>ThemeProvider</em></strong>;</pre><h4>Styleguide</h4><p>We also need to define a layout for our Styleguide. So, we create a ThemeWrapper component to serve as a top level wrapper component and customises the layout.</p><pre>// Create styleguide folder<br>$ mkdir src/styleguide</pre><pre>$ touch src/styleguide/ThemeWrapper.tsx</pre><p>And we enter the following:</p><pre><strong>// </strong>src/styleguide/ThemeWrapper.tsx</pre><pre><strong>import </strong>* <strong>as </strong>React <strong>from &#39;react&#39;</strong>;<br><strong>import </strong>{ <strong><em>ThemeProvider </em></strong>} <strong>from &#39;styled-components&#39;</strong>;<br><strong>import </strong>theme <strong>from &#39;../theme/project1/theme&#39;</strong>;<br><br><strong>const </strong><em>ThemeWrapper</em>: React.FC = ({ children}) =&gt; {<br>  <strong>return </strong>&lt;<strong>ThemeProvider theme=</strong>{theme}&gt;{children}&lt;/<strong>ThemeProvider</strong>&gt;;<br>};<br><br><strong>export default </strong><em>ThemeWrapper</em>;</pre><p>The ThemeProvider component accepts a theme prop, which it passes it down to all child components.</p><p>Next, we modify our <a href="https://gist.github.com/s-barrah/2c3afce24211e5a1d835979ce50a33ec">styleguide.config.js</a> and update the styleguideComponents prop to our new ThemeWrapper component, enabling a customised layout:</p><pre><em>//styleguide.config.js<br></em>styleguideComponents: {<br>  Wrapper: path.<em>join</em>(__dirname, &#39;src/styleguide/ThemeWrapper&#39;)<br>}</pre><p>Next we modify the script commands in our package.json file</p><pre><strong>&quot;scripts&quot;</strong>: {<br>  <strong>&quot;styleguide&quot;</strong>: <strong>&quot;styleguidist server&quot;</strong>,<br>  <strong>&quot;styleguide:build&quot;</strong>: <strong>&quot;styleguidist build&quot;</strong>,<br>  ....<strong><br></strong>},</pre><p>Running yarn run styleguide will start the style guide dev server, while yarn run styleguide:build builds a production-ready HTML version.</p><h4>Components</h4><p>In structuring the components, I have adopted the <a href="https://bradfrost.com/blog/post/atomic-web-design/">Atomic Design system</a> proposed by Brad Frost.</p><pre>// Create the components folder<br>$ mkdir src/components</pre><pre>// Create the Atoms folder<br>$ mkdir src/components/Atoms</pre><pre>// Create our Atomic components<br>$ mkdir src/components/Atoms/Text<br>$ touch src/components/Atoms/Text/Text.tsx</pre><pre>$ mkdir src/components/Atoms/RichText<br>$ touch src/components/Atoms/RichText/RichText.tsx</pre><pre>// Create the Molecules folder<br>$ mkdir src/components/Molecules</pre><pre>// Create our Molecule component<br>$ mkdir src/components/Molecules/Section<br>$ touch src/components/Molecules/Section/Section.tsx</pre><p>We modify Text.tsx atomic component as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/021c2f4c0b535a286290dac5360a0990/href">https://medium.com/media/021c2f4c0b535a286290dac5360a0990/href</a></iframe><p>Next, we modify RichText.tsxatomic component</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/415fb4163c859f9f25d2c06999e9d14f/href">https://medium.com/media/415fb4163c859f9f25d2c06999e9d14f/href</a></iframe><p>Next, we create our Section.tsx molecule component. Molecules are a combination of two or more Atomic components</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d21940ab31cbcb5a0b2e35580160e12e/href">https://medium.com/media/d21940ab31cbcb5a0b2e35580160e12e/href</a></iframe><p><a href="https://react-styleguidist.js.org/">Styleguidist</a> handles documentation using the JSDoc comment blocks in the components and also picks up props from each propTypes declaration and displays them in a table.</p><p>To view the styleguide library locally, we run yarn run styleguide to start styleguide dev server and we can view it at <a href="http://localhost:6060/">http://localhost:6060/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dFYIetEQiwAQOFIw-xeXNw.png" /><figcaption>React Component Library styleguide</figcaption></figure><p>We can see our Introduction but not our new components.</p><p>This is because Styleguidist will look for a README file such as a Readme.md or Text.md or RichText.md within the respective components folder in order to display them. You can read more about <a href="https://react-styleguidist.js.org/docs/documenting/">Styleguidist documentation</a>.</p><p>We need to create README files for our new components:</p><pre>// Create Text component Readme file<br>$ touch src/components/Atoms/Text/Text.md</pre><pre>// Create RichText component Readme file<br>$ touch src/components/Atoms/RichText/RichText.md</pre><p>Then add a few examples such as the following to the Text.md:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f058bfeb88f1c4664c02d1fa74eac1d/href">https://medium.com/media/1f058bfeb88f1c4664c02d1fa74eac1d/href</a></iframe><p>And alsoRichText.md</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e77c8dfa178cd12af5b97631ccb1acbf/href">https://medium.com/media/e77c8dfa178cd12af5b97631ccb1acbf/href</a></iframe><p>After a hot reload, Styleguidist will generate the components from the markup:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*73PvL9UWz76Bsgu7Kwwq0g.png" /><figcaption>RichText components</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qkCnoiMvWrSumMAAv0rGag.png" /><figcaption>Text components</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PJ5ItaYpzs92-h1CQmT3yw.png" /><figcaption>Section.tsx</figcaption></figure><h4>Testing</h4><p><a href="https://react-styleguidist.js.org/">Styleguidist</a> uses <a href="https://blog.sapegin.me/all/react-jest/">Jest with Enzyme</a> for testing.</p><p>To add tests to our library, we need to install some dependencies:</p><pre>$ yarn add jest-css-modules-transform<br>// Install jest and dependencies<br>$ yarn add -D jest jest-styled-components babel-jest</pre><pre>// Allows us to render React components outside the DOM<br>$ yarn add react-test-renderer @types/react-test-renderer</pre><p>Next, we need to add some tests for our components. First, we create a higher order shallow wrapper component:</p><pre>// Create hoc folder<br>$ mkdir src/hoc</pre><pre>// Create renderer component<br>$ touch src/hoc/shallowWithTheme.tsx</pre><p>Update the shallowWithTheme component as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3bb60dbccba2b88d585e9e0ee58d5a6e/href">https://medium.com/media/3bb60dbccba2b88d585e9e0ee58d5a6e/href</a></iframe><p>Next, we create our test files</p><pre>// Create test files at component levels<br>$ touch src/components/Atoms/Text/Text.test.tsx</pre><pre>$ touch src/components/Atoms/RichText/RichText.test.tsx</pre><pre>$ touch src/components/Molecules/Section/Section.test.tsx</pre><p>And we enter the following to theText.test.tsx , RichText.test.tsx and Section.test.tsx files:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebf58e31a861325d0792d63f82435567/href">https://medium.com/media/ebf58e31a861325d0792d63f82435567/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58b1c2e3f291947b0b83c54f0cae3621/href">https://medium.com/media/58b1c2e3f291947b0b83c54f0cae3621/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb0641cfdb725160962b2d4479de9cac/href">https://medium.com/media/fb0641cfdb725160962b2d4479de9cac/href</a></iframe><p>We need to update our package.json with our test commands:</p><pre><strong>&quot;scripts&quot;</strong>: {<br>  ...<br>  <strong>&quot;test&quot;</strong>: <strong>&quot;yarn run jest --collectCoverage&quot;</strong>,<br>  <strong>&quot;test:watch&quot;</strong>: <strong>&quot;yarn run jest --watch&quot;</strong>,<br>  <strong>&quot;test:update&quot;</strong>: <strong>&quot;yarn run jest -u&quot;</strong>,<br>  <strong>&quot;test:no-warnings&quot;</strong>: <strong>&quot;yarn run jest --watch --silent&quot;</strong>,<br>  <strong>...<br></strong>},</pre><p>Running yarn run testwill run the full suite of tests; yarn run test:watch watches test files for changes, yarn run test:update updates our tests and yarn run test:no-warnings runs tests in silent mode.</p><h4>Linting</h4><p>It is important to have a clear and consistent coding convention. <a href="https://eslint.org/">ESLint</a> makes it possible to identify, report and fix any inconsistencies and bugs in our code during development.</p><p>To add linting to our project, we need to install a few dependencies:</p><pre>// Install ESLint and plugins<br>$ yarn add -D eslint eslint-plugin-react eslint-plugin-react-hooks</pre><pre>// Lint styleguide support<br>$ yarn add -D eslint-config-airbnb eslint-plugin-import@^2.21.2 eslint-plugin-jsx-a11y@^6.3.0</pre><pre>// Typescript support<br>$ yarn add -D <a href="http://twitter.com/typescript">@typescript</a>-eslint/eslint-plugin <a href="http://twitter.com/typescript">@typescript</a>-eslint/parser</pre><pre>// Install Prettier and plugins<br>$ yarn add -D prettier eslint-plugin-prettier eslint-config-prettier</pre><pre>// Installs husky and lint<br>$ yarn add -D husky lint-staged</pre><p>We also installed <a href="https://prettier.io/">Prettier</a> which forces code formatting; <a href="https://github.com/okonet/lint-staged#readme">Lint-staged</a> which ensures that linting is run on files before they are committed; <a href="https://github.com/typicode/husky#readme">Husky</a> which helps makes git hooks easier.</p><p>We then need to set up a configuration file for ESLint:</p><pre>$ npx eslint --init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BT8CpE4Eccz6xEejiGcGlw.png" /><figcaption>ESLint init</figcaption></figure><p>This generates a configuration file .eslintrc.js. I have added some modifications with our plugins and rules:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b3221b0d9746a0b5bb1abbbe7a57ee9/href">https://medium.com/media/3b3221b0d9746a0b5bb1abbbe7a57ee9/href</a></iframe><p>Next, we need to create an .eslintignore file which tells ESLint which directories or files to ignore and add the following:</p><pre>node_modules<br>dist<br>tests<br>coverage<br>styleguide.config.js<br><br>src/**/*.test.tsx<br>src/**/*.md<br>src/serviceWorker.ts</pre><p>Next, we need to also update our package.jsonfor by adding our lint command to the script field and adding new fields for husky and lint-staged :</p><pre>&quot;scripts&quot;: {<br>  ...<br>  &quot;lint&quot;: &quot;eslint &#39;src/**/*.{js,ts,tsx}&#39; --quiet --fix&quot;<br>},<br>&quot;husky&quot;: {<br>  &quot;hooks&quot;: {<br>    &quot;pre-commit&quot;: &quot;lint-staged&quot;<br>  }<br>},<br>&quot;lint-staged&quot;: {<br>  &quot;src/**/*.{js,jsx,ts,tsx,json,css,scss}&quot;: [<br>    &quot;prettier --single-quote --write&quot;,<br>    &quot;eslint --fix&quot;<br>  ]<br>}</pre><p>We can run yarn run lintto lint test our files. Also, every changed file to will also be lint tested before it is committed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*pmlCNKzPk1O8bJWvM5pVhA.png" /><figcaption>Husky — pre-commit</figcaption></figure><h3>Production</h3><p>In order to use our library as npm module, we need to export our themes and components and compile our typescript files into plain Javascript before we can publish as a module and import into our projects.</p><p>First, we create our export file src/index.ts and add the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c3923899a592e29f1996efe587af5bc/href">https://medium.com/media/8c3923899a592e29f1996efe587af5bc/href</a></iframe><p>Next, we need to install the following modules :</p><pre>// TypeScript execution for node<br>$ yarn add -D ts-node</pre><pre>// Typescript loader for webpack<br>$ yarn add -D ts-loader</pre><p>And update our script field inpackage.json with our postinstall and build command.</p><pre><strong>&quot;scripts&quot;</strong>: {<br>  ......<br>  <strong>&quot;postinstall&quot;</strong>: <strong>&quot;yarn run build&quot;</strong>,<br>  <strong>&quot;build&quot;</strong>: <strong>&quot;NODE_ENV=production tsc&quot;</strong>,<strong><br>  ......</strong></pre><pre>},</pre><p>This means that everytime we run yarn install, the build command will be triggered, creating a new build of our project. Next, we also need to modify our Typescript configuration file tsconfig.json to specific our source foldersrc and compiled destination dist folder and also which directories or files to exclude from typechecks.</p><pre>{<br>  <strong>&quot;compilerOptions&quot;</strong>: {<br>    <strong>&quot;target&quot;</strong>: <strong>&quot;es5&quot;</strong>,<br>    <strong>&quot;module&quot;</strong>: <strong>&quot;commonjs&quot;</strong>,<br>    <strong>&quot;lib&quot;</strong>: [<br>      <strong>&quot;dom&quot;</strong>,<br>      <strong>&quot;dom.iterable&quot;</strong>,<br>      <strong>&quot;esnext&quot;<br>    </strong>],<br>    <strong>&quot;allowJs&quot;</strong>: <strong>true</strong>,<br>    <strong>&quot;declaration&quot;</strong>: <strong>true</strong>,<br>    <strong>&quot;sourceMap&quot;</strong>: <strong>true</strong>,<br>    <strong>&quot;skipLibCheck&quot;</strong>: <strong>true</strong>,<br>    <strong>&quot;esModuleInterop&quot;</strong>: <strong>true</strong>,<br>    <em>/* Redirect output structure to the directory. */<br>    </em><strong>&quot;outDir&quot;</strong>: <strong>&quot;./dist&quot;</strong>, <br>    <em>/* Specify the root directory of input files. */</em>                      <em><br>    </em><strong>&quot;rootDir&quot;</strong>: <strong>&quot;./src&quot;</strong>,<br>    <em>/* Do not emit comments to output. */<br>    </em><strong>&quot;removeComments&quot;</strong>: <strong>true</strong>,<em><br>    </em><strong>&quot;allowSyntheticDefaultImports&quot;</strong>: <strong>true</strong>,<br>    <strong>&quot;strict&quot;</strong>: <strong>true</strong>,<br>    <strong>&quot;forceConsistentCasingInFileNames&quot;</strong>: <strong>true</strong>,<br>    <strong>&quot;moduleResolution&quot;</strong>: <strong>&quot;node&quot;</strong>,<br>    <strong>&quot;resolveJsonModule&quot;</strong>: <strong>true</strong>,<br>    <strong>&quot;isolatedModules&quot;</strong>: <strong>true</strong>,<br>    <strong>&quot;noImplicitAny&quot;</strong>: <strong>false</strong>,<br>    <em>// &quot;noEmit&quot;: true,<br>    </em><strong>&quot;jsx&quot;</strong>: <strong>&quot;react&quot;<br>  </strong>},<br>  <strong>&quot;include&quot;</strong>: [<br>    <strong>&quot;src&quot;<br>  </strong>],<br>  <strong>&quot;exclude&quot;</strong>: [<br>    <strong>&quot;node_modules&quot;</strong>,<br>    <strong>&quot;src/__tests__&quot;</strong>,<br>    <strong>&quot;**/*.test.tsx&quot;</strong>,<br>    <strong>&quot;**/*.test.ts&quot;</strong>,<br>    <strong>&quot;dist&quot;<br>  </strong>]<br>}</pre><p>Next, we run yarn run build to generate compiled javascript files in the destination dist folder.</p><p>We also need to run yarn run styleguide:build to generate a production-build of a HTML-static library in the styleguide folder. Your project structure should now look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*3Vf0GBbl9x6ER0xBXOeLBQ.png" /><figcaption>React Component Library project structure</figcaption></figure><p>Next we updatepackage.json by adding new fields to point to the compiled source as below:</p><pre><strong>&quot;main&quot;</strong>: <strong>&quot;dist/index.js&quot;</strong>,<br><strong>&quot;module&quot;</strong>: <strong>&quot;dist/index.js&quot;</strong>,<br><strong>&quot;types&quot;</strong>: <strong>&quot;dist/index.d.ts&quot;</strong></pre><h4>Publishing</h4><p>Next, before we can publish our library, we need to also create a .npmignore file, which tells <a href="https://www.npmjs.com/">NPM</a> which directories or file to ignore. We then add the following:</p><pre>src<br>node_modules<br>tests<br>.idea<br>coverage</pre><p>And we can run npm publish , which publishes the library on <a href="https://www.npmjs.com/">NPM</a>. You need to have an account on <a href="https://www.npmjs.com/">NPM</a> before you can publish. If you don’t have an account, you can create one and it is free. Also, the name of your library / module must be unique on <a href="https://www.npmjs.com/">NPM</a>. In this case, I named the library rcl-demoon <a href="https://www.npmjs.com/">NPM</a>.</p><h4>Continuous Integration and Development, Versioning and Publishing</h4><p>Next, we automate our builds, tests and deployments using <a href="https://github.com/">Github</a> and <a href="https://circleci.com/">CircleCI</a> . You can read more about how to <a href="https://circleci.com/docs/2.0/getting-started/#setting-up-circleci">set up CircleCI</a> and <a href="https://circleci.com/blog/what-is-continuous-integration/">what Continuous Integration and Development means</a>. You can choose whichever CI/CD platforms you prefer.</p><p>First, we push our remote repository on <a href="https://github.com/">Github</a> and then look for and set up the project on the <a href="https://circleci.com/">CircleCI Dashboard</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bMXwF23YBHMrIbwp9Unjlg.png" /><figcaption>CircleCI Dashboard</figcaption></figure><p>I have opted to manually add the configuration file .circleci/config.yml to my project:</p><pre>// Create CircleCI configuration file at the root of project<br>$ mkdir .circleci<br>$ touch .circleci/config.yml</pre><p>We will also be using <a href="https://github.com/semantic-release/semantic-release">Semantic Release</a> to automate version management and publishing of our package to <a href="https://www.npmjs.com/">NPM</a>. To do that, we need to install the module and it’s CLI:</p><pre>// Install Semantic release <br>$ yarn add semantic-release-cli<br>$ yarn add -D semantic-release</pre><p>By default, <a href="https://github.com/semantic-release/semantic-release">Semantic Release</a> expects commits to be in the conventional GIT commit format likefeat: add feature X or fix: fix bug Y that perform minor and patch version bumps respectively.</p><p>The <a href="https://circleci.com/">CircleCI</a> configuration is triggered on every push to the remote repository on <a href="https://github.com/">GitHub</a> and this also triggers a release as a part of the workflow:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0142dfc58081c869715bf717cfd37be3/href">https://medium.com/media/0142dfc58081c869715bf717cfd37be3/href</a></iframe><p>Next, we need to setup our authentication tokensGH_TOKEN/ GITHUB_TOKEN and NPM_TOKEN environmental variables in the <a href="https://circleci.com/">CircleCI</a> project setup. Read <a href="https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token">Creating a personal access token</a> on how to create an access token on <a href="https://github.com/">GitHub</a>. Also, you need to have an account on <a href="https://www.npmjs.com/">NPM</a> to create an access token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uyr5lbxQ0UqA2qzSOJNGLQ.png" /><figcaption>CircleCI Project settings</figcaption></figure><p>After renaming the library to <a href="https://www.npmjs.com/package/rcl-demo">rcl-demo</a> , we trigger another deployment</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_94YjwgLXKC6jZg_YHfgdw.png" /><figcaption>CircleCI Pipeline</figcaption></figure><p>We also need to update the README.md file as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2fa6be232b7b449a142d5109beb6f67/href">https://medium.com/media/a2fa6be232b7b449a142d5109beb6f67/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wFkzM_JmKyzBtSTt3E10rg.png" /><figcaption><a href="https://www.npmjs.com/package/rcl-demo">NPM — React Component Library</a></figcaption></figure><h4>Usage</h4><p>To use our library in any project, we simply need to install by running yarn add rcl-demo or npm install rcl-demo .</p><p>Next we need to import the. ThemeProvider and theme as a high order component wrapper in our application:</p><pre><strong>import </strong>{ ThemeProvider, <strong><em>theme </em></strong>} <strong>from &#39;rcl-demo&#39;</strong>;</pre><pre>&lt;<strong>ThemeProvider theme=</strong>{<strong><em>theme</em></strong>}&gt;<br>  &lt;<strong>div className=&quot;app&quot;</strong>&gt;<br>    ...<br>  &lt;/<strong>div</strong>&gt;<br>&lt;/<strong>ThemeProvider</strong>&gt;</pre><p>And we can import any component and use anywhere in the project</p><pre><strong>import </strong>{ Text<strong><em> </em></strong>} <strong>from &#39;rcl-demo&#39;</strong>;</pre><pre><em>&lt;Text tag=&quot;p&quot; size=&quot;xl&quot; family=&quot;Anton&quot;&gt;<br>  My paragraph xl and font Anton<br>&lt;/Text&gt;</em></pre><h4>Preview</h4><p>To deploy the static pages on <a href="https://app.netlify.com/">Netlify</a>, you need login / signup and import the project from Github. Next, we need to update the build command and publish directory</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZfFDld5sHw79Y6mxMXkd4w.png" /><figcaption>Netlify — Build settings</figcaption></figure><p>Clicking on theDeploy site button should trigger the deployment:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8mUBSdnQeaWJBBSnIGfehg.png" /></figure><p>With <a href="https://app.netlify.com/">Netlify</a>, you can also customise the settings for the static site and domain.</p><p>As soon as deployment is finished, we can preview our static library:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GNut1ieh39bJIAyUZan_dA.png" /><figcaption>React Component Library — Netlify</figcaption></figure><h3>Conclusion</h3><p>Having a component library is definitely the way to go if you want to have sharable and reusable components and prevent code duplication across different projects. It also means we can also fix bugs or add new features to our components with less effort.</p><p>There are various frameworks that also help create your own system or provide you with reusable components right out-of-the-box like <a href="https://material-ui.com/">Material UI</a>, <a href="https://react-bootstrap.github.io/">React Bootstrap</a>, <a href="https://developer.microsoft.com/en-us/fluentui#/">Fluent UI</a> and <a href="https://react.semantic-ui.com/">Semantic UI</a>.</p><p>I have included the <a href="https://github.com/s-barrah/react-component-library">Github repository</a> with the current implementation in this article. Feel free to clone, fork or star it if it helps you.</p><p><a href="https://github.com/s-barrah/react-component-library">s-barrah/react-component-library</a></p><h3>Further Reading</h3><ul><li><a href="https://www.pluralsight.com/guides/typescript-react-getting-started">Getting started with React and Typescript</a></li><li><a href="https://react-styleguidist.js.org/docs/cookbook">React-Styleguidist Cookbook</a></li><li><a href="https://bradfrost.com/blog/post/atomic-web-design/">Atomic Web Design</a></li><li><a href="https://circleci.com/blog/what-is-continuous-integration/">What is Continuous Integration?</a></li><li><a href="https://circleci.com/docs/2.0/getting-started/#setting-up-circleci">Getting started with CircleCI</a></li><li><a href="https://blog.greenkeeper.io/introduction-to-semantic-release-33f73b117c8">Introduction to Semantic Release</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67e33f5e712a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/creating-a-react-component-library-with-typescript-using-styleguidist-67e33f5e712a">Creating a React Component Library With Typescript Using Styleguidist</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Serverless Computing — is it the Future?]]></title>
            <link>https://medium.com/the-kickstarter/serverless-computing-is-it-the-future-c90b9d85006f?source=rss-9983385adb9e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c90b9d85006f</guid>
            <category><![CDATA[observability]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[serverless-computing]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Sidney Barrah]]></dc:creator>
            <pubDate>Mon, 25 May 2020 23:42:21 GMT</pubDate>
            <atom:updated>2021-02-18T10:20:09.430Z</atom:updated>
            <content:encoded><![CDATA[<h3>Serverless — the Ghost of the Future?</h3><h4>My takeaways from the maiden Serverless Computing conference in London</h4><p>I know this article is a bit late. It was written a long time ago but remained unpublished until now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t1oTTHszusQnBj42Zdk63Q.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@tvick?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Taylor Vick</a> on <a href="https://unsplash.com/s/photos/servers?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p><a href="https://www.cloudflare.com/learning/serverless/what-is-serverless/">Serverless computing</a> was borne out of the shift from enterprise application architectures to containers and micro-services. By abstracting away most operational concerns, serverless computing provides users with the opportunity to no longer worry about managing servers, scalability, availability, over/under provisioning of resources and all other infrastructural issues. However, this still means that users are responsible for deploying and managing the hosting environment configurations.</p><p>I was introduced to the serverless world in 2018 after joining an amazing engineering team in one of the UK’s well-known charities, <a href="https://www.comicrelief.com/">Comic Relief</a> . At the time, I was still just getting acquainted with micro-service architecture after years of developing monoliths. It was all new, shiny and exciting! As a developer, I saw the appeal, as it meant not having to worry about servers and not paying when my code was not running.</p><figure><img alt="Serverless computing" src="https://cdn-images-1.medium.com/max/648/1*9fwVBDfH0dILKHXJKGP8tg.jpeg" /><figcaption>Serverless Computing London</figcaption></figure><p>The maiden edition of the <a href="https://2018.serverlesscomputing.london/">Serverless Computing London</a> on 12–14 November, 2018 at 30 Euston Square saw a number of keynote speakers discuss serverless computing in detail. Everyone, from enthusiasts to engineers and vendors, was present.</p><h3>Takeaways</h3><p>I put together my key takeaways from some of the speakers I was fortunate enough to hear. These are my thoughts/impressions and in no way a reflection of the speakers.</p><p>My main takeaways from my two days at the conference are:</p><ul><li><a href="https://thenewstack.io/category/serverless/"><strong>New</strong></a> — Serverless is still in the growth stage as most businesses explore how it could help them achieve their overall goals.</li><li><a href="https://read.acloud.guru/testing-and-the-serverless-approach-495cef7495ea"><strong>Testing, testing and more testing</strong></a><strong> </strong>—<strong> </strong>Especially end-to-end feature testing and testing in production is key. You need to anticipate every action of the end users.</li><li><a href="https://en.wikipedia.org/wiki/Observability"><strong>Observability</strong></a> — Understanding exactly what happens every time a request passes through your code. Using various logging and tracing tools, it makes life easier to debug your systems.</li></ul><h4>The Talks</h4><p>I attended the talks that were of personal interests to me at the time and have summarised some of my takeaways below:</p><h4><strong>Day 1</strong></h4><p><strong>Keynote: </strong><a href="https://2018.serverlesscomputing.london/sessions/three-ghosts-serverless-look-past-present-yet-come/">Three Ghosts of Serverless — A look into the Past, Present, and Yet to Come</a></p><p><strong>Speaker:</strong> <a href="https://twitter.com/chadarimura">Chad Arimura</a>, <a href="https://www.oracle.com/uk/index.html">Oracle</a></p><p>In this keynote, Chad took us on a visual journey of how much technology has evolved over time using the stories of the Three Ghosts of Serverless — The Past Ghost, The Present Ghost and the Future/Yet to come Ghost.</p><p><strong>Takeaways:</strong></p><ul><li><a href="https://mediatemple.net/blog/cloud-hosting/what-is-serverless/">Serverless computing is the future and we can only expect much more</a>.</li><li>The thing that is inevitable is change, no matter what or how we feel about it.</li><li>Serverless provides developers with boundless opportunities and possibly the first billion dollar app developed by a single developer!</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lpIvSNJz7EA7as2TfqGW_g.jpeg" /><figcaption>Chad — Ghosts of Serverless — Serverless Computing London 2018</figcaption></figure><p><strong>Event: </strong><a href="https://2018.serverlesscomputing.london/sessions/graphql-and-serverless/">GraphQL and Serverless</a></p><p><strong>Speaker:</strong> <a href="https://twitter.com/IamStan">Ant Stanley</a></p><p><strong>Takeaways:</strong></p><ul><li><a href="https://graphql.org/">GraphQL</a> is exciting and offers a lot of advantages especially in a serverless environment. However, it is important to understand the trade-offs before opting to replace REST with <a href="https://graphql.org/">GraphQL</a>.</li><li><a href="https://graphql.org/">GraphQL</a> makes sense in applications that require complex queries but not so much for those that donʼt.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*dLM6WbrCvU1XX4xKNTKUgg.png" /><figcaption>Angry Birds</figcaption></figure><p><strong>Event:</strong> <a href="https://2018.serverlesscomputing.london/sessions/service-migration/">Migrating an Existing Service To Serverless</a></p><p><strong>Speaker:</strong> <a href="https://twitter.com/mavi888uy">Marcia Villalba</a>, <a href="https://www.rovio.com/">Rovio</a></p><p>In this talk, Marcia shared how her team at <a href="https://www.rovio.com/">Rovio</a> (creators of Angry Birds), with no experience in serverless architecture, migrated an existing video-on-demand service to use serverless. The focus was mainly on the team’s process and the learnings.</p><p><strong>Takeaways:</strong></p><ul><li>She emphasised the importance in training for teams; at the start of the project, none of the team members had any experience with serverless.</li><li>The team was also able to cut down costs for the business and improve on their automated testing and CI/CD processes.</li><li>She also emphasised the importance of system monitoring with dashboards and logging.</li></ul><p><strong>Event:</strong> <a href="https://2018.serverlesscomputing.london/sessions/serverless-design-patterns/">Serverless design patterns</a></p><p><strong>Speaker:</strong> <a href="https://twitter.com/theburningmonk">Yan Cui</a>, <a href="https://www.dazn.com/">Dazn</a></p><p>The advent of serverless means that new architectural design patterns have also emerged and must be considered when developing serverless apps. Yan discussed knowing how to pick the right event source based on the trade-offs that you want.</p><p><strong>Takeaways:</strong></p><ul><li>Going serverless means that the time from idea to product is shorter, with less operational responsibility.</li><li>Design patterns do not guarantee success, as it is more important to understand the problems and constraints over following a pattern.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PlfW1caThtyajSkAPL3Q5w.jpeg" /><figcaption>Yan Cui — Serverless Design Patterns — Serverless Computing London 2018</figcaption></figure><p><strong>Event:</strong> <a href="https://2018.serverlesscomputing.london/sessions/brave-new-world-rethinking-testing-serverless/">A Brave New World: Rethinking Testing For Serverless</a></p><p><strong>Speaker: </strong><a href="https://twitter.com/ntaggart">Nate Taggart</a>, <a href="https://www.stackery.io/">Stackery</a></p><p><strong>Takeaways:</strong></p><ul><li>Serverless has changed testing approaches, making it easier and sometimes harder.</li><li>Serverless means testing strategies have to be adapted.</li></ul><h4>Day 2</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ESQfZz-oHSpEeQynAHxIQ.jpeg" /><figcaption>Charity Majors — Observability — Serverless Computing London 2018</figcaption></figure><p><strong>Keynote:</strong> <a href="https://2018.serverlesscomputing.london/sessions/keynote-ii/">Observability (and Responsibility) for Serverless Systems</a></p><p><strong>Speaker:</strong> <a href="https://twitter.com/mipsytipsy">Charity Majors</a>, <a href="http://honeycomb.io/">Honeycomb</a></p><p>She talks about how going serverless does not mean that we stop thinking about debugging our systems but means that it is harder because we are dealing with a black box. This emphasises the importance of observability.</p><p><strong>Takeaways:</strong></p><ul><li>Observability is everything!</li><li>Monitoring is not the same as observability and should not be confused as such.</li><li>We are not getting better at building large softwares fast enough when compared to the complexities.</li><li>Developers should take responsibility for the deployment of their code and should also support their code in production.</li><li>It is much easier to build complex systems than to understand them.</li><li>It is crucial for us to understand what is going on within your systems.</li><li>Always test before production, and testing in production is important.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*Ou2BqsCoV2SspSFzqv1_gg.jpeg" /><figcaption>Red Nose Day — Comic Relief</figcaption></figure><p><strong>Event:</strong> <a href="https://2018.serverlesscomputing.london/sessions/going-serverless-comic-relief-deep-dive-donations-platform/">Going Serverless at Comic Relief: A deep dive into our donations platform.</a></p><p><strong>Speaker:</strong> <a href="https://twitter.com/pvhee">Peter Vanhee</a>, <a href="https://www.comicrelief.com/">Comic Relief</a></p><p>Peter talks about how <a href="https://www.comicrelief.com/">Comic Relief</a>, a well-known UK charity, which runs one of the largest fundraising events was able to architect a donation platform able to handle hundreds of per-second donations, all done serverlessly. I was lucky to be part of the Comic Relief team at the time. Peter went on a deep dive into the overall architecture of the serverless donations platform at Comic Relief, including our implementation of CI/CD, chaos testing, and observability.</p><p><strong>Takeaways:</strong></p><ul><li>The importance of end-to-end test-driven development.</li><li>How we used chaos engineering to test various parts of the donation platform.</li><li>How we ran load testing in our serverless applications.</li><li>The importance of having a highly resilient system capable of failing gracefully.</li></ul><p><strong>Event: </strong><a href="https://2018.serverlesscomputing.london/sessions/serverless-allowed-us-build-point-solution-meet-unique-requirements-single-broadcast-tv-client/">How we used Serverless to meet the unique requirements of a major broadcaster</a></p><p><strong>Speaker: </strong><a href="https://www.linkedin.com/in/paulmarkham1/">Paul Markham</a></p><p>Paul spoke about how a major media company solved a complex technical problem by leveraging the advantages of serverless computing. They were able to handle large video files and deliver media content on time to their clients. He talked about the lessons learnt and things they would do differently if they had to do it again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jlPisTpM6ED8_zcIe9O4qg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@martinshreder?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Martin Shreder</a> on <a href="https://unsplash.com/s/photos/technology?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>Conclusion</h3><p>Serverless technology has come a long way since 2018 and I have been lucky to attend a few more serverless events since then. Serverless technology provides simplicity and economic advantages, which is why it has continued to gain popularity. This has been spurred by the rapid growth in the offerings by the various cloud providers such as <a href="https://aws.amazon.com/">AWS</a>, <a href="https://cloud.google.com/">Google</a>, <a href="https://azure.microsoft.com/">Microsoft</a>, and <a href="https://www.ibm.com/cloud">IBM</a>. There has also been the introduction of more observability tools to provide visibility into systems like never before.</p><p>Serverless computing gives cloud providers the opportunity to control the entire development stack, manage resources and thus, minimise costs, encourage customers to use the various products/services offered in their ecosystem and continue to reduce the amount of effort developers need to create and manage scalable applications.</p><p>As a developer, the abstraction of operational and infrastructural concerns allow me to only worry about my code. However, there are challenges that still exist. One of the drawbacks of serverless has been the lack of tools and frameworks. Thankfully, this is changing gradually as several cloud providers now provide various products/services which address this concern and aids the development process. One of my favourite tools is the <a href="https://www.serverless.com/">serverless framework</a>, as it is open source, provides excellent support and deployment to any cloud provider.</p><p>With the rapid advancement in technology, I see most of the challenges as soon becoming part of the past.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dl0F36mQqB_LNtA_dKd3ug.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@markusspiske?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Markus Spiske</a> on <a href="https://unsplash.com/s/photos/technology?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>Resources</h3><ul><li><a href="https://aws.amazon.com/serverless/">AWS Serverless</a></li><li><a href="https://azure.microsoft.com/en-gb/overview/serverless-computing/">Serverless computing — Microsoft Azure</a></li><li><a href="https://cloud.google.com/serverless">Serverless computing — Google Cloud</a></li><li><a href="https://www.computerworld.com/article/3427298/what-is-serverless-computing-and-which-enterprises-are-adopting-it.html">What is serverless computing and which enterprises are adopting it?- Scott Carey, Computerworld</a></li><li><a href="https://www.twilio.com/docs/glossary/what-is-serverless-architecture">Serverless Architecture — Twilio</a></li><li><a href="https://martinfowler.com/articles/serverless.html">Serverless Architectures</a></li><li><a href="https://dl.acm.org/doi/pdf/10.1145/3368454">The Rise of Serverless Computing</a></li><li><a href="https://thenewstack.io/category/serverless/">Serverless — The New Stack</a></li><li><a href="https://mediatemple.net/blog/cloud-hosting/what-is-serverless/">Serverless: The New World of Software Development — Eddie Jauregui</a></li><li><a href="https://read.acloud.guru/testing-and-the-serverless-approach-495cef7495ea">The serverless approach to testing is different and may actually be easier -Paul Johnston</a></li><li><a href="https://www.serverless.com/blog/serverless-test-framework/">Basic Integration Testing with Serverless Framework</a></li><li><a href="https://www.serverless.com/blog/how-test-serverless-applications/">How to Test Serverless Applications</a></li><li><a href="https://epsagon.com/blog/how-to-test-serverless-apps/">How to Test Serverless Applications — Yan Cui</a></li><li><a href="http://principlesofchaos.org/?lang=ENcontent">Principles of Chaos Engineering</a></li><li><a href="https://medium.com/@copyconstruct/monitoring-and-observability-8417d1952e1c">Monitoring and Observability — Cindy Sridharan</a></li><li><a href="https://epsagon.com/wp-content/uploads/2019/05/Epsagon-Five-Approaches-to-Serverless-Application-Observability.pdf">Five Approaches to Serverless Application Observability- Epsagon</a></li><li><a href="https://hackernoon.com/serverless-observability-part-1-new-challenges-to-old-practices-95de1b94d379">Serverless observability brings new challenges to current practices — Yan Cui</a></li><li><a href="https://orangematter.solarwinds.com/2017/09/14/monitoring-isnt-observability/">Monitoring Isn’t Observability — Baron Schwartz</a></li><li><a href="https://thenewstack.io/monitoring-and-observability-whats-the-difference-and-why-does-it-matter/">Monitoring and Observability — What’s the Difference and Why Does It Matter? — Peter Waterhouse</a></li><li><a href="https://www.serverless.com/blog/best-tools-serverless-observability/">Best tools for serverless observability — Andrea Passwater</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c90b9d85006f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-kickstarter/serverless-computing-is-it-the-future-c90b9d85006f">Serverless Computing — is it the Future?</a> was originally published in <a href="https://medium.com/the-kickstarter">The KickStarter</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>