licenseActions.ts module provides utility functions for managing Cryptlex licenses from payment platform webhook events.
Functions
createLicense
Creates a new license in Cryptlex with the provided configuration.The Cryptlex API client instance
License creation request body containing:
productId(string): The Cryptlex product IDlicenseTemplateId(string, optional): License template to useuserId(string): The user ID to assign the license tometadata(array, optional): Metadata key-value pairssubscriptionInterval(string, optional): Subscription interval (e.g.,"P1M","P1Y", or""for perpetual)subscriptionStartTrigger(string, optional): When subscription should startallowedActivations(number, optional): Number of allowed activations
Returns an object with:
message: “License created successfully.”data: Object containing the createdlicensestatus: 201
getLicensesBySubscriptionId
Retrieves all licenses that have a specific subscription ID stored in their metadata.The Cryptlex API client instance
The subscription ID to search for
The metadata key where subscription ID is stored (e.g.,
"subscription_id", "paddle_subscription_id")Array of license objects matching the subscription ID
- Searches licenses using metadata filters
- Throws error if no licenses found with the given subscription ID
- Throws error if the API request fails
- Stripe:
"subscription_id" - FastSpring:
"subscription_id" - Paddle:
"paddle_subscription_id"
getLicenseTemplate
Retrieves a license template by ID.The Cryptlex API client instance
The ID of the license template to retrieve
The license template object containing policy configuration
- Used to validate or extract configuration from license templates
- Throws descriptive error if template not found
Common Usage Patterns
Creating a Subscription-Based License
Creating a Perpetual License
Renewing Licenses by Subscription ID
Creating Multiple Licenses (Quantity Handling)
Subscription Intervals
Subscription intervals use ISO 8601 duration format:| Interval | Format | Description |
|---|---|---|
| Daily | P1D | 1 day |
| Weekly | P1W | 1 week |
| Monthly | P1M | 1 month |
| Quarterly | P3M | 3 months |
| Yearly | P1Y | 1 year |
| Perpetual | "" | Empty string for one-time/perpetual |