UNPKG

@shipengine/connect-carrier-api

Version:

This is the typescript/javascript definitions for carrier api

131 lines (127 loc) 7.08 kB
import { AccountModals, AccountModalsSchema } from './account-modals'; import { PackageType, PackageTypeSchema } from './package-type'; import { ShippingService, ShippingServiceSchema } from './shipping-service'; import { ShippingOptionDictionary, ShippingOptionDictionarySchema } from './shipping-option'; import { CountryAssociation, CountryAssociationSchema } from './country-association'; import { CarrierAttributeEnum, CarrierAttributeEnumSchema } from './carrier-attributes'; import { LabelFormatsEnum, LabelFormatsEnumSchema } from './label-formats'; import { LabelSizesEnum, LabelSizesEnumSchema } from './label-sizes'; import { ConfirmationDictionary, ConfirmationDictionarySchema } from './confirmation-type'; import Joi from 'joi'; import { NativeRatingConfiguration, NativeRatingConfigurationSchema, } from './native-rating-configuration'; import { fileExists } from './custom-validators/file-exists'; import { Zone, ZoneSchema } from './zone'; import { ApiCodeRegex, ApiCodeValidationMessage } from '@shipengine/connect-runtime'; import { PackageRatingGroup, PackageRatingGroupSchema } from './package-rating-group'; import { AccountConnectionSpecification, AccountConnectionSpecificationSchema, } from './account-connection-specification'; import { NormalizedErrors, NormalizedErrorsConfigurationSchema } from './normalized-errors'; import { TrackingSubscriptionLevel } from './enums'; /** @description Basic structure for each carrier */ export interface Carrier { /** @description Defines UI Modals for connecting and updating settings */ AccountModals: AccountModals; /** @description The list of package types used by this carrier */ PackageTypes?: PackageType[]; /** @description A list of shipping services associated with this branded carrier */ ShippingServices?: ShippingService[]; /** @description This object defines which shipping options should be made available and what those shipping options should be called in the ui */ ShippingOptions?: ShippingOptionDictionary; /** @description A list of supported countries, used to determine which services are visible based on shipstation sellers home country */ DefaultSupportedCountries?: CountryAssociation[]; /** @description This provides a list of supported label sizes by the carrier */ DefaultLabelSizes?: LabelSizesEnum[]; /** @description This provides a list of label formats supported by the carrier */ LabelFormats?: LabelFormatsEnum[]; /** @description This dictionary allows you to specify which supported delivery confirmation types the carrier offers. Setting one to undefined will use the default name in shipstation */ DefaultConfirmationTypes?: ConfirmationDictionary; /** @description Attributes describing the carrier */ CarrierAttributes?: CarrierAttributeEnum[]; /** @description This is the url template for static tracking pages ex: http://www.shipper.com/tracking/{0} */ TrackingUrl?: string; /** @description This is the url to the carriers website */ CarrierUrl?: string; /** @description This is a human readable description of the branded carrier */ Description?: string; /** @description The name of this branded carrier, this is what is seen by the customer */ Name: string; /** @description The identifier for this carrier to be used in API calls. Must be snake cased and unique */ ApiCode?: string; /** @description The id for this branded carrier (this GUID should not be changed after publishing) */ Id: string; /** @description This defines images associated with this branded carrier */ Images: { /** @description This is the full file path to the branded logo */ Logo: string; /** @description This is the full file path to the branded icon */ Icon: string; }; /** @description If this carrier uses Native Rating, details about the connection */ NativeRating?: NativeRatingConfiguration; /** @description This is the file path to the documents template, which is used by Rendering Service. Optional. If it's filled and template file provided, ApiCode must be filled. ApiCode will be used to identify the file in Rendering Service.*/ DocumentTemplate?: string; /** @description List of possible zones used by the carrier. */ Zones?: Zone[]; /** @description List of package rating groups for the carrier */ PackageRatingGroups?: PackageRatingGroup[]; /** @description Specifies account connection information */ AccountConnection?: AccountConnectionSpecification; /** @description This is the file path to the error library file, which connect-runtime uses to unify error returns from modules */ ErrorLibrary?: NormalizedErrors[]; /** @description Defines the subscription level required for a carrier to provide tracking updates. */ TrackingSubscriptionLevel?: TrackingSubscriptionLevel; } export const CarrierSchema = Joi.object({ AccountModals: AccountModalsSchema.required(), PackageTypes: Joi.array().optional().items(PackageTypeSchema).unique('Id'), ShippingServices: Joi.array().optional().items(ShippingServiceSchema).unique('Id'), ShippingOptions: ShippingOptionDictionarySchema.optional(), DefaultSupportedCountries: Joi.array() .optional() .items(CountryAssociationSchema) .unique('FromCountry'), DefaultLabelSizes: Joi.array().optional().items(LabelSizesEnumSchema).unique(), LabelFormats: Joi.array().optional().items(LabelFormatsEnumSchema).unique(), DefaultConfirmationTypes: ConfirmationDictionarySchema.optional(), CarrierAttributes: Joi.array().optional().items(CarrierAttributeEnumSchema).unique(), TrackingUrl: Joi.string() .optional() .pattern( new RegExp( /^((http|https):\/\/)([^\/\s]+)\.([^(.:)\/\s]+)((\/\w+)*\/?)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$/, ), ) .message('Invalid TrackingUrl') .max(200), CarrierUrl: Joi.string().optional().uri().max(100), Description: Joi.string().optional().max(250), Name: Joi.string().required().max(50), ApiCode: Joi.string().optional().pattern(ApiCodeRegex, ApiCodeValidationMessage), Id: Joi.string().uuid().required(), Images: Joi.object({ Icon: Joi.string() .required() .custom(fileExists, 'icon exists') .pattern(new RegExp('^.*.(svg)$')) .message('Images.Icon must be a svg file.'), Logo: Joi.string() .required() .custom(fileExists, 'logo exists') .pattern(new RegExp('^.*.(svg)$')) .message('Images.Logo must be a svg file.'), }).required(), NativeRating: NativeRatingConfigurationSchema.optional(), DocumentTemplate: Joi.string().optional().custom(fileExists, 'template exists'), Zones: Joi.array().optional().items(ZoneSchema).unique('ApiCode'), PackageRatingGroups: Joi.array().optional().items(PackageRatingGroupSchema).unique('Id'), AccountConnection: AccountConnectionSpecificationSchema.optional(), ErrorLibrary: NormalizedErrorsConfigurationSchema.optional(), TrackingSubscriptionLevel: Joi.string() .valid(...Object.values(TrackingSubscriptionLevel)) .optional(), }).with('DocumentTemplate', 'ApiCode');