@shipengine/connect-carrier-api 2.12.20 → 4.0.0-beta.2

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 (254) hide show
  1. package/lib/app/build-app-deployment.d.ts +3 -0
  2. package/lib/app/build-app-deployment.js +41 -0
  3. package/lib/app/build-app-deployment.js.map +1 -0
  4. package/lib/app/carrier-app-definition.d.ts +7 -0
  5. package/lib/app/create-endpoint-mapping.d.ts +4 -0
  6. package/lib/app/create-endpoint-mapping.js +26 -0
  7. package/lib/app/create-endpoint-mapping.js.map +1 -0
  8. package/lib/app/index.d.ts +4 -2
  9. package/lib/app/index.js +4 -2
  10. package/lib/app/index.js.map +1 -1
  11. package/lib/app/metadata/index.d.ts +2 -0
  12. package/lib/app/metadata/index.js +2 -0
  13. package/lib/app/metadata/index.js.map +1 -1
  14. package/lib/app/{native-rating/data-validator.d.ts → native-rating-data-validator.d.ts} +1 -1
  15. package/lib/app/{native-rating/data-validator.js → native-rating-data-validator.js} +1 -1
  16. package/lib/app/native-rating-data-validator.js.map +1 -0
  17. package/lib/models/addresses/address-base-schema.d.ts +2 -0
  18. package/lib/models/addresses/address-base-schema.js +24 -0
  19. package/lib/models/addresses/address-base-schema.js.map +1 -0
  20. package/lib/models/addresses/address-residential-indicator-schema.d.ts +2 -0
  21. package/lib/models/addresses/address-residential-indicator-schema.js +8 -0
  22. package/lib/models/addresses/address-residential-indicator-schema.js.map +1 -0
  23. package/lib/models/addresses/pudo-location-schema.d.ts +2 -0
  24. package/lib/models/addresses/pudo-location-schema.js +11 -0
  25. package/lib/models/addresses/pudo-location-schema.js.map +1 -0
  26. package/lib/models/addresses/ship-to-schema.d.ts +2 -0
  27. package/lib/models/addresses/ship-to-schema.js +11 -0
  28. package/lib/models/addresses/ship-to-schema.js.map +1 -0
  29. package/lib/models/advanced-options-schema.d.ts +2 -0
  30. package/lib/models/advanced-options-schema.js +15 -0
  31. package/lib/models/advanced-options-schema.js.map +1 -0
  32. package/lib/models/advanced-options.d.ts +0 -5
  33. package/lib/models/advanced-options.js.map +1 -1
  34. package/lib/models/authorization-schema.d.ts +2 -0
  35. package/lib/models/authorization-schema.js +10 -0
  36. package/lib/models/authorization-schema.js.map +1 -0
  37. package/lib/models/billing/index.d.ts +0 -1
  38. package/lib/models/billing/index.js +0 -1
  39. package/lib/models/billing/index.js.map +1 -1
  40. package/lib/models/customs/customs-charges-schema.d.ts +2 -0
  41. package/lib/models/customs/customs-charges-schema.js +13 -0
  42. package/lib/models/customs/customs-charges-schema.js.map +1 -0
  43. package/lib/models/customs/customs-content-types-schema.d.ts +2 -0
  44. package/lib/models/customs/customs-content-types-schema.js +8 -0
  45. package/lib/models/customs/customs-content-types-schema.js.map +1 -0
  46. package/lib/models/customs/customs-item-schema.d.ts +2 -0
  47. package/lib/models/customs/customs-item-schema.js +21 -0
  48. package/lib/models/customs/customs-item-schema.js.map +1 -0
  49. package/lib/models/customs/customs-non-delivery-schema.d.ts +2 -0
  50. package/lib/models/customs/customs-non-delivery-schema.js +8 -0
  51. package/lib/models/customs/customs-non-delivery-schema.js.map +1 -0
  52. package/lib/models/customs/customs-schema.d.ts +2 -0
  53. package/lib/models/customs/customs-schema.js +25 -0
  54. package/lib/models/customs/customs-schema.js.map +1 -0
  55. package/lib/models/customs/customs.d.ts +2 -2
  56. package/lib/models/importer-records/importer-of-record-schema.d.ts +2 -0
  57. package/lib/models/importer-records/importer-of-record-schema.js +20 -0
  58. package/lib/models/importer-records/importer-of-record-schema.js.map +1 -0
  59. package/lib/models/importer-records/{importer_of_record.js → importer-of-record.js} +1 -1
  60. package/lib/models/importer-records/importer-of-record.js.map +1 -0
  61. package/lib/models/inconterms/terms-of-trade-code-schema.d.ts +2 -0
  62. package/lib/models/inconterms/terms-of-trade-code-schema.js +8 -0
  63. package/lib/models/inconterms/terms-of-trade-code-schema.js.map +1 -0
  64. package/lib/models/index.d.ts +0 -3
  65. package/lib/models/index.js +0 -3
  66. package/lib/models/index.js.map +1 -1
  67. package/lib/models/labels/label-message-schema.d.ts +2 -0
  68. package/lib/models/labels/label-message-schema.js +11 -0
  69. package/lib/models/labels/label-message-schema.js.map +1 -0
  70. package/lib/models/pickup/shipped-package-schema.d.ts +2 -0
  71. package/lib/models/pickup/shipped-package-schema.js +25 -0
  72. package/lib/models/pickup/shipped-package-schema.js.map +1 -0
  73. package/lib/models/pickup/shipped-shipment-schema.d.ts +3 -0
  74. package/lib/models/pickup/shipped-shipment-schema.js +21 -0
  75. package/lib/models/pickup/shipped-shipment-schema.js.map +1 -0
  76. package/lib/models/taxes/tax-identifier-schema.d.ts +2 -0
  77. package/lib/models/taxes/tax-identifier-schema.js +13 -0
  78. package/lib/models/taxes/tax-identifier-schema.js.map +1 -0
  79. package/lib/models/taxes/tax-identifier-type-schema.d.ts +2 -0
  80. package/lib/models/taxes/tax-identifier-type-schema.js +8 -0
  81. package/lib/models/taxes/tax-identifier-type-schema.js.map +1 -0
  82. package/lib/models/taxes/tax-identifier.d.ts +1 -3
  83. package/lib/models/taxes/tax-identifier.js.map +1 -1
  84. package/lib/models/units/dimension-details-schema.d.ts +2 -0
  85. package/lib/models/units/dimension-details-schema.js +14 -0
  86. package/lib/models/units/dimension-details-schema.js.map +1 -0
  87. package/lib/models/units/dimension-unit-schema.d.ts +2 -0
  88. package/lib/models/units/dimension-unit-schema.js +8 -0
  89. package/lib/models/units/dimension-unit-schema.js.map +1 -0
  90. package/lib/models/units/weight-details-schema.d.ts +2 -0
  91. package/lib/models/units/weight-details-schema.js +13 -0
  92. package/lib/models/units/weight-details-schema.js.map +1 -0
  93. package/lib/models/units/weight-unit-schema.d.ts +2 -0
  94. package/lib/models/units/weight-unit-schema.js +8 -0
  95. package/lib/models/units/weight-unit-schema.js.map +1 -0
  96. package/lib/requests/base-request-schema.d.ts +2 -0
  97. package/lib/requests/base-request-schema.js +12 -0
  98. package/lib/requests/base-request-schema.js.map +1 -0
  99. package/lib/requests/cancel-notification-request-schema.d.ts +2 -0
  100. package/lib/requests/cancel-notification-request-schema.js +12 -0
  101. package/lib/requests/cancel-notification-request-schema.js.map +1 -0
  102. package/lib/requests/create-label-request.d.ts +1 -3
  103. package/lib/requests/create-label-request.js.map +1 -1
  104. package/lib/requests/get-rates-request.d.ts +1 -3
  105. package/lib/requests/get-rates-request.js.map +1 -1
  106. package/package.json +4 -4
  107. package/spec.json +1 -49
  108. package/src/app/build-app-deployment.ts +50 -0
  109. package/src/app/carrier-app-definition.ts +10 -0
  110. package/src/app/create-endpoint-mapping.ts +25 -0
  111. package/src/app/index.ts +4 -2
  112. package/src/app/metadata/index.ts +2 -0
  113. package/src/app/{native-rating/data-validator.ts → native-rating-data-validator.ts} +1 -1
  114. package/src/models/addresses/address-base-schema.ts +20 -0
  115. package/src/models/addresses/address-residential-indicator-schema.ts +6 -0
  116. package/src/models/addresses/pudo-location-schema.ts +7 -0
  117. package/src/models/addresses/ship-to-schema.ts +7 -0
  118. package/src/models/advanced-options-schema.ts +11 -0
  119. package/src/models/advanced-options.ts +0 -5
  120. package/src/models/authorization-schema.ts +6 -0
  121. package/src/models/billing/index.ts +0 -1
  122. package/src/models/customs/customs-charges-schema.ts +9 -0
  123. package/src/models/customs/customs-content-types-schema.ts +4 -0
  124. package/src/models/customs/customs-item-schema.ts +17 -0
  125. package/src/models/customs/customs-non-delivery-schema.ts +4 -0
  126. package/src/models/customs/customs-schema.ts +21 -0
  127. package/src/models/customs/customs.ts +2 -2
  128. package/src/models/importer-records/importer-of-record-schema.ts +16 -0
  129. package/src/models/inconterms/terms-of-trade-code-schema.ts +4 -0
  130. package/src/models/index.ts +0 -3
  131. package/src/models/labels/label-message-schema.ts +7 -0
  132. package/src/models/pickup/shipped-package-schema.ts +21 -0
  133. package/src/models/pickup/shipped-shipment-schema.ts +18 -0
  134. package/src/models/taxes/tax-identifier-schema.ts +9 -0
  135. package/src/models/taxes/tax-identifier-type-schema.ts +4 -0
  136. package/src/models/taxes/tax-identifier.ts +1 -3
  137. package/src/models/units/dimension-details-schema.ts +10 -0
  138. package/src/models/units/dimension-unit-schema.ts +4 -0
  139. package/src/models/units/weight-details-schema.ts +9 -0
  140. package/src/models/units/weight-unit-schema.ts +4 -0
  141. package/src/requests/base-request-schema.ts +8 -0
  142. package/src/requests/cancel-notification-request-schema.ts +8 -0
  143. package/src/requests/create-label-request.ts +0 -3
  144. package/src/requests/get-rates-request.ts +0 -3
  145. package/tsconfig.tsbuildinfo +1 -1
  146. package/lib/app/build-native-rating-routes.d.ts +0 -3
  147. package/lib/app/build-native-rating-routes.js +0 -105
  148. package/lib/app/build-native-rating-routes.js.map +0 -1
  149. package/lib/app/carrier-app.d.ts +0 -15
  150. package/lib/app/carrier-app.js +0 -166
  151. package/lib/app/carrier-app.js.map +0 -1
  152. package/lib/app/create-get-rates-handler.d.ts +0 -4
  153. package/lib/app/create-get-rates-handler.js +0 -100
  154. package/lib/app/create-get-rates-handler.js.map +0 -1
  155. package/lib/app/internal/branded-image.d.ts +0 -9
  156. package/lib/app/internal/branded-image.js +0 -3
  157. package/lib/app/internal/branded-image.js.map +0 -1
  158. package/lib/app/internal/carrier-app-specification.d.ts +0 -16
  159. package/lib/app/internal/carrier-app-specification.js +0 -3
  160. package/lib/app/internal/carrier-app-specification.js.map +0 -1
  161. package/lib/app/internal/carrier-specification.d.ts +0 -38
  162. package/lib/app/internal/carrier-specification.js +0 -86
  163. package/lib/app/internal/carrier-specification.js.map +0 -1
  164. package/lib/app/internal/connect-runtime-app.d.ts +0 -14
  165. package/lib/app/internal/connect-runtime-app.js +0 -3
  166. package/lib/app/internal/connect-runtime-app.js.map +0 -1
  167. package/lib/app/internal/document-template.d.ts +0 -7
  168. package/lib/app/internal/document-template.js +0 -3
  169. package/lib/app/internal/document-template.js.map +0 -1
  170. package/lib/app/internal/index.d.ts +0 -3
  171. package/lib/app/internal/index.js +0 -7
  172. package/lib/app/internal/index.js.map +0 -1
  173. package/lib/app/internal/metadata.d.ts +0 -13
  174. package/lib/app/internal/metadata.js +0 -64
  175. package/lib/app/internal/metadata.js.map +0 -1
  176. package/lib/app/internal/native-rating-specification.d.ts +0 -5
  177. package/lib/app/internal/native-rating-specification.js +0 -3
  178. package/lib/app/internal/native-rating-specification.js.map +0 -1
  179. package/lib/app/internal/route.d.ts +0 -27
  180. package/lib/app/internal/route.js +0 -12
  181. package/lib/app/internal/route.js.map +0 -1
  182. package/lib/app/native-rating/base-rate-context.d.ts +0 -3
  183. package/lib/app/native-rating/base-rate-context.js +0 -83
  184. package/lib/app/native-rating/base-rate-context.js.map +0 -1
  185. package/lib/app/native-rating/context-results.d.ts +0 -3
  186. package/lib/app/native-rating/context-results.js +0 -3
  187. package/lib/app/native-rating/context-results.js.map +0 -1
  188. package/lib/app/native-rating/create-dynamic-carrier.d.ts +0 -7
  189. package/lib/app/native-rating/create-dynamic-carrier.js +0 -63
  190. package/lib/app/native-rating/create-dynamic-carrier.js.map +0 -1
  191. package/lib/app/native-rating/data-validator.js.map +0 -1
  192. package/lib/app/native-rating/get-rates.d.ts +0 -7
  193. package/lib/app/native-rating/get-rates.js +0 -3
  194. package/lib/app/native-rating/get-rates.js.map +0 -1
  195. package/lib/app/native-rating/get-variables.d.ts +0 -6
  196. package/lib/app/native-rating/get-variables.js +0 -3
  197. package/lib/app/native-rating/get-variables.js.map +0 -1
  198. package/lib/app/native-rating/get-zone.d.ts +0 -6
  199. package/lib/app/native-rating/get-zone.js +0 -3
  200. package/lib/app/native-rating/get-zone.js.map +0 -1
  201. package/lib/app/native-rating/implementation-type.d.ts +0 -31
  202. package/lib/app/native-rating/implementation-type.js +0 -8
  203. package/lib/app/native-rating/implementation-type.js.map +0 -1
  204. package/lib/app/native-rating/index.d.ts +0 -3
  205. package/lib/app/native-rating/index.js +0 -7
  206. package/lib/app/native-rating/index.js.map +0 -1
  207. package/lib/app/native-rating/numeric-currency.d.ts +0 -5
  208. package/lib/app/native-rating/numeric-currency.js +0 -3
  209. package/lib/app/native-rating/numeric-currency.js.map +0 -1
  210. package/lib/app/native-rating/rating-context.d.ts +0 -15
  211. package/lib/app/native-rating/rating-context.js +0 -3
  212. package/lib/app/native-rating/rating-context.js.map +0 -1
  213. package/lib/models/bill-to.d.ts +0 -14
  214. package/lib/models/bill-to.js +0 -14
  215. package/lib/models/bill-to.js.map +0 -1
  216. package/lib/models/billing/billing-to-party.d.ts +0 -10
  217. package/lib/models/billing/billing-to-party.js +0 -15
  218. package/lib/models/billing/billing-to-party.js.map +0 -1
  219. package/lib/models/cod-payment-type.d.ts +0 -9
  220. package/lib/models/cod-payment-type.js +0 -14
  221. package/lib/models/cod-payment-type.js.map +0 -1
  222. package/lib/models/collect-on-delivery.d.ts +0 -9
  223. package/lib/models/collect-on-delivery.js +0 -8
  224. package/lib/models/collect-on-delivery.js.map +0 -1
  225. package/lib/models/importer-records/importer_of_record.js.map +0 -1
  226. package/src/app/build-native-rating-routes.ts +0 -119
  227. package/src/app/carrier-app.ts +0 -222
  228. package/src/app/create-get-rates-handler.ts +0 -128
  229. package/src/app/internal/README.md +0 -1
  230. package/src/app/internal/branded-image.ts +0 -9
  231. package/src/app/internal/carrier-app-specification.ts +0 -17
  232. package/src/app/internal/carrier-specification.ts +0 -135
  233. package/src/app/internal/connect-runtime-app.ts +0 -15
  234. package/src/app/internal/document-template.ts +0 -7
  235. package/src/app/internal/index.ts +0 -3
  236. package/src/app/internal/metadata.ts +0 -86
  237. package/src/app/internal/native-rating-specification.ts +0 -5
  238. package/src/app/internal/route.ts +0 -31
  239. package/src/app/native-rating/base-rate-context.ts +0 -101
  240. package/src/app/native-rating/context-results.ts +0 -3
  241. package/src/app/native-rating/create-dynamic-carrier.ts +0 -82
  242. package/src/app/native-rating/get-rates.ts +0 -9
  243. package/src/app/native-rating/get-variables.ts +0 -8
  244. package/src/app/native-rating/get-zone.ts +0 -9
  245. package/src/app/native-rating/implementation-type.ts +0 -34
  246. package/src/app/native-rating/index.ts +0 -3
  247. package/src/app/native-rating/numeric-currency.ts +0 -5
  248. package/src/app/native-rating/rating-context.ts +0 -19
  249. package/src/models/bill-to.ts +0 -15
  250. package/src/models/billing/billing-to-party.ts +0 -10
  251. package/src/models/cod-payment-type.ts +0 -9
  252. package/src/models/collect-on-delivery.ts +0 -10
  253. /package/lib/models/importer-records/{importer_of_record.d.ts → importer-of-record.d.ts} +0 -0
  254. /package/src/models/importer-records/{importer_of_record.ts → importer-of-record.ts} +0 -0
@@ -1,9 +0,0 @@
1
- import { CodPaymentType } from './cod-payment-type';
2
- import { Currency } from './currency';
3
- /** @description This model represents the option to defer payment for a shipment, otherwise known as Collect on Delivery (COD) */
4
- export declare class CollectOnDelivery {
5
- /** @description The payment amount for Collect on Delivery (COD) */
6
- payment_amount: Currency;
7
- /** @description The payment method permitted for Collect on Delivery (COD) */
8
- payment_type?: CodPaymentType;
9
- }
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CollectOnDelivery = void 0;
4
- /** @description This model represents the option to defer payment for a shipment, otherwise known as Collect on Delivery (COD) */
5
- class CollectOnDelivery {
6
- }
7
- exports.CollectOnDelivery = CollectOnDelivery;
8
- //# sourceMappingURL=collect-on-delivery.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"collect-on-delivery.js","sourceRoot":"","sources":["../../src/models/collect-on-delivery.ts"],"names":[],"mappings":";;;AAGA,kIAAkI;AAClI,MAAa,iBAAiB;CAK7B;AALD,8CAKC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"importer_of_record.js","sourceRoot":"","sources":["../../../src/models/importer-records/importer_of_record.ts"],"names":[],"mappings":";;;AAEA,0DAA0D;AAC1D,MAAa,gBAAgB;CAuB5B;AAvBD,4CAuBC"}
@@ -1,119 +0,0 @@
1
- import { resolve } from 'path';
2
- import { readFile, stat } from 'fs/promises';
3
- import { Request } from 'express';
4
- import { Method, Route } from './internal/route';
5
- import { CarrierAppMetadata } from './metadata/carrier-app-metadata';
6
- import { rateLogicName } from './create-get-rates-handler';
7
- import { RateCard } from './metadata/rate-card';
8
-
9
- const buildFilePath = async (path: string, fileName: string, error: string) => {
10
- const filePath = resolve(path, fileName);
11
-
12
- try {
13
- await stat(filePath);
14
- return filePath;
15
- } catch {
16
- throw new Error(error);
17
- }
18
- };
19
-
20
- export const buildNativeRatingRoutes = (metadata: CarrierAppMetadata): Route[] => {
21
- const getCarrierDetails = async (
22
- req: Request,
23
- ): Promise<{ path: string; rateCards: RateCard[] }> => {
24
- const carrierId = req.params.carrier_id;
25
- const carrier = metadata.Carriers.find((x) => x.Id === carrierId);
26
- if (!carrier) {
27
- throw new Error(`Could not find carrier with id ${carrierId}`);
28
- }
29
-
30
- if (!carrier.NativeRating) {
31
- throw new Error(`Carrier ${carrierId} does not have a NativeRating property`);
32
- }
33
-
34
- if (!carrier.NativeRating.Path) {
35
- throw new Error(`Carrier ${carrierId} does not have NativeRating path set`);
36
- }
37
-
38
- try {
39
- await stat(carrier.NativeRating.Path);
40
- } catch {
41
- throw new Error(`Carrier ${carrierId} does not have NativeRating data`);
42
- }
43
-
44
- return {
45
- path: carrier.NativeRating.Path,
46
- rateCards: carrier.NativeRating.RateCards || [],
47
- };
48
- };
49
-
50
- const getRateCardPath = async (req: Request): Promise<string> => {
51
- const rateCardId = req.params.id;
52
- const { path, rateCards } = await getCarrierDetails(req);
53
-
54
- if (!rateCards.find((x) => x.Id === rateCardId)) {
55
- throw new Error(`Could not find a rate card with id ${rateCardId}`);
56
- }
57
-
58
- const rateCardPath = resolve(path, rateCardId);
59
-
60
- try {
61
- await stat(rateCardPath);
62
- } catch {
63
- throw new Error(`Rate card does not have any data`);
64
- }
65
-
66
- return rateCardPath;
67
- };
68
-
69
- return [
70
- {
71
- path: '/NativeRating/:carrier_id/RateCards',
72
- method: Method.GET,
73
- handler: async (req: Request) => {
74
- const { rateCards } = await getCarrierDetails(req);
75
- return rateCards.map((x) => ({ Id: x.Id, Currency: x.Currency }));
76
- },
77
- },
78
- {
79
- path: '/NativeRating/:carrier_id/RateCards/:id/Implementation',
80
- method: Method.GET,
81
- handler: async (req: any) => {
82
- const path = await getRateCardPath(req);
83
- const codePath = await buildFilePath(path, rateLogicName, `Could not find rating logic`);
84
- const code = (await readFile(codePath)).toString('base64');
85
- return { code };
86
- },
87
- },
88
- ...['Rates', 'Variables'].map((x) => ({
89
- path: `/NativeRating/:carrier_id/RateCards/:id/${x}`,
90
- method: Method.GET,
91
- file: async (req: any) => {
92
- const path = await getRateCardPath(req);
93
- return await buildFilePath(
94
- path,
95
- `${x.toLowerCase()}.json`,
96
- `Could not find ${x.toLowerCase()}`,
97
- );
98
- },
99
- })),
100
- {
101
- path: '/NativeRating/:carrier_id/Implementation',
102
- method: Method.GET,
103
- handler: async (req: any) => {
104
- const { path } = await getCarrierDetails(req);
105
- const codePath = await buildFilePath(path, rateLogicName, `Could not find rating logic`);
106
- const code = (await readFile(codePath)).toString('base64');
107
- return { code };
108
- },
109
- },
110
- {
111
- path: '/NativeRating/:carrier_id/Zones',
112
- method: Method.GET,
113
- file: async (req: any) => {
114
- const { path } = await getCarrierDetails(req);
115
- return await buildFilePath(path, 'zones.json', `Could not find zones`);
116
- },
117
- },
118
- ];
119
- };
@@ -1,222 +0,0 @@
1
- import { CarrierAppDefinition } from '.';
2
- import { ConnectRuntimeApp, Method, Route, BrandedImages } from './internal';
3
- import { ApiEndpoints } from './constants';
4
- import { OpenApiSpecification } from '../spec';
5
-
6
- import { Metadata } from './internal/metadata';
7
- import { CarrierSpecification } from './internal/carrier-specification';
8
- import { CarrierAppMetadataSchema } from './metadata';
9
- import { ImportedTrackingEventSchema } from '../models';
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
- GetRelayPointsResponseSchema,
24
- GetServicePointsResponseSchema,
25
- GetServicePointResponseSchema,
26
- } from '../responses';
27
- import { Schema } from 'joi';
28
- import { DocumentTemplate } from './internal/document-template';
29
- import fs, { existsSync } from 'fs';
30
- import { createGetRatesHandler } from './create-get-rates-handler';
31
- import { buildNativeRatingRoutes } from './build-native-rating-routes';
32
- import { isDataValidationError, validateRatingData } from './native-rating/data-validator';
33
-
34
- const handleRequest = (implementation?: Function): any => {
35
- if (implementation) {
36
- return async (request: any) => {
37
- const { transaction_id } = request.body;
38
- const result = await implementation(request.body);
39
- result.transaction_id = transaction_id;
40
- return result;
41
- };
42
- }
43
- };
44
-
45
- export class CarrierApp implements ConnectRuntimeApp {
46
- routes: Route[] = [];
47
- data: Metadata;
48
- redoc?: string;
49
- validate: () => string[] | undefined;
50
- getSupportedCountries: () => string[] | undefined;
51
- constructor(definition: CarrierAppDefinition) {
52
- this.getSupportedCountries = () => {
53
- const countries: (string | undefined)[] = [];
54
- const rootCountries = definition.Metadata.Carriers.flatMap((c) =>
55
- c.DefaultSupportedCountries?.flatMap((sc) => sc.FromCountry),
56
- );
57
- const serviceCountries = definition.Metadata.Carriers.flatMap((c) =>
58
- c.ShippingServices?.flatMap((s) => s.SupportedCountries).flatMap((sc) => sc?.FromCountry),
59
- );
60
- countries.push(...rootCountries);
61
- countries.push(...serviceCountries);
62
- const uniqueCountries = [...new Set(countries)].filter((c) => c !== undefined) as string[];
63
- return uniqueCountries;
64
- };
65
- this.validate = () => {
66
- const results = CarrierAppMetadataSchema.validate(definition.Metadata, {
67
- allowUnknown: true,
68
- abortEarly: false,
69
- });
70
- if (results.error) {
71
- return results.error.details.map((detail) => `${detail.message}`);
72
- }
73
-
74
- const nativeRatingCarriers = definition.Metadata.Carriers.filter(
75
- (carrier) =>
76
- carrier.NativeRating &&
77
- carrier.NativeRating.Path &&
78
- existsSync(carrier.NativeRating.Path),
79
- );
80
-
81
- const validationErrors = nativeRatingCarriers
82
- .map(validateRatingData)
83
- .filter(isDataValidationError)
84
- .flat();
85
- if (validationErrors.length > 0) {
86
- return validationErrors.map(
87
- (error) => `${error.message} \n Duplicate Keys: ${error.duplicateKeys?.join(', ')}`,
88
- );
89
- }
90
- };
91
-
92
- const ratingImplementation = createGetRatesHandler(definition);
93
-
94
- new Array<[Method, ApiEndpoints, any, Schema]>(
95
- [
96
- Method.POST,
97
- ApiEndpoints.CancelNotification,
98
- definition.CancelNotification,
99
- CancelNotificationResponseSchema,
100
- ],
101
- [Method.POST, ApiEndpoints.CancelPickup, definition.CancelPickup, CancelPickupResponseSchema],
102
- [Method.POST, ApiEndpoints.CreateLabel, definition.CreateLabel, CreateLabelResponseSchema],
103
- [
104
- Method.POST,
105
- ApiEndpoints.CreateManifest,
106
- definition.CreateManifest,
107
- CreateManifestResponseSchema,
108
- ],
109
- [Method.POST, ApiEndpoints.GetManifest, definition.GetManifest, CreateManifestResponseSchema],
110
- [
111
- Method.POST,
112
- ApiEndpoints.CreateNotification,
113
- definition.CreateNotification,
114
- CreateNotificationResponseSchema,
115
- ],
116
- [Method.POST, ApiEndpoints.GetRates, ratingImplementation, GetRatesResponseSchema],
117
- [
118
- Method.POST,
119
- ApiEndpoints.NormalizeTrackingData,
120
- definition.NormalizeTrackingData,
121
- NormalizeTrackingDataResponseSchema,
122
- ],
123
- [Method.POST, ApiEndpoints.Register, definition.Register, RegisterResponseSchema],
124
- [
125
- Method.POST,
126
- ApiEndpoints.SchedulePickup,
127
- definition.SchedulePickup,
128
- SchedulePickupResponseSchema,
129
- ],
130
- [Method.POST, ApiEndpoints.Track, definition.Track, TrackingResponseSchema],
131
- [
132
- Method.POST,
133
- ApiEndpoints.ValidateInboundData,
134
- definition.ValidateInboundData,
135
- ValidateInboundDataResponseSchema,
136
- ],
137
- [Method.POST, ApiEndpoints.VoidLabels, definition.VoidLabels, VoidLabelsResponseSchema],
138
- [
139
- Method.POST,
140
- ApiEndpoints.GetRelayPoints,
141
- definition.GetRelayPoints,
142
- GetRelayPointsResponseSchema,
143
- ],
144
- [
145
- Method.POST,
146
- ApiEndpoints.GetServicePoints,
147
- definition.GetServicePoints,
148
- GetServicePointsResponseSchema,
149
- ],
150
- [
151
- Method.POST,
152
- ApiEndpoints.GetServicePoint,
153
- definition.GetServicePoint,
154
- GetServicePointResponseSchema,
155
- ],
156
- [
157
- Method.POST,
158
- ApiEndpoints.ImportTrackingEvents,
159
- definition.ImportTrackingEvents,
160
- ImportedTrackingEventSchema,
161
- ],
162
- ).forEach(([method, path, implementation, schema]) => {
163
- if (implementation) {
164
- this.routes.push({
165
- method,
166
- path,
167
- handler: handleRequest(implementation as Function),
168
- validateResponse: (result: any): string[] | undefined => {
169
- const validationResults = schema.validate(result, {
170
- abortEarly: false,
171
- });
172
- const errors = validationResults?.error?.details?.map((detail) => detail.message);
173
- return errors;
174
- },
175
- });
176
- }
177
- });
178
- this.routes.push({
179
- path: '/DocumentTemplates/:id',
180
- method: Method.GET,
181
- handler: async (request: any) => {
182
- return await this.getDocumentTemplate(request);
183
- },
184
- });
185
-
186
- buildNativeRatingRoutes(definition.Metadata).forEach((x) => this.routes.push(x));
187
-
188
- this.data = new Metadata(definition);
189
- this.redoc = JSON.stringify(OpenApiSpecification);
190
- }
191
-
192
- getImages(): BrandedImages[] {
193
- const mapBrandedImages = (carrier: CarrierSpecification): BrandedImages => {
194
- return {
195
- id: carrier.Id,
196
- logo: carrier.Images.LogoUrl,
197
- icon: carrier.Images.IconUrl,
198
- };
199
- };
200
- return this.data.Carriers.map(mapBrandedImages);
201
- }
202
-
203
- getDocumentTemplatesListFromMetadata(): DocumentTemplate[] {
204
- const mapDocumentTemplates = (carrier: CarrierSpecification): DocumentTemplate => {
205
- return {
206
- id: carrier.Id,
207
- template: carrier.DocumentTemplate,
208
- };
209
- };
210
- return this.data.Carriers.map(mapDocumentTemplates);
211
- }
212
-
213
- getDocumentTemplate = async (req: any): Promise<JSON> => {
214
- const templates = this.getDocumentTemplatesListFromMetadata();
215
- const file = templates.find((file: any) => file.id === req.params.id);
216
- if (file && file.template) {
217
- const templateContent = await fs.promises.readFile(file.template);
218
- return JSON.parse(templateContent.toString());
219
- }
220
- return JSON.parse('{}');
221
- };
222
- }
@@ -1,128 +0,0 @@
1
- import { join } from 'path';
2
- import { existsSync, readFileSync } from 'fs';
3
- import { GetRatesRequest } from '../requests';
4
- import { CarrierAppDefinition } from './carrier-app-definition';
5
- import { Carrier } from './metadata/carrier';
6
- import { createContextBuilder } from './native-rating/base-rate-context';
7
- import createDynamicCarrier from './native-rating/create-dynamic-carrier';
8
- import { RateResultsAndId, RatingCarrier } from './native-rating/implementation-type';
9
-
10
- export const rateLogicName = 'rate-shipments.js';
11
-
12
- const runNativeRatingLocally = process.env.LOCAL_NATIVE_RATING
13
- ? process.env.LOCAL_NATIVE_RATING !== 'false'
14
- : process.env.NODE_ENV !== 'production';
15
-
16
- const createImplementation = (basePath: string): RatingCarrier | undefined => {
17
- const logicPath = join(basePath, rateLogicName);
18
-
19
- if (!existsSync(logicPath)) {
20
- return undefined;
21
- }
22
-
23
- const rawImplementation = readFileSync(logicPath, 'utf8');
24
- return createDynamicCarrier(rawImplementation);
25
- };
26
-
27
- const createNativeRatingHandler = (carrier: Carrier) => {
28
- if (!carrier.NativeRating) {
29
- console.log('Carrier does NOT have a Native Rating property in its config');
30
- return undefined;
31
- }
32
-
33
- const basePath = carrier.NativeRating.Path;
34
- if (!basePath) {
35
- console.log('Carrier does NOT have a Native Rating path set');
36
- return undefined;
37
- }
38
-
39
- if (!existsSync(basePath)) {
40
- console.log(`Path for Native Rating '${basePath}' does not exist`);
41
- return undefined;
42
- }
43
-
44
- try {
45
- const buildContext = createContextBuilder(basePath);
46
- const defaultImplementation = createImplementation(basePath);
47
- const rateCards = Object.fromEntries(
48
- carrier.NativeRating.RateCards?.map((card) => {
49
- const impl = createImplementation(join(basePath, card.Id)) || defaultImplementation;
50
- if (!impl) {
51
- throw new Error(
52
- `Cannot find default nor card specific rating logic for rate card ${card.Id}`,
53
- );
54
- }
55
-
56
- const context = buildContext(card);
57
- const rateShipments = (req: GetRatesRequest): Promise<RateResultsAndId[]> =>
58
- impl.rateShipments(context, [{ id: 'rate-request', shipment: req }]);
59
-
60
- return [card.Id, rateShipments];
61
- }) || [],
62
- );
63
-
64
- const defaultRateCard = rateCards[carrier.NativeRating.DefaultRateCardId];
65
- if (!defaultRateCard) {
66
- throw new Error(
67
- `Could not find a rate card definition for default rate card ${carrier.NativeRating.DefaultRateCardId}`,
68
- );
69
- }
70
-
71
- return async (req: GetRatesRequest) => {
72
- const rateCardId = req.metadata?.['native-rating-rate-card'];
73
- const rateShipments = rateCardId ? rateCards[rateCardId] : defaultRateCard;
74
-
75
- if (!rateShipments) {
76
- throw new Error(`Could not find rate card ${rateCardId}`);
77
- }
78
-
79
- const results = await rateShipments(req);
80
- const rateResult = results.find((x) => x.id === 'rate-request');
81
- if (!rateResult) {
82
- throw new Error(
83
- `Could not find rate for request 'rate-request'. Ensure you return the request id with your rates.`,
84
- );
85
- }
86
-
87
- return {
88
- rates: rateResult.rates,
89
- metadata: {
90
- error: rateResult.error,
91
- },
92
- };
93
- };
94
- } catch (err: any) {
95
- console.warn(err?.message);
96
- return undefined;
97
- }
98
- };
99
-
100
- export const createGetRatesHandler = (definition: CarrierAppDefinition) => {
101
- if (!runNativeRatingLocally) {
102
- return definition.GetRates;
103
- }
104
-
105
- const nativeRatingCarriers = definition.Metadata.Carriers.map((x) => ({
106
- apiCode: x.ApiCode || x.Name,
107
- handler: createNativeRatingHandler(x) || definition.GetRates,
108
- })).filter((x) => x.handler !== undefined);
109
-
110
- // If there aren't any native rating implementations found, return whatever is defined in the definition
111
- // This is what should happen in production because the Kong gateway should route any rate requests for NR
112
- // carriers directly to the Native Rating service
113
- if (nativeRatingCarriers.length === 0) {
114
- return definition.GetRates;
115
- }
116
-
117
- // If there's only a single carrier defined, just return the Native Rating handler so that we can avoid
118
- // requiring the "carrier_code" property be set on the "metadata" object when testing
119
- if (definition.Metadata.Carriers.length === 1) {
120
- return nativeRatingCarriers[0].handler;
121
- }
122
-
123
- const implementationLookup = Object.fromEntries(
124
- nativeRatingCarriers.map((x) => [x.apiCode, x.handler]),
125
- );
126
-
127
- return (req: GetRatesRequest) => implementationLookup[req.metadata?.['carrier_code']]?.(req);
128
- };
@@ -1 +0,0 @@
1
- This directory is used for classes & interfaces that should never be exposed to the integrations implementors.
@@ -1,9 +0,0 @@
1
- /** @description This contains the logo and icon for an individual branded entity */
2
- export interface BrandedImages {
3
- /** @description The id associated with the branded item (typically the carrier id, or ordersource id) */
4
- id: string;
5
- /** @description The full path to the logo file */
6
- logo: string;
7
- /** @description The full path to the icon file */
8
- icon: string;
9
- }
@@ -1,17 +0,0 @@
1
- import { AuthSpecification } from '../metadata/auth-specification';
2
- import { ShippingProviderConnector } from '../metadata/shipping-provider-connector';
3
- import { CarrierSpecification } from './carrier-specification';
4
-
5
- /** @description This represents a single integration which may contain multiple carrier sources */
6
- export interface CarrierAppSpecification {
7
- /** @description The id for this integration */
8
- Id: string;
9
- /** @description The name of this integration */
10
- Name: string;
11
- /** @description Information about the connector */
12
- Connector: ShippingProviderConnector;
13
- /** @description The specification for authorizing with this carrier */
14
- AuthProcess?: AuthSpecification;
15
- /** @description A list of carrier sources associated with this integration */
16
- Carriers: CarrierSpecification[];
17
- }
@@ -1,135 +0,0 @@
1
- import { Carrier } from '../metadata/carrier';
2
- import { AccountModals } from '../metadata/account-modals';
3
- import { PackageType } from '../metadata/package-type';
4
- import { ShippingService } from '../metadata/shipping-service';
5
- import {
6
- ShippingOption,
7
- ShippingOptionDescription,
8
- ShippingOptionDictionary,
9
- ShippingOptionEnum,
10
- } from '../metadata/shipping-option';
11
- import { CountryAssociation } from '../metadata/country-association';
12
- import {
13
- ConfirmationDictionary,
14
- ConfirmationType,
15
- ConfirmationTypeEnum,
16
- } from '../metadata/confirmation-type';
17
- import { LabelFormatsEnum } from '../metadata/label-formats';
18
- import { LabelSizesEnum } from '../metadata/label-sizes';
19
- import { CarrierAttributeEnum } from '../metadata/carrier-attributes';
20
- import { NativeRatingSpecification } from './native-rating-specification';
21
- import { NativeRatingConfiguration } from '../metadata/native-rating-configuration';
22
-
23
- export const mapShippingOptions = (
24
- options?: ShippingOptionDictionary,
25
- ): ShippingOption[] | undefined => {
26
- if (!options) {
27
- return undefined;
28
- }
29
- const ret: ShippingOption[] = [];
30
- Object.keys(options).forEach((key: string) => {
31
- const Type = key as ShippingOptionEnum;
32
- const { Name, Description } = options[Type] as ShippingOptionDescription;
33
- ret.push({
34
- Name,
35
- Description,
36
- Type,
37
- });
38
- });
39
- return ret;
40
- };
41
-
42
- export const mapConfirmationTypes = (types?: ConfirmationDictionary): ConfirmationType[] => {
43
- if (!types) {
44
- return [];
45
- }
46
- const ret: ConfirmationType[] = [];
47
- Object.keys(types).forEach((key: any) => {
48
- const confirmations = types as ConfirmationDictionary;
49
- const Type = key as ConfirmationTypeEnum;
50
- const Name = confirmations[Type] as string;
51
- ret.push({
52
- Name,
53
- Type,
54
- });
55
- });
56
- return ret;
57
- };
58
-
59
- const mapAccountModal = (modal: AccountModals): AccountModals => {
60
- return {
61
- RegistrationFormSchema: {
62
- JsonSchema:
63
- modal.RegistrationFormSchema.JsonSchema ??
64
- modal.RegistrationFormSchema.formSchema?.jsonSchema,
65
- UiSchema:
66
- modal.RegistrationFormSchema.UiSchema ?? modal.RegistrationFormSchema.formSchema?.uiSchema,
67
- },
68
- SettingsFormSchema: {
69
- JsonSchema:
70
- modal.SettingsFormSchema.JsonSchema ?? modal.SettingsFormSchema.formSchema?.jsonSchema,
71
- UiSchema: modal.SettingsFormSchema.UiSchema ?? modal.SettingsFormSchema.formSchema?.uiSchema,
72
- },
73
- };
74
- };
75
-
76
- const mapNativeRating = (
77
- model?: NativeRatingConfiguration,
78
- ): NativeRatingSpecification | undefined => {
79
- if (!model) {
80
- return undefined;
81
- }
82
-
83
- return {
84
- DefaultRateCard: model.DefaultRateCardId,
85
- };
86
- };
87
-
88
- /** @description This represents what we send to data manager */
89
- export class CarrierSpecification {
90
- Id: string;
91
- Name: string;
92
- ApiCode?: string;
93
- AccountModals: AccountModals;
94
- PackageTypes?: PackageType[];
95
- ShippingServices?: ShippingService[];
96
- ShippingOptions?: ShippingOption[];
97
- DefaultSupportedCountries?: CountryAssociation[];
98
- DefaultLabelSizes?: LabelSizesEnum[];
99
- LabelFormats?: LabelFormatsEnum[];
100
- DefaultConfirmationTypes: ConfirmationType[];
101
- CarrierAttributes?: CarrierAttributeEnum[];
102
- TrackingUrl?: string;
103
- CarrierUrl?: string;
104
- Description?: string;
105
- Images: {
106
- LogoUrl: string;
107
- IconUrl: string;
108
- };
109
- NativeRating?: NativeRatingSpecification;
110
- DocumentTemplate?: string;
111
-
112
- constructor(definition: Carrier) {
113
- this.Images = {
114
- LogoUrl: definition.Images.Logo,
115
- IconUrl: definition.Images.Icon,
116
- };
117
- this.Id = definition.Id;
118
- this.Name = definition.Name;
119
- this.ApiCode = definition.ApiCode;
120
- this.AccountModals = mapAccountModal(definition.AccountModals);
121
- this.PackageTypes = definition.PackageTypes;
122
- this.ShippingServices = definition.ShippingServices;
123
- this.ShippingOptions = mapShippingOptions(definition.ShippingOptions);
124
- this.DefaultSupportedCountries = definition.DefaultSupportedCountries;
125
- this.DefaultLabelSizes = definition.DefaultLabelSizes;
126
- this.LabelFormats = definition.LabelFormats;
127
- this.DefaultConfirmationTypes = mapConfirmationTypes(definition.DefaultConfirmationTypes);
128
- this.CarrierAttributes = definition.CarrierAttributes;
129
- this.TrackingUrl = definition.TrackingUrl;
130
- this.CarrierUrl = definition.CarrierUrl;
131
- this.Description = definition.Description;
132
- this.NativeRating = mapNativeRating(definition.NativeRating);
133
- this.DocumentTemplate = definition.DocumentTemplate;
134
- }
135
- }
@@ -1,15 +0,0 @@
1
- import { BrandedImages, Route } from '.';
2
-
3
- /** @description This exposes the base needs for an app to be succeful in the generic connect runtime */
4
- export interface ConnectRuntimeApp {
5
- /** @description The routes your application should expose */
6
- routes: Route[];
7
- /** @description The metadata associated with your application */
8
- data: any;
9
- /** @description A method that returns an array of images associated with branded entities within your app */
10
- getImages: () => BrandedImages[];
11
- /** @description A method that validates the metadata for an app and returns an array of errors if they exist */
12
- validate: () => string[] | undefined;
13
- /** @description String containing yaml or json file to display with redoc */
14
- redoc?: string;
15
- }
@@ -1,7 +0,0 @@
1
- /** @description Contains template file with carrier documents and labels */
2
- export interface DocumentTemplate {
3
- /** @description The id associated with the template - the carrier id */
4
- id: string;
5
- /** @description The full path to the template file */
6
- template?: string;
7
- }