# Asset Types
Asset types let you define common parameters for some or all of your Assets, including:
- Assets considered as available in terms of time and quantity,
- Transaction process applicable and transitions between Transaction statuses,
- Fees collected by your platform.
When you create your first Asset, a default Asset Type is automatically created and attached to any new Asset. You probably can leave this default Asset Type alone for some time.
If you plan to enable “Purchase” and “Rental”-like use cases on your marketplace, then you’ll likely want to have two Asset Types:
- “Rental” depends on some duration and availability periods,
- while “Purchase” can just depend on stock quantities.
Asset Types help making search more specific and can be useful to customize your UI depending on the type of product or experience your Users are looking for.
# Examples
The following table highlights the flexibility provided by Asset Types.
Creating your own Asset Type is as simple as:
await stelace.assetTypes.create({
name: 'Rental',
timeBased: true,
infiniteStock: false // default value
})
# Custom Asset Type
Let’s create an Asset of type “Rental” with a simple API call:
await stelace.assets.create({
name: 'New Delorean DMC-12',
description: 'Limited edition: 3 cars available for rent.',
assetTypeId: 'typ_T3ZfQps1I3a1gJYz2I3a'
})
When your business requirements evolve, any update to “Rental” Asset Type configuration propagates to related Assets.
await stelace.assetTypes.update('typ_T3ZfQps1I3a1gJYz2I3a', {
infiniteStock: true
})
or
curl -X PATCH https://api.stelace.com/asset-types/typ_T3ZfQps1I3a1gJYz2I3a \
-u seck_test_rylx3ebUg0bNs1HkJKlqNHkI: \
-H "Content-Type: application/json" \
-d '{ "infiniteStock": true }'
# Default Asset Type
Please note that you can also update your default Asset Type once you have created your first Asset. You might want to create your first Asset Type beforehand.
There is only a single default Asset Type at a time, automatically used if you omit assetTypeId
when creating an Asset.
Default Asset Type object has timeBased
property set to true
and infiniteStock
set to false
.
# Transaction process
Asset Type transactionProcess
object property lets you customize transitions of all Transactions created on related Assets, depending on your platform requirements.
You can pick appropriate starting and cancellation statuses with transactionProcess.initStatus
and transactionProcess.cancelStatus
respectively.
Let’s suppose we want all Assets of a given Asset Type to pre-accept Transactions on behalf on their owners for faster user experience:
await stelace.assetTypes.update('typ_T3ZfQps1I3a1gJYz2I3a', {
transactionProcess: {
initStatus: 'accepted',
cancelStatus: 'cancelled',
// transitions from the default transaction process, they can be customized if needed
transitions: [
{ name: 'accept', from: 'draft', to: 'accepted', actors: ['owner'] },
{ name: 'confirm', from: 'draft', to: 'confirmed', actors: ['taker'] },
{ name: 'pay', from: 'draft', to: 'pending-acceptance', actors: ['taker'] },
{ name: 'confirmAndPay', from: 'draft', to: 'pending-acceptance', actors: ['taker'] },
{ name: 'pay', from: 'confirmed', to: 'pending-acceptance', actors: ['taker'] },
{ name: 'accept', from: 'confirmed', to: 'pending-payment', actors: ['owner'] },
{ name: 'pay', from: 'accepted', to: 'validated', actors: ['taker'] },
{ name: 'confirmAndPay', from: 'accepted', to: 'validated', actors: ['taker'] },
{ name: 'confirm', from: 'accepted', to: 'pending-payment', actors: ['taker'] },
{ name: 'accept', from: 'pending-acceptance', to: 'validated', actors: ['owner'] },
{ name: 'pay', from: 'pending-payment', to: 'validated', actors: ['taker'] },
{ name: 'complete', from: 'validated', to: 'completed' },
{ name: 'cancel', from: '*', to: 'cancelled' }
]
}
})
Please refer to Transaction process section to have a look at the default Transaction status transitions.
# Availability
Asset Type unavailableWhen
property is a list of status making related Assets unavailable in Search:
await stelace.assetTypes.update('typ_T3ZfQps1I3a1gJYz2I3a', {
unavailableWhen: ['paid', 'completed']
})
Now, any Transaction status
transition to paid
or completed
blocks availability over new Transaction periods, impacting Search results.