@shipengine/connect-carrier-api 2.4.7 → 2.5.1

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 (66) hide show
  1. package/lib/app/carrier-app-definition.d.ts +7 -2
  2. package/lib/app/carrier-app.js +10 -2
  3. package/lib/app/carrier-app.js.map +1 -1
  4. package/lib/app/constants.d.ts +1 -0
  5. package/lib/app/constants.js +1 -0
  6. package/lib/app/constants.js.map +1 -1
  7. package/lib/app/internal/carrier-specification.d.ts +1 -0
  8. package/lib/app/internal/carrier-specification.js +1 -0
  9. package/lib/app/internal/carrier-specification.js.map +1 -1
  10. package/lib/app/internal/metadata.js +3 -0
  11. package/lib/app/internal/metadata.js.map +1 -1
  12. package/lib/app/metadata/carrier.d.ts +1 -0
  13. package/lib/app/metadata/carrier.js +1 -0
  14. package/lib/app/metadata/carrier.js.map +1 -1
  15. package/lib/models/labels/index.d.ts +3 -0
  16. package/lib/models/labels/index.js +3 -0
  17. package/lib/models/labels/index.js.map +1 -1
  18. package/lib/models/labels/label-details.d.ts +36 -0
  19. package/lib/models/labels/label-details.js +8 -0
  20. package/lib/models/labels/label-details.js.map +1 -0
  21. package/lib/models/labels/label-payment-result.d.ts +10 -0
  22. package/lib/models/labels/label-payment-result.js +17 -0
  23. package/lib/models/labels/label-payment-result.js.map +1 -0
  24. package/lib/models/labels/label-request.d.ts +35 -0
  25. package/lib/models/labels/label-request.js +3 -0
  26. package/lib/models/labels/label-request.js.map +1 -0
  27. package/lib/models/manifests/manifest-request-shipment.d.ts +1 -1
  28. package/lib/models/manifests/manifest-request-shipment.js +2 -2
  29. package/lib/models/manifests/manifest-request-shipment.js.map +1 -1
  30. package/lib/models/time-window.d.ts +1 -1
  31. package/lib/models/time-window.js +3 -3
  32. package/lib/models/time-window.js.map +1 -1
  33. package/lib/requests/create-label-payment-request.d.ts +6 -0
  34. package/lib/requests/create-label-payment-request.js +9 -0
  35. package/lib/requests/create-label-payment-request.js.map +1 -0
  36. package/lib/requests/create-label-request.d.ts +3 -2
  37. package/lib/requests/create-label-request.js.map +1 -1
  38. package/lib/requests/index.d.ts +1 -0
  39. package/lib/requests/index.js +1 -0
  40. package/lib/requests/index.js.map +1 -1
  41. package/lib/responses/create-label-payment-response.d.ts +9 -0
  42. package/lib/responses/create-label-payment-response.js +16 -0
  43. package/lib/responses/create-label-payment-response.js.map +1 -0
  44. package/lib/responses/index.d.ts +1 -0
  45. package/lib/responses/index.js +1 -0
  46. package/lib/responses/index.js.map +1 -1
  47. package/package.json +1 -1
  48. package/spec.json +800 -212
  49. package/src/app/carrier-app-definition.ts +9 -0
  50. package/src/app/carrier-app.ts +12 -2
  51. package/src/app/constants.ts +1 -0
  52. package/src/app/internal/carrier-specification.ts +2 -0
  53. package/src/app/internal/metadata.ts +4 -0
  54. package/src/app/metadata/carrier.ts +2 -0
  55. package/src/models/labels/index.ts +3 -0
  56. package/src/models/labels/label-details.ts +55 -0
  57. package/src/models/labels/label-payment-result.ts +17 -0
  58. package/src/models/labels/label-request.ts +53 -0
  59. package/src/models/manifests/manifest-request-shipment.ts +1 -1
  60. package/src/models/time-window.ts +4 -4
  61. package/src/requests/create-label-payment-request.ts +7 -0
  62. package/src/requests/create-label-request.ts +4 -1
  63. package/src/requests/index.ts +1 -0
  64. package/src/responses/create-label-payment-response.ts +14 -0
  65. package/src/responses/index.ts +1 -0
  66. package/tsconfig.tsbuildinfo +1 -1
@@ -13,6 +13,7 @@ import {
13
13
  ValidateInboundDataRequest,
14
14
  NormalizeTrackingDataRequest,
15
15
  GetRelayPointsRequest,
16
+ CreateLabelPaymentRequest,
16
17
  } from '../requests';
17
18
 
18
19
  import {
@@ -29,6 +30,7 @@ import {
29
30
  ValidateInboundDataResponse,
30
31
  NormalizeTrackingDataResponse,
31
32
  GetRelayPointsResponse,
33
+ CreateLabelPaymentResponse,
32
34
  } from '../responses';
33
35
 
34
36
  import { CarrierAppMetadata } from './metadata/carrier-app-metadata';
@@ -48,6 +50,13 @@ export interface CarrierAppDefinition {
48
50
  * @param request Data needed by the provider to create a label
49
51
  */
50
52
  CreateLabel?: (request: CreateLabelRequest) => CreateLabelResponse | Promise<CreateLabelResponse>;
53
+ /**
54
+ * @description This method is used to create a label
55
+ * @param request Data needed by the provider to create a label
56
+ */
57
+ CreateLabelPayment?: (
58
+ request: CreateLabelPaymentRequest,
59
+ ) => CreateLabelPaymentResponse | Promise<CreateLabelPaymentResponse>;
51
60
  /**
52
61
  * @description This method is used to void multiple labels
53
62
  * @param request Data needed by the provider to void multiple labels
@@ -15,6 +15,7 @@ import {
15
15
  GetRatesResponseSchema,
16
16
  VoidLabelsResponseSchema,
17
17
  CreateLabelResponseSchema,
18
+ CreateLabelPaymentResponseSchema,
18
19
  CreateManifestResponseSchema,
19
20
  CreateNotificationResponseSchema,
20
21
  ValidateInboundDataResponseSchema,
@@ -25,8 +26,11 @@ import { Schema } from 'joi';
25
26
 
26
27
  const handleRequest = (implementation?: Function): any => {
27
28
  if (implementation) {
28
- return (request: any) => {
29
- return implementation(request.body);
29
+ return async (request: any) => {
30
+ const { transaction_id } = request.body;
31
+ const result = await implementation(request.body);
32
+ result.transaction_id = transaction_id;
33
+ return result;
30
34
  };
31
35
  }
32
36
  };
@@ -69,6 +73,12 @@ export class CarrierApp implements ConnectRuntimeApp {
69
73
  ],
70
74
  [Method.POST, ApiEndpoints.CancelPickup, definition.CancelPickup, CancelPickupResponseSchema],
71
75
  [Method.POST, ApiEndpoints.CreateLabel, definition.CreateLabel, CreateLabelResponseSchema],
76
+ [
77
+ Method.POST,
78
+ ApiEndpoints.CreateLabelPayment,
79
+ definition.CreateLabelPayment,
80
+ CreateLabelPaymentResponseSchema,
81
+ ],
72
82
  [
73
83
  Method.POST,
74
84
  ApiEndpoints.CreateManifest,
@@ -1,6 +1,7 @@
1
1
  export enum ApiEndpoints {
2
2
  Register = '/Register',
3
3
  CreateLabel = '/CreateLabel',
4
+ CreateLabelPayment = '/CreateLabelPayment',
4
5
  VoidLabels = '/VoidLabels',
5
6
  GetRates = '/GetRates',
6
7
  CreateManifest = '/CreateManifest',
@@ -95,6 +95,7 @@ export class CarrierSpecification {
95
95
  AppId: string;
96
96
  DefaultRateCard: string;
97
97
  };
98
+ RequiresLabelPayment?: boolean;
98
99
 
99
100
  constructor(definition: Carrier) {
100
101
  this.Images = {
@@ -116,5 +117,6 @@ export class CarrierSpecification {
116
117
  this.CarrierUrl = definition.CarrierUrl;
117
118
  this.Description = definition.Description;
118
119
  this.NativeRating = definition.NativeRating;
120
+ this.RequiresLabelPayment = definition.RequiresLabelPayment;
119
121
  }
120
122
  }
@@ -22,6 +22,10 @@ const mapFunctions = (app: CarrierAppDefinition): FunctionSpecification[] => {
22
22
  fns.push(fn('CreateLabel'));
23
23
  }
24
24
 
25
+ if (app.CreateLabelPayment) {
26
+ fns.push(fn('CreateLabelPayment'));
27
+ }
28
+
25
29
  if (app.VoidLabels) {
26
30
  fns.push(fn('VoidLabels'));
27
31
  }
@@ -39,6 +39,7 @@ export interface Carrier {
39
39
  /** @description Default rate card to use for rating */
40
40
  DefaultRateCard: string;
41
41
  };
42
+ RequiresLabelPayment?: boolean;
42
43
  }
43
44
 
44
45
  const fileExists = (value: string, helpers: any) => {
@@ -90,4 +91,5 @@ export const CarrierSchema = Joi.object({
90
91
  .pattern(new RegExp('^.*.(svg)$'))
91
92
  .message('Images.Logo must be a svg file.'),
92
93
  }).required(),
94
+ RequiresLabelPayment: Joi.boolean().optional(),
93
95
  });
@@ -4,6 +4,9 @@ export * from './label-download';
4
4
  export * from './document-formats';
5
5
  export * from './label-layouts';
6
6
  export * from './label-message';
7
+ export * from './label-details';
8
+ export * from './label-payment-result';
9
+ export * from './label-request';
7
10
  export * from './return-label-details';
8
11
  export * from './void-request';
9
12
  export * from './void-response';
@@ -0,0 +1,55 @@
1
+ import {
2
+ ConfirmationTypes,
3
+ Document,
4
+ DocumentFormat,
5
+ LabelRequest,
6
+ LabelLayouts,
7
+ AdvancedOptions,
8
+ InsuranceProviders,
9
+ Package,
10
+ ShipTo,
11
+ ShipFrom,
12
+ PudoLocation,
13
+ RelayPointDetails,
14
+ ShipFromDisplay,
15
+ ReturnLabelDetails,
16
+ FulfillmentPlanDetails,
17
+ TimeWindow,
18
+ Identifier,
19
+ } from '..';
20
+
21
+ /** @description Basic structure for a label */
22
+ export class LabelDetails implements LabelRequest {
23
+ correlation_id!: string;
24
+ service_code?: string;
25
+ ship_datetime!: string;
26
+ confirmation?: ConfirmationTypes;
27
+ label_format?: DocumentFormat;
28
+ label_layout?: LabelLayouts;
29
+ /** @description Whether the request is for a test */
30
+ is_test_label?: boolean;
31
+ /** @description Any additional options a shipment may require, including custom options */
32
+ advanced_options?: AdvancedOptions;
33
+ insurance_provider?: InsuranceProviders;
34
+ /** @description Whether the shipment is a return */
35
+ is_return_label!: boolean;
36
+ packages!: Package[];
37
+ ship_to!: ShipTo;
38
+ ship_from!: ShipFrom;
39
+ pickup_location?: PudoLocation;
40
+ relay_points?: RelayPointDetails;
41
+ ship_from_display?: ShipFromDisplay;
42
+ /** @description Whether the shipment requires next day shipping */
43
+ next_day?: boolean;
44
+ /** @description Whether the shipment is international */
45
+ international?: boolean;
46
+ reference?: string;
47
+ return_details?: ReturnLabelDetails;
48
+ fulfillment_plan_details?: FulfillmentPlanDetails;
49
+ attachments?: Document[];
50
+ /** @description The carrier pickup window is the time designated when the carrier will pickup your package from the initial location */
51
+ carrier_pickup_window?: TimeWindow;
52
+ /** @description Unique identifier for the carrier rate */
53
+ carrier_rate_id?: string;
54
+ alternative_identifiers?: Identifier[];
55
+ }
@@ -0,0 +1,17 @@
1
+ import Joi from 'joi';
2
+ import { Identifier, IdentifierSchema } from '../identifier';
3
+
4
+ /** @description Basic structure for a label payment result */
5
+ export class LabelPaymentResult {
6
+ correlation_id!: string;
7
+ alternative_identifiers!: Identifier[];
8
+ error_messages?: string[];
9
+ warning_messages?: string[];
10
+ }
11
+
12
+ export const LabelPaymentResultSchema = Joi.object({
13
+ correlation_id: Joi.string().required(),
14
+ alternative_identifiers: Joi.array().required().items(IdentifierSchema),
15
+ error_messages: Joi.array().optional().items(Joi.string()),
16
+ warning_messages: Joi.array().optional().items(Joi.string()),
17
+ });
@@ -0,0 +1,53 @@
1
+ import {
2
+ AdvancedOptions,
3
+ ConfirmationTypes,
4
+ FulfillmentPlanDetails,
5
+ InsuranceProviders,
6
+ DocumentFormat,
7
+ LabelLayouts,
8
+ Package,
9
+ ReturnLabelDetails,
10
+ ShipFrom,
11
+ PudoLocation,
12
+ ShipFromDisplay,
13
+ ShipTo,
14
+ Document,
15
+ TimeWindow,
16
+ RelayPointDetails,
17
+ Identifier,
18
+ } from '..';
19
+
20
+ /** @description Basic structure for a request to create a label */
21
+ export interface LabelRequest {
22
+ service_code?: string;
23
+ ship_datetime: string;
24
+ confirmation?: ConfirmationTypes;
25
+ label_format?: DocumentFormat;
26
+ label_layout?: LabelLayouts;
27
+ /** @description Whether the request is for a test */
28
+ is_test_label?: boolean;
29
+ /** @description Any additional options a shipment may require, including custom options */
30
+ advanced_options?: AdvancedOptions;
31
+ insurance_provider?: InsuranceProviders;
32
+ /** @description Whether the shipment is a return */
33
+ is_return_label: boolean;
34
+ packages: Package[];
35
+ ship_to: ShipTo;
36
+ ship_from: ShipFrom;
37
+ pickup_location?: PudoLocation;
38
+ relay_points?: RelayPointDetails;
39
+ ship_from_display?: ShipFromDisplay;
40
+ /** @description Whether the shipment requires next day shipping */
41
+ next_day?: boolean;
42
+ /** @description Whether the shipment is international */
43
+ international?: boolean;
44
+ reference?: string;
45
+ return_details?: ReturnLabelDetails;
46
+ fulfillment_plan_details?: FulfillmentPlanDetails;
47
+ attachments?: Document[];
48
+ /** @description The carrier pickup window is the time designated when the carrier will pickup your package from the initial location */
49
+ carrier_pickup_window?: TimeWindow;
50
+ /** @description Unique identifier for the carrier rate */
51
+ carrier_rate_id?: string;
52
+ alternative_identifiers?: Identifier[];
53
+ }
@@ -1,4 +1,4 @@
1
- import { ShippedShipment } from '..';
1
+ import { ShippedShipment } from '../pickup/shipped-shipment';
2
2
 
3
3
  export class ManifestRequestShipment extends ShippedShipment {
4
4
  manifest_request_shipment_id!: string;
@@ -5,7 +5,7 @@ export class TimeWindow {
5
5
  /** @description The local time zone represented in IANA. See https://www.iana.org/time-zones.
6
6
  * Example: America/Chicago
7
7
  */
8
- time_zone_iana!: string;
8
+ time_zone_iana?: string;
9
9
  /** @description The start of the window when the pickup could be made relative to the time_zone_iana.
10
10
  * ISO 8601 format, with local offset
11
11
  * Example: 2021-08-20T14:38:36.859237-05:00
@@ -19,7 +19,7 @@ export class TimeWindow {
19
19
  }
20
20
 
21
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(),
22
+ time_zone_iana: Joi.string().optional().allow(null).empty(''),
23
+ start_window: Joi.string().optional().allow(null).empty('').isoDate(),
24
+ end_window: Joi.string().optional().allow(null).empty('').isoDate(),
25
25
  });
@@ -0,0 +1,7 @@
1
+ import { BaseRequest } from './base-request';
2
+ import { LabelDetails } from '../models';
3
+
4
+ /** @description Basic structure for a request to create one or more label payments */
5
+ export class CreateLabelPaymentRequest extends BaseRequest {
6
+ labels!: LabelDetails[];
7
+ }
@@ -15,10 +15,12 @@ import {
15
15
  Document,
16
16
  TimeWindow,
17
17
  RelayPointDetails,
18
+ LabelRequest,
19
+ Identifier,
18
20
  } from '../models';
19
21
 
20
22
  /** @description Basic structure for a request to create a label */
21
- export class CreateLabelRequest extends BaseRequest {
23
+ export class CreateLabelRequest extends BaseRequest implements LabelRequest {
22
24
  service_code?: string;
23
25
  ship_datetime!: string;
24
26
  confirmation?: ConfirmationTypes;
@@ -49,4 +51,5 @@ export class CreateLabelRequest extends BaseRequest {
49
51
  carrier_pickup_window?: TimeWindow;
50
52
  /** @description Unique identifier for the carrier rate */
51
53
  carrier_rate_id?: string;
54
+ alternative_identifiers?: Identifier[];
52
55
  }
@@ -1,5 +1,6 @@
1
1
  export * from './cancel-pickup-request';
2
2
  export * from './create-label-request';
3
+ export * from './create-label-payment-request';
3
4
  export * from './create-manifest-request';
4
5
  export * from './get-manifest-request';
5
6
  export * from './get-rates-request';
@@ -0,0 +1,14 @@
1
+ import Joi from 'joi';
2
+ import { BaseResponse, BaseResponseSchema } from './base-response';
3
+ import { LabelPaymentResult, LabelPaymentResultSchema } from '../models';
4
+
5
+ /** @description Basic structure for a response to create a label */
6
+ export class CreateLabelPaymentResponse extends BaseResponse {
7
+ transaction_id!: string;
8
+ results!: LabelPaymentResult[];
9
+ }
10
+
11
+ export const CreateLabelPaymentResponseSchema = BaseResponseSchema.keys({
12
+ transaction_id: Joi.string().required(),
13
+ results: Joi.array().required().items(LabelPaymentResultSchema),
14
+ });
@@ -1,5 +1,6 @@
1
1
  export * from './cancel-pickup-response';
2
2
  export * from './create-label-response';
3
+ export * from './create-label-payment-response';
3
4
  export * from './create-manifest-response';
4
5
  export * from './get-rates-response';
5
6
  export * from './register-response';