@shipengine/connect-carrier-api 2.1.18 → 2.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/lib/app/carrier-app-definition.d.ts +12 -2
  2. package/lib/app/carrier-app.js +79 -53
  3. package/lib/app/carrier-app.js.map +1 -1
  4. package/lib/app/constants.d.ts +14 -0
  5. package/lib/app/constants.js +19 -0
  6. package/lib/app/constants.js.map +1 -0
  7. package/lib/app/internal/route.d.ts +1 -0
  8. package/lib/models/authorization.d.ts +4 -0
  9. package/lib/models/authorization.js +7 -0
  10. package/lib/models/authorization.js.map +1 -0
  11. package/lib/models/billing/billing-categories.d.ts +2 -0
  12. package/lib/models/billing/billing-categories.js +4 -1
  13. package/lib/models/billing/billing-categories.js.map +1 -1
  14. package/lib/models/billing/billing-line-item.d.ts +2 -0
  15. package/lib/models/billing/billing-line-item.js +12 -1
  16. package/lib/models/billing/billing-line-item.js.map +1 -1
  17. package/lib/models/currency.d.ts +2 -0
  18. package/lib/models/currency.js +7 -1
  19. package/lib/models/currency.js.map +1 -1
  20. package/lib/models/documents/document-type.d.ts +2 -0
  21. package/lib/models/documents/document-type.js +4 -1
  22. package/lib/models/documents/document-type.js.map +1 -1
  23. package/lib/models/documents/document.d.ts +2 -0
  24. package/lib/models/documents/document.js +10 -1
  25. package/lib/models/documents/document.js.map +1 -1
  26. package/lib/models/identifier.d.ts +2 -0
  27. package/lib/models/identifier.js +7 -1
  28. package/lib/models/identifier.js.map +1 -1
  29. package/lib/models/inbound-content-types.d.ts +7 -0
  30. package/lib/models/inbound-content-types.js +13 -0
  31. package/lib/models/inbound-content-types.js.map +1 -0
  32. package/lib/models/index.d.ts +2 -0
  33. package/lib/models/index.js +2 -0
  34. package/lib/models/index.js.map +1 -1
  35. package/lib/models/labels/document-formats.d.ts +2 -0
  36. package/lib/models/labels/document-formats.js +4 -1
  37. package/lib/models/labels/document-formats.js.map +1 -1
  38. package/lib/models/labels/form-download.d.ts +2 -0
  39. package/lib/models/labels/form-download.js +6 -1
  40. package/lib/models/labels/form-download.js.map +1 -1
  41. package/lib/models/labels/label-download.d.ts +2 -0
  42. package/lib/models/labels/label-download.js +6 -1
  43. package/lib/models/labels/label-download.js.map +1 -1
  44. package/lib/models/labels/label-package.d.ts +2 -0
  45. package/lib/models/labels/label-package.js +10 -1
  46. package/lib/models/labels/label-package.js.map +1 -1
  47. package/lib/models/labels/void-response.d.ts +5 -0
  48. package/lib/models/labels/void-response.js +10 -1
  49. package/lib/models/labels/void-response.js.map +1 -1
  50. package/lib/models/manifests/manifest.d.ts +2 -0
  51. package/lib/models/manifests/manifest.js +10 -1
  52. package/lib/models/manifests/manifest.js.map +1 -1
  53. package/lib/models/pickup/pickup-confirmation.d.ts +2 -0
  54. package/lib/models/pickup/pickup-confirmation.js +10 -1
  55. package/lib/models/pickup/pickup-confirmation.js.map +1 -1
  56. package/lib/models/pickup/pickup-window.d.ts +2 -0
  57. package/lib/models/pickup/pickup-window.js +9 -1
  58. package/lib/models/pickup/pickup-window.js.map +1 -1
  59. package/lib/models/pickup/shipment-identifier.d.ts +2 -0
  60. package/lib/models/pickup/shipment-identifier.js +8 -1
  61. package/lib/models/pickup/shipment-identifier.js.map +1 -1
  62. package/lib/models/rates/rate.d.ts +2 -0
  63. package/lib/models/rates/rate.js +18 -1
  64. package/lib/models/rates/rate.js.map +1 -1
  65. package/lib/models/registration/credentials.d.ts +2 -0
  66. package/lib/models/registration/credentials.js +7 -1
  67. package/lib/models/registration/credentials.js.map +1 -1
  68. package/lib/models/resource-download.d.ts +2 -0
  69. package/lib/models/resource-download.js +7 -1
  70. package/lib/models/resource-download.js.map +1 -1
  71. package/lib/models/time-window.d.ts +2 -0
  72. package/lib/models/time-window.js +8 -1
  73. package/lib/models/time-window.js.map +1 -1
  74. package/lib/models/tracking/index.d.ts +1 -0
  75. package/lib/models/tracking/index.js +1 -0
  76. package/lib/models/tracking/index.js.map +1 -1
  77. package/lib/models/tracking/lat-long.d.ts +2 -0
  78. package/lib/models/tracking/lat-long.js +7 -1
  79. package/lib/models/tracking/lat-long.js.map +1 -1
  80. package/lib/models/tracking/service.d.ts +2 -0
  81. package/lib/models/tracking/service.js +7 -1
  82. package/lib/models/tracking/service.js.map +1 -1
  83. package/lib/models/tracking/standardized-status-codes.d.ts +2 -0
  84. package/lib/models/tracking/standardized-status-codes.js +4 -1
  85. package/lib/models/tracking/standardized-status-codes.js.map +1 -1
  86. package/lib/models/tracking/track-event.d.ts +2 -0
  87. package/lib/models/tracking/track-event.js +18 -1
  88. package/lib/models/tracking/track-event.js.map +1 -1
  89. package/lib/models/tracking/tracking-info.d.ts +2 -0
  90. package/lib/models/tracking/tracking-info.js +27 -1
  91. package/lib/models/tracking/tracking-info.js.map +1 -1
  92. package/lib/models/tracking/update-method.d.ts +9 -0
  93. package/lib/models/tracking/update-method.js +15 -0
  94. package/lib/models/tracking/update-method.js.map +1 -0
  95. package/lib/models/units/dimensions.d.ts +2 -0
  96. package/lib/models/units/dimensions.js +8 -1
  97. package/lib/models/units/dimensions.js.map +1 -1
  98. package/lib/requests/base-request.d.ts +2 -0
  99. package/lib/requests/base-request.js.map +1 -1
  100. package/lib/requests/index.d.ts +2 -0
  101. package/lib/requests/index.js +2 -0
  102. package/lib/requests/index.js.map +1 -1
  103. package/lib/requests/normalize-tracking-data-request.d.ts +8 -0
  104. package/lib/requests/normalize-tracking-data-request.js +3 -0
  105. package/lib/requests/normalize-tracking-data-request.js.map +1 -0
  106. package/lib/requests/validate-inbound-data-request.d.ts +8 -0
  107. package/lib/requests/validate-inbound-data-request.js +3 -0
  108. package/lib/requests/validate-inbound-data-request.js.map +1 -0
  109. package/lib/responses/base-response.d.ts +2 -0
  110. package/lib/responses/base-response.js +6 -1
  111. package/lib/responses/base-response.js.map +1 -1
  112. package/lib/responses/cancel-notification-response.d.ts +2 -0
  113. package/lib/responses/cancel-notification-response.js +7 -1
  114. package/lib/responses/cancel-notification-response.js.map +1 -1
  115. package/lib/responses/cancel-pickup-response.d.ts +2 -0
  116. package/lib/responses/cancel-pickup-response.js +9 -1
  117. package/lib/responses/cancel-pickup-response.js.map +1 -1
  118. package/lib/responses/create-label-response.d.ts +2 -0
  119. package/lib/responses/create-label-response.js +19 -1
  120. package/lib/responses/create-label-response.js.map +1 -1
  121. package/lib/responses/create-manifest-response.d.ts +2 -0
  122. package/lib/responses/create-manifest-response.js +8 -1
  123. package/lib/responses/create-manifest-response.js.map +1 -1
  124. package/lib/responses/create-notification-response.d.ts +2 -0
  125. package/lib/responses/create-notification-response.js +6 -1
  126. package/lib/responses/create-notification-response.js.map +1 -1
  127. package/lib/responses/get-rates-response.d.ts +2 -0
  128. package/lib/responses/get-rates-response.js +7 -1
  129. package/lib/responses/get-rates-response.js.map +1 -1
  130. package/lib/responses/index.d.ts +2 -0
  131. package/lib/responses/index.js +2 -0
  132. package/lib/responses/index.js.map +1 -1
  133. package/lib/responses/normalize-tracking-data-response.d.ts +14 -0
  134. package/lib/responses/normalize-tracking-data-response.js +16 -0
  135. package/lib/responses/normalize-tracking-data-response.js.map +1 -0
  136. package/lib/responses/register-response.d.ts +2 -0
  137. package/lib/responses/register-response.js +8 -1
  138. package/lib/responses/register-response.js.map +1 -1
  139. package/lib/responses/schedule-pickup-response.d.ts +2 -0
  140. package/lib/responses/schedule-pickup-response.js +11 -1
  141. package/lib/responses/schedule-pickup-response.js.map +1 -1
  142. package/lib/responses/tracking-response.d.ts +1 -0
  143. package/lib/responses/tracking-response.js +5 -1
  144. package/lib/responses/tracking-response.js.map +1 -1
  145. package/lib/responses/validate-inbound-data-response.d.ts +9 -0
  146. package/lib/responses/validate-inbound-data-response.js +15 -0
  147. package/lib/responses/validate-inbound-data-response.js.map +1 -0
  148. package/lib/responses/void-labels-response.d.ts +2 -0
  149. package/lib/responses/void-labels-response.js +7 -1
  150. package/lib/responses/void-labels-response.js.map +1 -1
  151. package/package.json +2 -2
  152. package/spec.json +31 -1
  153. package/src/app/carrier-app-definition.ts +18 -0
  154. package/src/app/carrier-app.ts +107 -55
  155. package/src/app/constants.ts +14 -0
  156. package/src/app/internal/route.ts +1 -0
  157. package/src/models/authorization.ts +4 -0
  158. package/src/models/billing/billing-categories.ts +6 -0
  159. package/src/models/billing/billing-line-item.ts +14 -2
  160. package/src/models/currency.ts +7 -0
  161. package/src/models/documents/document-type.ts +6 -0
  162. package/src/models/documents/document.ts +11 -2
  163. package/src/models/identifier.ts +7 -0
  164. package/src/models/inbound-content-types.ts +10 -0
  165. package/src/models/index.ts +2 -0
  166. package/src/models/labels/document-formats.ts +5 -0
  167. package/src/models/labels/form-download.ts +6 -1
  168. package/src/models/labels/label-download.ts +6 -1
  169. package/src/models/labels/label-package.ts +9 -2
  170. package/src/models/labels/void-response.ts +11 -0
  171. package/src/models/manifests/manifest.ts +9 -1
  172. package/src/models/pickup/pickup-confirmation.ts +11 -2
  173. package/src/models/pickup/pickup-window.ts +8 -0
  174. package/src/models/pickup/shipment-identifier.ts +7 -1
  175. package/src/models/rates/rate.ts +20 -2
  176. package/src/models/registration/credentials.ts +7 -0
  177. package/src/models/resource-download.ts +7 -0
  178. package/src/models/time-window.ts +8 -0
  179. package/src/models/tracking/index.ts +1 -0
  180. package/src/models/tracking/lat-long.ts +7 -0
  181. package/src/models/tracking/service.ts +6 -0
  182. package/src/models/tracking/standardized-status-codes.ts +6 -0
  183. package/src/models/tracking/track-event.ts +16 -0
  184. package/src/models/tracking/tracking-info.ts +29 -4
  185. package/src/models/tracking/update-method.ts +13 -0
  186. package/src/models/units/dimensions.ts +7 -0
  187. package/src/requests/base-request.ts +3 -0
  188. package/src/requests/index.ts +2 -0
  189. package/src/requests/normalize-tracking-data-request.ts +9 -0
  190. package/src/requests/validate-inbound-data-request.ts +9 -0
  191. package/src/responses/base-response.ts +6 -0
  192. package/src/responses/cancel-notification-response.ts +7 -1
  193. package/src/responses/cancel-pickup-response.ts +9 -1
  194. package/src/responses/create-label-response.ts +25 -1
  195. package/src/responses/create-manifest-response.ts +8 -2
  196. package/src/responses/create-notification-response.ts +6 -1
  197. package/src/responses/get-rates-response.ts +7 -2
  198. package/src/responses/index.ts +2 -0
  199. package/src/responses/normalize-tracking-data-response.ts +24 -0
  200. package/src/responses/register-response.ts +6 -1
  201. package/src/responses/schedule-pickup-response.ts +18 -2
  202. package/src/responses/tracking-response.ts +6 -2
  203. package/src/responses/validate-inbound-data-response.ts +16 -0
  204. package/src/responses/void-labels-response.ts +7 -2
  205. package/tsconfig.tsbuildinfo +1 -1
package/spec.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "info": {
4
4
  "title": "ShipEngine Connect Carrier API",
5
5
  "description": "This API specification describes the canonical ShipEngine Carrier API connector module. A module which implements one or more endpoints from this specification can be integrated with the ShipEngine Carrier Platform.",
6
- "version": "1.14.10"
6
+ "version": "1.14.13"
7
7
  },
8
8
  "paths": {
9
9
  "/Register": {
@@ -1178,6 +1178,25 @@
1178
1178
  "additionalProperties": { },
1179
1179
  "description": "This is a schemaless object. It is for open ended customizations unique to particular carriers. The documented\r\nkeys are some common options shared by many carriers, but are not definitive. Advanced options you support will\r\nbe defined in ShipEngine. If the field is absent it should be interpreted as the default value for any\r\napplicable options, e.g. false for booleans."
1180
1180
  },
1181
+ "Authorization": {
1182
+ "type": "object",
1183
+ "properties": {
1184
+ "access_token": {
1185
+ "type": "string",
1186
+ "description": "The access token used to authorize the request",
1187
+ "nullable": true
1188
+ },
1189
+ "connection_context": {
1190
+ "type": "object",
1191
+ "additionalProperties": {
1192
+ "type": "string"
1193
+ },
1194
+ "description": "Optional - any additional information required to authorize the request",
1195
+ "nullable": true
1196
+ }
1197
+ },
1198
+ "additionalProperties": false
1199
+ },
1181
1200
  "BadRequestResponse": {
1182
1201
  "type": "object",
1183
1202
  "allOf": [
@@ -1196,6 +1215,9 @@
1196
1215
  "description": "The transaction ID uniquely represents this request. If the request is retried then this transaction ID will be the same. You should only perform the requested action once per given transaction ID.",
1197
1216
  "format": "uuid"
1198
1217
  },
1218
+ "authorization": {
1219
+ "$ref": "#/components/schemas/Authorization"
1220
+ },
1199
1221
  "metadata": {
1200
1222
  "type": "object",
1201
1223
  "additionalProperties": { },
@@ -3449,6 +3471,14 @@
3449
3471
  },
3450
3472
  "description": "A list of errors preventing this label from being voided. If no errors are returned the void is considered\r\nsuccessful. If any errors are returned the void is considered failed.",
3451
3473
  "nullable": true
3474
+ },
3475
+ "billing_line_items": {
3476
+ "type": "array",
3477
+ "items": {
3478
+ "$ref": "#/components/schemas/BillingLineItem"
3479
+ },
3480
+ "description": "Individual Billing Line items which remain after voiding the label, e.g. a cancellation fee.",
3481
+ "nullable": true
3452
3482
  }
3453
3483
  },
3454
3484
  "additionalProperties": false,
@@ -9,6 +9,8 @@ import {
9
9
  TrackingRequest,
10
10
  CancelNotificationRequest,
11
11
  CreateNotificationRequest,
12
+ ValidateInboundDataRequest,
13
+ NormalizeTrackingDataRequest,
12
14
  } from '../requests';
13
15
 
14
16
  import {
@@ -22,6 +24,8 @@ import {
22
24
  TrackingResponse,
23
25
  CancelNotificationResponse,
24
26
  CreateNotificationResponse,
27
+ ValidateInboundDataResponse,
28
+ NormalizeTrackingDataResponse,
25
29
  } from '../responses';
26
30
 
27
31
  import { CarrierAppMetadata } from './metadata/carrier-app-metadata';
@@ -101,4 +105,18 @@ export interface CarrierAppDefinition {
101
105
  CancelNotification?: (
102
106
  request: CancelNotificationRequest,
103
107
  ) => CancelNotificationResponse | Promise<CancelNotificationResponse>;
108
+ /**
109
+ * @description This endpoint is used to validate inbound data and determine the type of data included in the inbound message
110
+ * @param request Data received from the provider via an inbound method, such as a webhook
111
+ */
112
+ ValidateInboundData?: (
113
+ request: ValidateInboundDataRequest,
114
+ ) => ValidateInboundDataResponse | Promise<ValidateInboundDataRequest>;
115
+ /**
116
+ * @description This endpoint is used to normalize inbound tracking data and determine the type of data
117
+ * @param request Tracking data received from the provider via an inbound method, such as a webhook
118
+ */
119
+ NormalizeTrackingData?: (
120
+ request: NormalizeTrackingDataRequest,
121
+ ) => NormalizeTrackingDataResponse | Promise<NormalizeTrackingDataResponse>;
104
122
  }
@@ -1,12 +1,27 @@
1
1
  import { CarrierAppDefinition } from '.';
2
2
  import { ConnectRuntimeApp, Method, Route, BrandedImages } from './internal';
3
-
3
+ import { ApiEndpoints } from './constants';
4
4
  import { resolve } from 'path';
5
5
  import { readFileSync, existsSync } from 'fs';
6
6
 
7
7
  import { Metadata } from './internal/metadata';
8
8
  import { CarrierSpecification } from './internal/carrier-specificaion';
9
9
  import { CarrierAppMetadataSchema } from './metadata';
10
+ import {
11
+ RegisterResponseSchema,
12
+ CancelNotificationResponseSchema,
13
+ CancelPickupResponseSchema,
14
+ SchedulePickupResponseSchema,
15
+ TrackingResponseSchema,
16
+ GetRatesResponseSchema,
17
+ VoidLabelsResponseSchema,
18
+ CreateLabelResponseSchema,
19
+ CreateManifestResponseSchema,
20
+ CreateNotificationResponseSchema,
21
+ ValidateInboundDataResponseSchema,
22
+ NormalizeTrackingDataResponseSchema,
23
+ } from '../responses';
24
+ import { Schema } from 'joi';
10
25
 
11
26
  const handleRequest = (implementation?: Function): any => {
12
27
  if (implementation) {
@@ -16,66 +31,12 @@ const handleRequest = (implementation?: Function): any => {
16
31
  }
17
32
  };
18
33
 
19
- const registerRoutes = (routes: Route[], definition: CarrierAppDefinition) => {
20
- routes.push({
21
- method: Method.POST,
22
- path: '/Register',
23
- handler: handleRequest(definition.Register),
24
- });
25
- routes.push({
26
- method: Method.POST,
27
- path: '/CreateLabel',
28
- handler: handleRequest(definition.CreateLabel),
29
- });
30
- routes.push({
31
- method: Method.POST,
32
- path: '/VoidLabels',
33
- handler: handleRequest(definition.VoidLabels),
34
- });
35
- routes.push({
36
- method: Method.POST,
37
- path: '/GetRates',
38
- handler: handleRequest(definition.GetRates),
39
- });
40
- routes.push({
41
- method: Method.POST,
42
- path: '/CreateManifest',
43
- handler: handleRequest(definition.CreateManifest),
44
- });
45
- routes.push({
46
- method: Method.POST,
47
- path: '/SchedulePickup',
48
- handler: handleRequest(definition.SchedulePickup),
49
- });
50
- routes.push({
51
- method: Method.POST,
52
- path: '/CancelPickup',
53
- handler: handleRequest(definition.CancelPickup),
54
- });
55
- routes.push({
56
- method: Method.POST,
57
- path: '/Track',
58
- handler: handleRequest(definition.Track),
59
- });
60
- routes.push({
61
- method: Method.POST,
62
- path: '/CreateNotification',
63
- handler: handleRequest(definition.CreateNotification),
64
- });
65
- routes.push({
66
- method: Method.POST,
67
- path: '/CancelNotification',
68
- handler: handleRequest(definition.CancelNotification),
69
- });
70
- };
71
-
72
34
  export class CarrierApp implements ConnectRuntimeApp {
73
35
  routes: Route[] = [];
74
36
  data: Metadata;
75
37
  redoc?: string;
76
38
  validate: () => string[] | undefined;
77
39
  constructor(definition: CarrierAppDefinition) {
78
- registerRoutes(this.routes, definition);
79
40
  this.validate = () => {
80
41
  const results = CarrierAppMetadataSchema.validate(definition.Metadata, {
81
42
  allowUnknown: true,
@@ -85,6 +46,97 @@ export class CarrierApp implements ConnectRuntimeApp {
85
46
  return results.error.details.map((detail) => `${detail.message}`);
86
47
  }
87
48
  };
49
+ new Array<[Method, ApiEndpoints, any, Schema]>(
50
+ [
51
+ Method.POST,
52
+ ApiEndpoints.CancelNotification,
53
+ definition.CancelNotification,
54
+ CancelNotificationResponseSchema,
55
+ ],
56
+ [
57
+ Method.POST,
58
+ ApiEndpoints.CancelPickup,
59
+ definition.CancelPickup,
60
+ CancelPickupResponseSchema,
61
+ ],
62
+ [
63
+ Method.POST,
64
+ ApiEndpoints.CreateLabel,
65
+ definition.CreateLabel,
66
+ CreateLabelResponseSchema,
67
+ ],
68
+ [
69
+ Method.POST,
70
+ ApiEndpoints.CreateManifest,
71
+ definition.CreateManifest,
72
+ CreateManifestResponseSchema,
73
+ ],
74
+ [
75
+ Method.POST,
76
+ ApiEndpoints.CreateNotification,
77
+ definition.CreateNotification,
78
+ CreateNotificationResponseSchema,
79
+ ],
80
+ [
81
+ Method.POST,
82
+ ApiEndpoints.GetRates,
83
+ definition.GetRates,
84
+ GetRatesResponseSchema,
85
+ ],
86
+ [
87
+ Method.POST,
88
+ ApiEndpoints.NormalizeTrackingData,
89
+ definition.NormalizeTrackingData,
90
+ NormalizeTrackingDataResponseSchema,
91
+ ],
92
+ [
93
+ Method.POST,
94
+ ApiEndpoints.Register,
95
+ definition.Register,
96
+ RegisterResponseSchema,
97
+ ],
98
+ [
99
+ Method.POST,
100
+ ApiEndpoints.SchedulePickup,
101
+ definition.SchedulePickup,
102
+ SchedulePickupResponseSchema,
103
+ ],
104
+ [
105
+ Method.POST,
106
+ ApiEndpoints.Track,
107
+ definition.Track,
108
+ TrackingResponseSchema,
109
+ ],
110
+ [
111
+ Method.POST,
112
+ ApiEndpoints.ValidateInboundData,
113
+ definition.ValidateInboundData,
114
+ ValidateInboundDataResponseSchema,
115
+ ],
116
+ [
117
+ Method.POST,
118
+ ApiEndpoints.VoidLabels,
119
+ definition.VoidLabels,
120
+ VoidLabelsResponseSchema,
121
+ ],
122
+ ).forEach(([method, path, implementation, schema]) => {
123
+ if (implementation) {
124
+ this.routes.push({
125
+ method,
126
+ path,
127
+ handler: handleRequest(implementation as Function),
128
+ validateResponse: (result: any): string[] | undefined => {
129
+ const validationResults = schema.validate(result, {
130
+ abortEarly: false,
131
+ });
132
+ const errors = validationResults?.error?.details?.map(
133
+ (detail) => detail.message,
134
+ );
135
+ return errors;
136
+ },
137
+ });
138
+ }
139
+ });
88
140
  this.data = new Metadata(definition);
89
141
 
90
142
  const jsonSpecPath = resolve(__dirname, '../../spec.json');
@@ -0,0 +1,14 @@
1
+ export enum ApiEndpoints {
2
+ Register = '/Register',
3
+ CreateLabel = '/CreateLabel',
4
+ VoidLabels = '/VoidLabels',
5
+ GetRates = '/GetRates',
6
+ CreateManifest = '/CreateManifest',
7
+ SchedulePickup = '/SchedulePickup',
8
+ CancelPickup = '/CancelPickup',
9
+ Track = '/Track',
10
+ CreateNotification = '/CreateNotification',
11
+ CancelNotification = '/CancelNotification',
12
+ ValidateInboundData = '/ValidateInboundData',
13
+ NormalizeTrackingData = '/NormalizeTrackingData',
14
+ }
@@ -10,4 +10,5 @@ export interface Route {
10
10
  path: string;
11
11
  method: Method;
12
12
  handler?: (req: any) => any | Promise<any>;
13
+ validateResponse?: (response: any) => string[] | undefined;
13
14
  }
@@ -0,0 +1,4 @@
1
+ export class Authorization {
2
+ access_token?: string;
3
+ connection_context?: any;
4
+ }
@@ -1,3 +1,5 @@
1
+ import Joi from 'joi';
2
+
1
3
  /** @description Category for a billing line item */
2
4
  export enum BillingCategories {
3
5
  Uncategorized = 'uncategorized',
@@ -23,3 +25,7 @@ export enum BillingCategories {
23
25
  /** @description Amount to be paid to the driver, used for local delivery and courier services. */
24
26
  Tip = 'tip',
25
27
  }
28
+
29
+ export const BillingCategoriesSchema = Joi.string().valid(
30
+ ...Object.values(BillingCategories),
31
+ );
@@ -1,5 +1,9 @@
1
- import { BillingCategories } from './billing-categories';
2
- import { Currency } from '../currency';
1
+ import {
2
+ BillingCategories,
3
+ BillingCategoriesSchema,
4
+ } from './billing-categories';
5
+ import { Currency, CurrencySchema } from '../currency';
6
+ import Joi from 'joi';
3
7
 
4
8
  /** @description Basic structure of each charge or line item */
5
9
  export class BillingLineItem {
@@ -9,3 +13,11 @@ export class BillingLineItem {
9
13
  memo?: string;
10
14
  amount!: Currency;
11
15
  }
16
+
17
+ export const BillingLineItemSchema = Joi.object({
18
+ billing_category: BillingCategoriesSchema.required(),
19
+ carrier_description: Joi.string().optional().empty(),
20
+ carrier_billing_code: Joi.string().optional().empty(),
21
+ memo: Joi.string().optional().empty(),
22
+ amount: CurrencySchema.required(),
23
+ });
@@ -1,5 +1,12 @@
1
+ import Joi from 'joi';
2
+
1
3
  /** @description Basic structure for defining an amount of money and its currency */
2
4
  export class Currency {
3
5
  currency!: string;
4
6
  amount!: string;
5
7
  }
8
+
9
+ export const CurrencySchema = Joi.object({
10
+ currency: Joi.string().required(),
11
+ amount: Joi.string().required(),
12
+ });
@@ -1,3 +1,5 @@
1
+ import Joi from 'joi';
2
+
1
3
  /** @description Types of documents */
2
4
  export enum DocumentType {
3
5
  Label = 'label',
@@ -5,3 +7,7 @@ export enum DocumentType {
5
7
  CommercialInvoice = 'commercial_invoice',
6
8
  BillOfLading = 'bill_of_lading',
7
9
  }
10
+
11
+ export const DocumentTypeSchema = Joi.string().valid(
12
+ ...Object.values(DocumentType),
13
+ );
@@ -1,5 +1,9 @@
1
- import { DocumentType } from './document-type';
2
- import { DocumentFormat } from '../labels/document-formats';
1
+ import { DocumentType, DocumentTypeSchema } from './document-type';
2
+ import {
3
+ DocumentFormat,
4
+ DocumentFormatSchema,
5
+ } from '../labels/document-formats';
6
+ import Joi from 'joi';
3
7
 
4
8
  /** @description Basic structure for a document */
5
9
  export class Document {
@@ -7,3 +11,8 @@ export class Document {
7
11
  data!: string;
8
12
  format!: DocumentFormat;
9
13
  }
14
+ export const DocumentSchema = Joi.object({
15
+ type: Joi.array().required().min(1).items(DocumentTypeSchema),
16
+ data: Joi.string().required(),
17
+ format: DocumentFormatSchema.required(),
18
+ });
@@ -1,5 +1,12 @@
1
+ import Joi from 'joi';
2
+
1
3
  /** @description Key value pair to allow custom properties */
2
4
  export class Identifier {
3
5
  type!: string;
4
6
  value!: string;
5
7
  }
8
+
9
+ export const IdentifierSchema = Joi.object({
10
+ type: Joi.string().required(),
11
+ value: Joi.string().required(),
12
+ });
@@ -0,0 +1,10 @@
1
+ import Joi from 'joi';
2
+
3
+ /** @description Types of inbound content */
4
+ export enum InboundDataContentTypes {
5
+ /** @description Tracking information */
6
+ Tracking = 'tracking',
7
+ }
8
+ export const InboundDataContentTypesSchema = Joi.string().valid(
9
+ ...Object.values(InboundDataContentTypes),
10
+ );
@@ -1,4 +1,5 @@
1
1
  export * from './addresses';
2
+ export * from './authorization';
2
3
  export * from './billing';
3
4
  export * from './customs';
4
5
  export * from './errors';
@@ -20,3 +21,4 @@ export * from './resource-download';
20
21
  export * from './taxes';
21
22
  export * from './documents';
22
23
  export * from './time-window';
24
+ export * from './inbound-content-types';
@@ -1,6 +1,11 @@
1
+ import Joi from 'joi';
2
+
1
3
  /** @description Label data type */
2
4
  export enum DocumentFormat {
3
5
  Pdf = 'PDF',
4
6
  Zpl = 'ZPL',
5
7
  Png = 'PNG',
6
8
  }
9
+ export const DocumentFormatSchema = Joi.string().valid(
10
+ ...Object.values(DocumentFormat),
11
+ );
@@ -1,5 +1,10 @@
1
- import { ResourceDownload } from '../resource-download';
1
+ import Joi from 'joi';
2
+ import { ResourceDownload, ResourceDownloadSchema } from '../resource-download';
2
3
 
3
4
  export class FormDownload extends ResourceDownload {
4
5
  form_data?: string;
5
6
  }
7
+
8
+ export const FormDownloadSchema = ResourceDownloadSchema.keys({
9
+ form_data: Joi.string().optional().empty(),
10
+ });
@@ -1,5 +1,10 @@
1
- import { ResourceDownload } from '../resource-download';
1
+ import Joi from 'joi';
2
+ import { ResourceDownload, ResourceDownloadSchema } from '../resource-download';
2
3
 
3
4
  export class LabelDownload extends ResourceDownload {
4
5
  label_data?: string;
5
6
  }
7
+
8
+ export const LabelDownloadSchema = ResourceDownloadSchema.keys({
9
+ label_data: Joi.string().optional().empty(),
10
+ });
@@ -1,5 +1,6 @@
1
- import { Identifier } from '../identifier';
2
- import { Document } from '../documents';
1
+ import { Identifier, IdentifierSchema } from '../identifier';
2
+ import { Document, DocumentSchema } from '../documents';
3
+ import Joi from 'joi';
3
4
 
4
5
  /** @description Package information provided by the carrier */
5
6
  export class LabelPackage {
@@ -8,3 +9,9 @@ export class LabelPackage {
8
9
  alternative_identifiers?: Identifier[];
9
10
  documents?: Document[];
10
11
  }
12
+
13
+ export const LabelPackageSchema = Joi.object({
14
+ tracking_number: Joi.string().optional().empty(),
15
+ alternative_identifiers: Joi.array().optional().items(IdentifierSchema),
16
+ documents: Joi.array().optional().items(DocumentSchema),
17
+ });
@@ -1,3 +1,5 @@
1
+ import Joi from 'joi';
2
+ import { BillingLineItem, BillingLineItemSchema } from '../billing';
1
3
  /** @description Basic structure for a response to void a label */
2
4
  export class VoidResponse {
3
5
  /** @description Id for the void response */
@@ -6,4 +8,13 @@ export class VoidResponse {
6
8
  message?: string;
7
9
  /** @description Any errors from attempting to void */
8
10
  errors?: string[];
11
+ /** @description Individual Billing Line items which remain after voiding the label, e.g. a cancellation fee. */
12
+ billing_line_items?: BillingLineItem[];
9
13
  }
14
+
15
+ export const VoidResponseSchema = Joi.object({
16
+ void_request_id: Joi.string().required(),
17
+ message: Joi.string().optional().empty(),
18
+ errors: Joi.array().optional().items(Joi.string()),
19
+ billing_line_items: Joi.array().optional().items(BillingLineItemSchema),
20
+ });
@@ -1,4 +1,5 @@
1
- import { ResourceDownload } from '../resource-download';
1
+ import Joi from 'joi';
2
+ import { ResourceDownload, ResourceDownloadSchema } from '../resource-download';
2
3
 
3
4
  /** @description Basic structure of a manifest */
4
5
  export class Manifest {
@@ -7,3 +8,10 @@ export class Manifest {
7
8
  document_href?: string;
8
9
  document_data?: string;
9
10
  }
11
+
12
+ export const ManifestSchema = Joi.object({
13
+ manifest_id: Joi.string().optional().empty(),
14
+ document_download: ResourceDownloadSchema.optional(),
15
+ document_href: Joi.string().optional().empty(),
16
+ document_data: Joi.string().optional().empty(),
17
+ });
@@ -1,5 +1,9 @@
1
- import { Identifier } from '../identifier';
2
- import { ShipmentIdentifier } from './shipment-identifier';
1
+ import Joi from 'joi';
2
+ import { Identifier, IdentifierSchema } from '../identifier';
3
+ import {
4
+ ShipmentIdentifier,
5
+ ShipmentIdentifierSchema,
6
+ } from './shipment-identifier';
3
7
 
4
8
  /** @description Basic structure for a pickup confirmation */
5
9
  export class PickupConfirmation {
@@ -7,3 +11,8 @@ export class PickupConfirmation {
7
11
  alternate_identifiers?: Identifier[];
8
12
  shipment_identifiers?: ShipmentIdentifier[];
9
13
  }
14
+ export const PickupConfirmationSchema = Joi.object({
15
+ confirmation_id: Joi.string().optional().empty(),
16
+ alternate_identifiers: Joi.array().optional().items(IdentifierSchema),
17
+ shipment_identifiers: Joi.array().optional().items(ShipmentIdentifierSchema),
18
+ });
@@ -1,3 +1,5 @@
1
+ import Joi from 'joi';
2
+
1
3
  /** @description Time window for pickup */
2
4
  export class PickupWindow {
3
5
  time_zone_iana!: string;
@@ -5,3 +7,9 @@ export class PickupWindow {
5
7
  start_time?: string;
6
8
  end_time?: string;
7
9
  }
10
+ export const PickupWindowSchema = Joi.object({
11
+ time_zone_iana: Joi.string().required(),
12
+ pickup_date: Joi.string().required().isoDate(),
13
+ start_time: Joi.string().optional().isoDate(),
14
+ end_time: Joi.string().optional().isoDate(),
15
+ });
@@ -1,7 +1,13 @@
1
- import { Identifier } from '../identifier';
1
+ import Joi from 'joi';
2
+ import { Identifier, IdentifierSchema } from '../identifier';
2
3
 
3
4
  /** @description Identifier object for shiments */
4
5
  export class ShipmentIdentifier {
5
6
  tracking_number?: string;
6
7
  alternate_identifiers?: Identifier[];
7
8
  }
9
+
10
+ export const ShipmentIdentifierSchema = Joi.object({
11
+ tracking_number: Joi.string().optional().empty(),
12
+ alternate_identifiers: Joi.array().optional().items(IdentifierSchema),
13
+ });
@@ -1,5 +1,9 @@
1
- import { BillingLineItem } from '../billing/billing-line-item';
2
- import { TimeWindow } from '../time-window';
1
+ import Joi from 'joi';
2
+ import {
3
+ BillingLineItem,
4
+ BillingLineItemSchema,
5
+ } from '../billing/billing-line-item';
6
+ import { TimeWindow, TimeWindowSchema } from '../time-window';
3
7
 
4
8
  /** @description Basic structure for a rate */
5
9
  export class Rate {
@@ -28,3 +32,17 @@ export class Rate {
28
32
  */
29
33
  expiration_datetime?: string;
30
34
  }
35
+
36
+ export const RateSchema = Joi.object({
37
+ service_code: Joi.string().optional().empty(),
38
+ ship_datetime: Joi.string().optional().empty().isoDate(),
39
+ estimated_delivery_datetime: Joi.string().optional().empty().isoDate(),
40
+ billing_line_items: Joi.array().optional().items(BillingLineItemSchema),
41
+ error_messages: Joi.array().optional().items(Joi.string()),
42
+ warning_messages: Joi.array().optional().items(Joi.string()),
43
+ negotiated_rate: Joi.boolean().optional(),
44
+ carrier_pickup_window: TimeWindowSchema.optional(),
45
+ delivery_window: TimeWindowSchema.optional(),
46
+ carrier_rate_id: Joi.string().optional().empty(),
47
+ expiration_datetime: Joi.string().optional().empty().isoDate(),
48
+ });
@@ -1,5 +1,12 @@
1
+ import Joi from 'joi';
2
+
1
3
  /** @description Basic structure for credentials */
2
4
  export class Credentials {
3
5
  username!: string;
4
6
  password!: string;
5
7
  }
8
+
9
+ export const CredentialsSchema = Joi.object({
10
+ username: Joi.string().required(),
11
+ password: Joi.string().required(),
12
+ });
@@ -1,5 +1,12 @@
1
+ import Joi from 'joi';
2
+
1
3
  /** @description Basic structure for a resource to download */
2
4
  export class ResourceDownload {
3
5
  href?: string;
4
6
  data?: string;
5
7
  }
8
+
9
+ export const ResourceDownloadSchema = Joi.object({
10
+ href: Joi.string().optional().empty(),
11
+ data: Joi.string().optional().empty(),
12
+ });
@@ -1,3 +1,5 @@
1
+ import Joi from 'joi';
2
+
1
3
  /** @description Basic structure for defining a time window */
2
4
  export class TimeWindow {
3
5
  /** @description The local time zone represented in IANA. See https://www.iana.org/time-zones.
@@ -15,3 +17,9 @@ export class TimeWindow {
15
17
  */
16
18
  end_window?: string;
17
19
  }
20
+
21
+ export const TimeWindowSchema = Joi.object({
22
+ time_zone_iana: Joi.string().required(),
23
+ start_window: Joi.string().required().isoDate(),
24
+ end_window: Joi.string().optional().empty().isoDate(),
25
+ });
@@ -5,3 +5,4 @@ export * from './track-event';
5
5
  export * from './tracking-attribute';
6
6
  export * from './tracking-identifier';
7
7
  export * from './tracking-info';
8
+ export * from './update-method';