strapi-plugin-delivery v0.0.1
Strapi plugin strapi-plugin-delivery
General logistics and delivery providers aggregator for Strapi 3.
Configuration
Plugin configuration is stored in the ./config/plugins.js
file of the application.
Here is example of the configuration file
module.exports = ({ env }) => ({
delivery: {
enabled: true,
providers: {
<some-provider>: {...}
},
callback: async (delivery, newStatus) => {....}
}
});
This plugin also runs a cron task to update delivery statuses every hour. For this cron must be enabled in application configuration in file ./config/server.js
.
Example content for this file:
module.exports = () => ({
cron: {
enabled: true,
}
});
Integration
This plugin does not configurate routes for the application. It only provides strapi.plugins['delivery'].services.delivery
service with functions:
function updatePending():void
function getStatus(delivery:Delivery):DeliveryStatus
function getPrice(width:number, heigth:number, depth:number, weigth:number, senderAddress:Address, receiverAddress:Address, deliverer:Deliverer, provider:string):Float
function requestDelivery(width:number, heigth:number, depth:number, weigth:number, senderAddress:Address, receiverAddress:Address, provider:string):Delivery
Besides these callable functions there is option to configure a callback function that will be called any time a status change is recorded from communication with service provider. This callback function is defined in the plugin configuration.
Providers
This plugins uses providers. Each provider needs to have name like strapi-provider-delivery-<name>
and must implement the following interfaces.
The exported default function must accept object that contains configuration options for the provider. This function must return an object that conforms to the following interface:
interface Provider {
name
listDeliverers():Deliverer[]
listPickupLocations(deliverer:Deliverer):Location[]
listDropoffLocations(deliverer:Deliverer):Location[]
getParcelDeliveryEstimate(width:number, heigth:number, depth:number, weigth:number, senderAddress:Address, receiverAddress:Address, deliverer:Deliverer|number):Float|Infinity
requestDelivery(width:number, heigth:number, depth:number, weigth:number, senderAddress:Address, receiverAddress:Address, deliverer:Deliverer|number):ProviderDelivery
getDeliveryStatus(externalId:string):DeliveryStatus
getPricingLink(deliverer:Deliverer):String
}
Types
enum DelivererType {
PARCHEL_MACHINE = 'parcel_machine'
COURIER = 'courier'
}
enum LocationType {
PARCHEL_MACHINE = 'parcel_machine'
OFFICE = 'office'
}
enum DeliveryStatusType {
NEW = 'new'
PENDING = 'pending'
DELIVERED = 'delivered'
FAILED = 'failed'
CANCELLED = 'cancelled'
RETURNED = 'returned'
}
interface Deliverer {
name: string
externalId: string
type: DelivererType,
logo: string
}
interface Location {
name: string
type: LocationType
externalId: string
metadata: json
}
interface Address {
location?: Location
countryCode: string
city: string
street: string
addressLine: string
postalCode: string
}
interface ProviderDelivery {
externalId: string
}
interface Delivery {
status: DeliveryStatusType
externalId: string
senderAddress: Address
receiverAddress: Address
provider: string
}
interface DeliveryStatus {
status: string
}
2 years ago