Implementing License.Exposed in TypeScript
This guide will help you implement License.Exposed in a TypeScript project. Before you begin, make sure you have already created an organization and a product. If you haven’t done so yet, see:
Getting Started
To implement License.Exposed in your TypeScript project, follow these steps:
-
Install the License.Exposed SDK
- Use npm or yarn to install the License.Exposed SDK in your project:
or1npm install license-exposed1yarn add license-exposed
- Use npm or yarn to install the License.Exposed SDK in your project:
-
Import the SDK and Wrap Your Main Function
- In your TypeScript file, import the
withLicensefunction from the License.Exposed SDK. This function will wrap your main application logic and provide access to the license information. - Here’s an example of how to set it up:
1import { withLicense, License } from 'license-exposed';23function main(license: License, args: string[]) {This is your main-function where you can implement your application logic. The `license` parameter will contain the license information provided by License.Exposed.4console.log("Hello World", args, license);5}67withLicense(license => main(license, process.argv), {8serverKey: "{{ YOUR SERVER KEY }}",9accessToken: "{{ YOUR ACCESS TOKEN }}"10}); - In your TypeScript file, import the
-
Get your Server Key and Access Token
- You can find your server key and access token in the License.Exposed dashboard under your project settings. These credentials are necessary for authenticating your application with the License.Exposed service.
- Replace
{{ YOUR SERVER KEY }}and{{ YOUR ACCESS TOKEN }}in the code above with your actual server key and access token.
-
Run Your Application for the First Time
- After setting up your main function and wrapping it with
withLicense, you can run your application as usual. The License.Exposed SDK will handle the license validation and provide the license information to your main function. - If all went well, you should see a link and a QR code in the console. You can scan the QR code with your phone to activate the license via a mobile phone, or you can visit the link in your browser to activate it on your computer.
- Once activated, the license will be stored in your apps working directory, and you can use it in subsequent runs of your application without needing to activate it again.
- After setting up your main function and wrapping it with
Using the withLicense function allows you to easily integrate License.Exposed into your TypeScript application. It handles the license validation and provides a simple interface for accessing license information. If you want to change the license validation logic or add custom behavior, you can write your own wrapper function, using the utilities in the license.exposed-SDK package directly.