@deenruv/inpost 1.0.0

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 (141) hide show
  1. package/LICENSE +23 -0
  2. package/dist/api/organizations/index.d.ts +18 -0
  3. package/dist/api/organizations/index.js +34 -0
  4. package/dist/api/organizations/shipments.d.ts +17 -0
  5. package/dist/api/organizations/shipments.js +33 -0
  6. package/dist/api/organizations.d.ts +18 -0
  7. package/dist/api/organizations.js +33 -0
  8. package/dist/api/shipments/index.d.ts +14 -0
  9. package/dist/api/shipments/index.js +26 -0
  10. package/dist/api/shipments.d.ts +19 -0
  11. package/dist/api/shipments.js +37 -0
  12. package/dist/error.d.ts +6 -0
  13. package/dist/error.js +14 -0
  14. package/dist/index.d.ts +16 -0
  15. package/dist/index.js +43 -0
  16. package/dist/index.test.d.ts +1 -0
  17. package/dist/index.test.js +99 -0
  18. package/dist/middleware/auth.d.ts +2 -0
  19. package/dist/middleware/auth.js +12 -0
  20. package/dist/middleware/endpoint.d.ts +2 -0
  21. package/dist/middleware/endpoint.js +10 -0
  22. package/dist/middleware/expect_200.d.ts +2 -0
  23. package/dist/middleware/expect_200.js +26 -0
  24. package/dist/middleware/get.d.ts +2 -0
  25. package/dist/middleware/get.js +8 -0
  26. package/dist/middleware/index.d.ts +9 -0
  27. package/dist/middleware/index.js +25 -0
  28. package/dist/middleware/json_request.d.ts +2 -0
  29. package/dist/middleware/json_request.js +14 -0
  30. package/dist/middleware/json_response.d.ts +5 -0
  31. package/dist/middleware/json_response.js +14 -0
  32. package/dist/middleware/middleware.d.ts +4 -0
  33. package/dist/middleware/middleware.js +2 -0
  34. package/dist/middleware/post.d.ts +2 -0
  35. package/dist/middleware/post.js +8 -0
  36. package/dist/middleware/values.d.ts +4 -0
  37. package/dist/middleware/values.js +14 -0
  38. package/dist/models/address.d.ts +13 -0
  39. package/dist/models/address.js +2 -0
  40. package/dist/models/carrier.d.ts +1 -0
  41. package/dist/models/carrier.js +2 -0
  42. package/dist/models/country_code.d.ts +4 -0
  43. package/dist/models/country_code.js +2 -0
  44. package/dist/models/currency_code.d.ts +3 -0
  45. package/dist/models/currency_code.js +2 -0
  46. package/dist/models/index.d.ts +11 -0
  47. package/dist/models/index.js +27 -0
  48. package/dist/models/money.d.ts +5 -0
  49. package/dist/models/money.js +2 -0
  50. package/dist/models/offer.d.ts +4 -0
  51. package/dist/models/offer.js +2 -0
  52. package/dist/models/organization.d.ts +19 -0
  53. package/dist/models/organization.js +2 -0
  54. package/dist/models/parcel.d.ts +69 -0
  55. package/dist/models/parcel.js +2 -0
  56. package/dist/models/person.d.ts +10 -0
  57. package/dist/models/person.js +2 -0
  58. package/dist/models/service.d.ts +1 -0
  59. package/dist/models/service.js +2 -0
  60. package/dist/models/shipment.d.ts +32 -0
  61. package/dist/models/shipment.js +2 -0
  62. package/dist/models/transaction.d.ts +7 -0
  63. package/dist/models/transaction.js +2 -0
  64. package/dist/validators/address.d.ts +2 -0
  65. package/dist/validators/address.js +18 -0
  66. package/dist/validators/array.d.ts +1 -0
  67. package/dist/validators/array.js +5 -0
  68. package/dist/validators/carrier.d.ts +2 -0
  69. package/dist/validators/carrier.js +13 -0
  70. package/dist/validators/is_country_code.d.ts +2 -0
  71. package/dist/validators/is_country_code.js +13 -0
  72. package/dist/validators/is_currency_code.d.ts +2 -0
  73. package/dist/validators/is_currency_code.js +12 -0
  74. package/dist/validators/is_money.d.ts +2 -0
  75. package/dist/validators/is_money.js +8 -0
  76. package/dist/validators/is_parcel.d.ts +2 -0
  77. package/dist/validators/is_parcel.js +8 -0
  78. package/dist/validators/is_shipment.d.ts +2 -0
  79. package/dist/validators/is_shipment.js +7 -0
  80. package/dist/validators/number.d.ts +1 -0
  81. package/dist/validators/number.js +5 -0
  82. package/dist/validators/object.d.ts +1 -0
  83. package/dist/validators/object.js +5 -0
  84. package/dist/validators/optional.d.ts +1 -0
  85. package/dist/validators/optional.js +5 -0
  86. package/dist/validators/organization.d.ts +2 -0
  87. package/dist/validators/organization.js +28 -0
  88. package/dist/validators/person.d.ts +2 -0
  89. package/dist/validators/person.js +17 -0
  90. package/dist/validators/services.d.ts +2 -0
  91. package/dist/validators/services.js +24 -0
  92. package/dist/validators/string.d.ts +1 -0
  93. package/dist/validators/string.js +5 -0
  94. package/package.json +30 -0
  95. package/src/api/organizations/index.ts +51 -0
  96. package/src/api/organizations/shipments.ts +53 -0
  97. package/src/api/organizations.ts +44 -0
  98. package/src/api/shipments/index.ts +44 -0
  99. package/src/api/shipments.ts +59 -0
  100. package/src/error.ts +10 -0
  101. package/src/index.test.ts +127 -0
  102. package/src/index.ts +33 -0
  103. package/src/middleware/auth.ts +12 -0
  104. package/src/middleware/endpoint.ts +12 -0
  105. package/src/middleware/expect_200.ts +28 -0
  106. package/src/middleware/get.ts +6 -0
  107. package/src/middleware/index.ts +9 -0
  108. package/src/middleware/json_request.ts +15 -0
  109. package/src/middleware/json_response.ts +18 -0
  110. package/src/middleware/middleware.ts +7 -0
  111. package/src/middleware/post.ts +7 -0
  112. package/src/middleware/values.ts +23 -0
  113. package/src/models/address.ts +16 -0
  114. package/src/models/carrier.ts +1 -0
  115. package/src/models/country_code.ts +4 -0
  116. package/src/models/currency_code.ts +3 -0
  117. package/src/models/index.ts +11 -0
  118. package/src/models/money.ts +5 -0
  119. package/src/models/offer.ts +4 -0
  120. package/src/models/organization.ts +19 -0
  121. package/src/models/parcel.ts +75 -0
  122. package/src/models/person.ts +11 -0
  123. package/src/models/service.ts +15 -0
  124. package/src/models/shipment.ts +39 -0
  125. package/src/models/transaction.ts +7 -0
  126. package/src/validators/address.ts +19 -0
  127. package/src/validators/array.ts +4 -0
  128. package/src/validators/carrier.ts +13 -0
  129. package/src/validators/is_country_code.ts +11 -0
  130. package/src/validators/is_currency_code.ts +10 -0
  131. package/src/validators/is_money.ts +8 -0
  132. package/src/validators/is_parcel.ts +11 -0
  133. package/src/validators/is_shipment.ts +5 -0
  134. package/src/validators/number.ts +1 -0
  135. package/src/validators/object.ts +2 -0
  136. package/src/validators/optional.ts +4 -0
  137. package/src/validators/organization.ts +29 -0
  138. package/src/validators/person.ts +18 -0
  139. package/src/validators/services.ts +24 -0
  140. package/src/validators/string.ts +1 -0
  141. package/tsconfig.json +13 -0
@@ -0,0 +1,75 @@
1
+ export type Parcel = {
2
+ id?: number;
3
+ identify_number?: string;
4
+ } & (
5
+ | {
6
+ template: 'small';
7
+ is_non_standard?: false;
8
+ dimensions?: {
9
+ length: 380;
10
+ width: 640;
11
+ height: 80;
12
+ unit: 'mm';
13
+ };
14
+ weight?: {
15
+ amount: 25;
16
+ unit: 'kg';
17
+ };
18
+ }
19
+ | {
20
+ template: 'medium';
21
+ is_non_standard?: false;
22
+ dimensions?: {
23
+ length: 380;
24
+ width: 640;
25
+ height: 190;
26
+ unit: 'mm';
27
+ };
28
+ weight?: {
29
+ amount: 25;
30
+ unit: 'kg';
31
+ };
32
+ }
33
+ | {
34
+ template: 'large';
35
+ is_non_standard?: false;
36
+ dimensions?: {
37
+ length: 380;
38
+ width: 640;
39
+ height: 410;
40
+ unit: 'mm';
41
+ };
42
+ weight?: {
43
+ amount: 25;
44
+ unit: 'kg';
45
+ };
46
+ }
47
+ | {
48
+ template: 'xlarge';
49
+ is_non_standard?: false;
50
+ dimensions?: {
51
+ length: 500;
52
+ width: 800;
53
+ height: 500;
54
+ unit: 'mm';
55
+ };
56
+ weight?: {
57
+ amount: 25;
58
+ unit: 'kg';
59
+ };
60
+ }
61
+ | {
62
+ is_non_standard?: boolean;
63
+ template?: null;
64
+ dimensions: {
65
+ length: number;
66
+ width: number;
67
+ height: number;
68
+ unit: string;
69
+ };
70
+ weight: {
71
+ amount: number;
72
+ unit: string;
73
+ };
74
+ }
75
+ );
@@ -0,0 +1,11 @@
1
+ import { Address } from './address.js';
2
+
3
+ export interface Person {
4
+ id?: number;
5
+ email?: string;
6
+ phone?: string;
7
+ first_name?: string;
8
+ last_name?: string;
9
+ company_name?: string;
10
+ address?: Address;
11
+ }
@@ -0,0 +1,15 @@
1
+ export type Service =
2
+ | 'inpost_locker_allegro'
3
+ | 'inpost_locker_pass_thru'
4
+ | 'inpost_locker_standard'
5
+ | 'inpost_letter_allegro'
6
+ | 'inpost_courier_palette'
7
+ | 'inpost_courier_allegro'
8
+ | 'inpost_courier_standard'
9
+ | 'inpost_courier_express_1000'
10
+ | 'inpost_courier_express_1200'
11
+ | 'inpost_courier_express_1700'
12
+ | 'inpost_courier_c2c'
13
+ | 'inpost_locker_standard_smart'
14
+ | 'inpost_locker_allegro_smart'
15
+ | 'inpost_locker_economy';
@@ -0,0 +1,39 @@
1
+ import { Person } from "./person.js";
2
+ import { Parcel } from "./parcel.js";
3
+ import { Money } from "./money.js";
4
+ import { Service } from "./service.js";
5
+ import { Offer } from "./offer.js";
6
+ import { Transaction } from "./transaction.js";
7
+
8
+ export interface Shipment {
9
+ id?: number;
10
+ receiver: Person;
11
+ sender?: Person;
12
+ parcels: Parcel[];
13
+ custom_attributes?: {
14
+ sending_method?:
15
+ | "parcel_locker"
16
+ | "dispatch_order"
17
+ | "branch"
18
+ | "pop"
19
+ | "any_point"
20
+ | "courier_pok";
21
+ target_point?: string;
22
+ dropoff_point?: string;
23
+ dispatch_order_id?: string;
24
+ };
25
+ cod?: Money;
26
+ insurance?: Money;
27
+ reference?: string;
28
+ is_return?: boolean;
29
+ service: Service;
30
+ additional_services?: ("sms" | "email" | "saturday")[];
31
+ external_customer_id?: string;
32
+ only_choice_of_offer?: boolean;
33
+ mpk?: string;
34
+ comments?: string;
35
+ status?: "created" | "offer_selected";
36
+ offers?: Offer[];
37
+ selected_offer?: Offer;
38
+ transactions?: Transaction[];
39
+ }
@@ -0,0 +1,7 @@
1
+ export type Transaction = {
2
+ id: number;
3
+ status: string;
4
+ offer_id: number;
5
+ created_at: string;
6
+ updated_at: string;
7
+ };
@@ -0,0 +1,19 @@
1
+ import { Address } from "../models/index.js";
2
+ import { isCountryCode } from "./is_country_code.js";
3
+ import { isNumber } from "./number.js";
4
+ import { isObject } from "./object.js";
5
+ import { isOptional } from "./optional.js";
6
+ import { isString } from "./string.js";
7
+
8
+ const validateAddress = (v: Address) =>
9
+ isNumber(v.id) &&
10
+ isOptional(isString)((v as { building_number: string }).building_number) &&
11
+ isOptional(isString)((v as { street: string }).street) &&
12
+ isOptional(isString)(v.city) &&
13
+ isOptional(isString)((v as { line1: string }).line1) &&
14
+ isOptional(isString)((v as { line2: string }).line2) &&
15
+ isString(v.post_code) &&
16
+ isCountryCode(v.country_code);
17
+
18
+ export const isAddress = (v: unknown): v is Address =>
19
+ isObject(v) && validateAddress(v as Address);
@@ -0,0 +1,4 @@
1
+ export const isArray =
2
+ <T>(fn: (v: unknown) => v is T) =>
3
+ (v: unknown): v is T[] =>
4
+ Array.isArray(v) && v.filter(fn).length === v.length;
@@ -0,0 +1,13 @@
1
+ import { Carrier } from '../models/index.js';
2
+
3
+ const mustBeCarrier = (v: Carrier): true => {
4
+ switch (v) {
5
+ case 'inpost_locker':
6
+ case 'inpost_letter':
7
+ case 'inpost_courier':
8
+ return true;
9
+ }
10
+ };
11
+
12
+ export const isCarrier = (v: unknown): v is Carrier =>
13
+ !!mustBeCarrier(v as Carrier);
@@ -0,0 +1,11 @@
1
+ import { CountryCode } from '../models/index.js';
2
+ // Small trick that will cause compile time error if any enum is missing
3
+ const mustBeCountryCode = (v: CountryCode) => {
4
+ switch (v) {
5
+ case CountryCode.pl:
6
+ case CountryCode.en:
7
+ return true;
8
+ }
9
+ };
10
+ export const isCountryCode = (v: unknown): v is CountryCode =>
11
+ !!mustBeCountryCode(v as CountryCode);
@@ -0,0 +1,10 @@
1
+ import { CurrencyCode } from '../models/index.js';
2
+ // Small trick that will cause compile time error if any enum is missing
3
+ const mustBeCurrencyCode = (v: CurrencyCode) => {
4
+ switch (v) {
5
+ case CurrencyCode.PLN:
6
+ return true;
7
+ }
8
+ };
9
+ export const isCurrencyCode = (v: unknown): v is CurrencyCode =>
10
+ !!mustBeCurrencyCode(v as CurrencyCode);
@@ -0,0 +1,8 @@
1
+ import { Money } from '../models/index.js';
2
+ import { isObject } from './object.js';
3
+ import { isCurrencyCode } from './is_currency_code.js';
4
+
5
+ const mustBeMoney = (v: Money) =>
6
+ typeof v.amount === 'number' && isCurrencyCode(v.currency);
7
+ export const isMoney = (v: unknown): v is Money =>
8
+ isObject(v) && mustBeMoney(v as Money);
@@ -0,0 +1,11 @@
1
+ import { Parcel } from '../models/index.js';
2
+ import { isObject } from './object.js';
3
+ import { isOptional } from './optional.js';
4
+
5
+ const mustBeParcel = (v: Parcel): v is Parcel =>
6
+ isOptional(
7
+ (v: unknown): v is Parcel['template'] =>
8
+ v === 'small' || v === 'medium' || v === 'large' || v === 'xlarge',
9
+ )(v.template);
10
+ export const isParcel = (v: unknown): v is Parcel =>
11
+ isObject(v) && mustBeParcel(v as Parcel);
@@ -0,0 +1,5 @@
1
+ import { Shipment } from '../models/index.js';
2
+ import { isObject } from './object.js';
3
+
4
+ // TODO: finish validation of shipment
5
+ export const isShipment = (v: unknown): v is Shipment => isObject(v);
@@ -0,0 +1 @@
1
+ export const isNumber = (v: unknown): v is number => typeof v === 'number';
@@ -0,0 +1,2 @@
1
+ export const isObject = (v: unknown): v is object =>
2
+ !!v && typeof v === 'object';
@@ -0,0 +1,4 @@
1
+ export const isOptional =
2
+ <T>(fn: (v: unknown) => v is T) =>
3
+ (v: unknown): v is T | undefined | null =>
4
+ v === undefined || v === null || fn(v);
@@ -0,0 +1,29 @@
1
+ import { isNumber } from './number.js';
2
+ import { isObject } from './object.js';
3
+ import { isOptional } from './optional.js';
4
+ import { isArray } from './array.js';
5
+ import { isString } from './string.js';
6
+ import { isCarrier } from './carrier.js';
7
+ import { isService } from './services.js';
8
+ import { isPerson } from './person.js';
9
+ import { isAddress } from './address.js';
10
+ import { Organization } from '../models/index.js';
11
+
12
+ const validateOrganization = (v: Organization) =>
13
+ isNumber(v.id) &&
14
+ isAddress(v.address) &&
15
+ isOptional(isString)(v.bank_account_number) &&
16
+ isArray(isCarrier)(v.carriers) &&
17
+ isOptional(isPerson)(v.contact_person) &&
18
+ isString(v.created_at) &&
19
+ isString(v.href) &&
20
+ isNumber(v.id) &&
21
+ isOptional(isAddress)(v.invoice_address) &&
22
+ isString(v.name) &&
23
+ isNumber(v.owner_id) &&
24
+ isArray(isService)(v.services) &&
25
+ isString(v.tax_id) &&
26
+ isString(v.updated_at);
27
+
28
+ export const isOrganization = (v: unknown): v is Organization =>
29
+ isObject(v) && validateOrganization(v as Organization);
@@ -0,0 +1,18 @@
1
+ import { Person } from '../models/index.js';
2
+ import { isAddress } from './address.js';
3
+ import { isNumber } from './number.js';
4
+ import { isObject } from './object.js';
5
+ import { isOptional } from './optional.js';
6
+ import { isString } from './string.js';
7
+
8
+ const validatePerson = (v: Person) =>
9
+ isOptional(isNumber)(v.id) &&
10
+ isOptional(isString)(v.email) &&
11
+ isOptional(isString)(v.first_name) &&
12
+ isOptional(isString)(v.last_name) &&
13
+ isOptional(isString)(v.phone) &&
14
+ isOptional(isString)(v.company_name) &&
15
+ isOptional(isAddress)(v.address);
16
+
17
+ export const isPerson = (v: unknown): v is Person =>
18
+ isObject(v) && validatePerson(v as Person);
@@ -0,0 +1,24 @@
1
+ import { Service } from '../models/index.js';
2
+
3
+ const mustBeService = (v: Service): true => {
4
+ switch (v) {
5
+ case 'inpost_locker_allegro':
6
+ case 'inpost_locker_pass_thru':
7
+ case 'inpost_locker_standard':
8
+ case 'inpost_locker_economy':
9
+ case 'inpost_letter_allegro':
10
+ case 'inpost_courier_palette':
11
+ case 'inpost_courier_allegro':
12
+ case 'inpost_courier_standard':
13
+ case 'inpost_courier_express_1000':
14
+ case 'inpost_courier_express_1200':
15
+ case 'inpost_courier_express_1700':
16
+ case 'inpost_courier_c2c':
17
+ case 'inpost_locker_standard_smart':
18
+ case 'inpost_locker_allegro_smart':
19
+ return true;
20
+ }
21
+ };
22
+
23
+ export const isService = (v: unknown): v is Service =>
24
+ !!mustBeService(v as Service);
@@ -0,0 +1 @@
1
+ export const isString = (v: unknown): v is string => typeof v === 'string';
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "esnext",
4
+ "moduleResolution": "nodenext",
5
+ "esModuleInterop": true,
6
+ "module": "nodenext",
7
+ "rootDir": "./src",
8
+ "outDir": "./dist",
9
+ "declaration": true,
10
+ "types": ["node"]
11
+ },
12
+ "include": ["src/**/*.cts", "src/**/*.mts", "src/**/*.ts"]
13
+ }