@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,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.post = void 0;
4
+ const post = (next) => (info, init) => next(info, {
5
+ ...init,
6
+ method: 'POST',
7
+ });
8
+ exports.post = post;
@@ -0,0 +1,4 @@
1
+ import { Middleware } from "./middleware.js";
2
+ type Values = string | [string, string][] | Record<string, string> | URLSearchParams;
3
+ export declare const values: (values: Values) => Middleware;
4
+ export {};
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.values = void 0;
4
+ const buildValues = (url, values) => {
5
+ url = new URL(url);
6
+ const params = new URLSearchParams(url.searchParams);
7
+ for (const [key, value] of new URLSearchParams(values)) {
8
+ params.set(key, value);
9
+ }
10
+ url.search = params.toString();
11
+ return url;
12
+ };
13
+ const values = (values) => (next) => (info, init) => next(buildValues(info, values), init);
14
+ exports.values = values;
@@ -0,0 +1,13 @@
1
+ import { CountryCode } from './country_code.js';
2
+ export type Address = {
3
+ id?: number;
4
+ city: string;
5
+ country_code: CountryCode;
6
+ post_code: string;
7
+ } & ({
8
+ line1: string;
9
+ line2?: string;
10
+ } | {
11
+ street: string;
12
+ building_number: string;
13
+ });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export type Carrier = 'inpost_locker' | 'inpost_letter' | 'inpost_courier';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export declare const enum CountryCode {
2
+ pl = "PL",
3
+ en = "EN"
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export declare const enum CurrencyCode {
2
+ PLN = "PLN"
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ export * from "./address.js";
2
+ export * from "./carrier.js";
3
+ export * from "./country_code.js";
4
+ export * from "./currency_code.js";
5
+ export * from "./money.js";
6
+ export * from "./offer.js";
7
+ export * from "./organization.js";
8
+ export * from "./parcel.js";
9
+ export * from "./person.js";
10
+ export * from "./shipment.js";
11
+ export * from "./service.js";
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./address.js"), exports);
18
+ __exportStar(require("./carrier.js"), exports);
19
+ __exportStar(require("./country_code.js"), exports);
20
+ __exportStar(require("./currency_code.js"), exports);
21
+ __exportStar(require("./money.js"), exports);
22
+ __exportStar(require("./offer.js"), exports);
23
+ __exportStar(require("./organization.js"), exports);
24
+ __exportStar(require("./parcel.js"), exports);
25
+ __exportStar(require("./person.js"), exports);
26
+ __exportStar(require("./shipment.js"), exports);
27
+ __exportStar(require("./service.js"), exports);
@@ -0,0 +1,5 @@
1
+ import { CurrencyCode } from './currency_code.js';
2
+ export interface Money {
3
+ amount: number;
4
+ currency: CurrencyCode;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export interface Offer {
2
+ id: number;
3
+ status: string;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,19 @@
1
+ import { Address } from './address.js';
2
+ import { Carrier } from './carrier.js';
3
+ import { Person } from './person.js';
4
+ import { Service } from './service.js';
5
+ export interface Organization {
6
+ address: Address;
7
+ bank_account_number?: string;
8
+ carriers: Carrier[];
9
+ contact_person?: Person;
10
+ created_at: string;
11
+ href: string;
12
+ id: number;
13
+ invoice_address?: Address;
14
+ name: string;
15
+ owner_id: number;
16
+ services: Service[];
17
+ tax_id: string;
18
+ updated_at: string;
19
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,69 @@
1
+ export type Parcel = {
2
+ id?: number;
3
+ identify_number?: string;
4
+ } & ({
5
+ template: 'small';
6
+ is_non_standard?: false;
7
+ dimensions?: {
8
+ length: 380;
9
+ width: 640;
10
+ height: 80;
11
+ unit: 'mm';
12
+ };
13
+ weight?: {
14
+ amount: 25;
15
+ unit: 'kg';
16
+ };
17
+ } | {
18
+ template: 'medium';
19
+ is_non_standard?: false;
20
+ dimensions?: {
21
+ length: 380;
22
+ width: 640;
23
+ height: 190;
24
+ unit: 'mm';
25
+ };
26
+ weight?: {
27
+ amount: 25;
28
+ unit: 'kg';
29
+ };
30
+ } | {
31
+ template: 'large';
32
+ is_non_standard?: false;
33
+ dimensions?: {
34
+ length: 380;
35
+ width: 640;
36
+ height: 410;
37
+ unit: 'mm';
38
+ };
39
+ weight?: {
40
+ amount: 25;
41
+ unit: 'kg';
42
+ };
43
+ } | {
44
+ template: 'xlarge';
45
+ is_non_standard?: false;
46
+ dimensions?: {
47
+ length: 500;
48
+ width: 800;
49
+ height: 500;
50
+ unit: 'mm';
51
+ };
52
+ weight?: {
53
+ amount: 25;
54
+ unit: 'kg';
55
+ };
56
+ } | {
57
+ is_non_standard?: boolean;
58
+ template?: null;
59
+ dimensions: {
60
+ length: number;
61
+ width: number;
62
+ height: number;
63
+ unit: string;
64
+ };
65
+ weight: {
66
+ amount: number;
67
+ unit: string;
68
+ };
69
+ });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import { Address } from './address.js';
2
+ export interface Person {
3
+ id?: number;
4
+ email?: string;
5
+ phone?: string;
6
+ first_name?: string;
7
+ last_name?: string;
8
+ company_name?: string;
9
+ address?: Address;
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export type Service = 'inpost_locker_allegro' | 'inpost_locker_pass_thru' | 'inpost_locker_standard' | 'inpost_letter_allegro' | 'inpost_courier_palette' | 'inpost_courier_allegro' | 'inpost_courier_standard' | 'inpost_courier_express_1000' | 'inpost_courier_express_1200' | 'inpost_courier_express_1700' | 'inpost_courier_c2c' | 'inpost_locker_standard_smart' | 'inpost_locker_allegro_smart' | 'inpost_locker_economy';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,32 @@
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
+ export interface Shipment {
8
+ id?: number;
9
+ receiver: Person;
10
+ sender?: Person;
11
+ parcels: Parcel[];
12
+ custom_attributes?: {
13
+ sending_method?: "parcel_locker" | "dispatch_order" | "branch" | "pop" | "any_point" | "courier_pok";
14
+ target_point?: string;
15
+ dropoff_point?: string;
16
+ dispatch_order_id?: string;
17
+ };
18
+ cod?: Money;
19
+ insurance?: Money;
20
+ reference?: string;
21
+ is_return?: boolean;
22
+ service: Service;
23
+ additional_services?: ("sms" | "email" | "saturday")[];
24
+ external_customer_id?: string;
25
+ only_choice_of_offer?: boolean;
26
+ mpk?: string;
27
+ comments?: string;
28
+ status?: "created" | "offer_selected";
29
+ offers?: Offer[];
30
+ selected_offer?: Offer;
31
+ transactions?: Transaction[];
32
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import { Address } from "../models/index.js";
2
+ export declare const isAddress: (v: unknown) => v is Address;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAddress = void 0;
4
+ const is_country_code_js_1 = require("./is_country_code.js");
5
+ const number_js_1 = require("./number.js");
6
+ const object_js_1 = require("./object.js");
7
+ const optional_js_1 = require("./optional.js");
8
+ const string_js_1 = require("./string.js");
9
+ const validateAddress = (v) => (0, number_js_1.isNumber)(v.id) &&
10
+ (0, optional_js_1.isOptional)(string_js_1.isString)(v.building_number) &&
11
+ (0, optional_js_1.isOptional)(string_js_1.isString)(v.street) &&
12
+ (0, optional_js_1.isOptional)(string_js_1.isString)(v.city) &&
13
+ (0, optional_js_1.isOptional)(string_js_1.isString)(v.line1) &&
14
+ (0, optional_js_1.isOptional)(string_js_1.isString)(v.line2) &&
15
+ (0, string_js_1.isString)(v.post_code) &&
16
+ (0, is_country_code_js_1.isCountryCode)(v.country_code);
17
+ const isAddress = (v) => (0, object_js_1.isObject)(v) && validateAddress(v);
18
+ exports.isAddress = isAddress;
@@ -0,0 +1 @@
1
+ export declare const isArray: <T>(fn: (v: unknown) => v is T) => (v: unknown) => v is T[];
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isArray = void 0;
4
+ const isArray = (fn) => (v) => Array.isArray(v) && v.filter(fn).length === v.length;
5
+ exports.isArray = isArray;
@@ -0,0 +1,2 @@
1
+ import { Carrier } from '../models/index.js';
2
+ export declare const isCarrier: (v: unknown) => v is Carrier;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCarrier = void 0;
4
+ const mustBeCarrier = (v) => {
5
+ switch (v) {
6
+ case 'inpost_locker':
7
+ case 'inpost_letter':
8
+ case 'inpost_courier':
9
+ return true;
10
+ }
11
+ };
12
+ const isCarrier = (v) => !!mustBeCarrier(v);
13
+ exports.isCarrier = isCarrier;
@@ -0,0 +1,2 @@
1
+ import { CountryCode } from '../models/index.js';
2
+ export declare const isCountryCode: (v: unknown) => v is CountryCode;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCountryCode = void 0;
4
+ // Small trick that will cause compile time error if any enum is missing
5
+ const mustBeCountryCode = (v) => {
6
+ switch (v) {
7
+ case "PL" /* CountryCode.pl */:
8
+ case "EN" /* CountryCode.en */:
9
+ return true;
10
+ }
11
+ };
12
+ const isCountryCode = (v) => !!mustBeCountryCode(v);
13
+ exports.isCountryCode = isCountryCode;
@@ -0,0 +1,2 @@
1
+ import { CurrencyCode } from '../models/index.js';
2
+ export declare const isCurrencyCode: (v: unknown) => v is CurrencyCode;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCurrencyCode = void 0;
4
+ // Small trick that will cause compile time error if any enum is missing
5
+ const mustBeCurrencyCode = (v) => {
6
+ switch (v) {
7
+ case "PLN" /* CurrencyCode.PLN */:
8
+ return true;
9
+ }
10
+ };
11
+ const isCurrencyCode = (v) => !!mustBeCurrencyCode(v);
12
+ exports.isCurrencyCode = isCurrencyCode;
@@ -0,0 +1,2 @@
1
+ import { Money } from '../models/index.js';
2
+ export declare const isMoney: (v: unknown) => v is Money;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isMoney = void 0;
4
+ const object_js_1 = require("./object.js");
5
+ const is_currency_code_js_1 = require("./is_currency_code.js");
6
+ const mustBeMoney = (v) => typeof v.amount === 'number' && (0, is_currency_code_js_1.isCurrencyCode)(v.currency);
7
+ const isMoney = (v) => (0, object_js_1.isObject)(v) && mustBeMoney(v);
8
+ exports.isMoney = isMoney;
@@ -0,0 +1,2 @@
1
+ import { Parcel } from '../models/index.js';
2
+ export declare const isParcel: (v: unknown) => v is Parcel;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isParcel = void 0;
4
+ const object_js_1 = require("./object.js");
5
+ const optional_js_1 = require("./optional.js");
6
+ const mustBeParcel = (v) => (0, optional_js_1.isOptional)((v) => v === 'small' || v === 'medium' || v === 'large' || v === 'xlarge')(v.template);
7
+ const isParcel = (v) => (0, object_js_1.isObject)(v) && mustBeParcel(v);
8
+ exports.isParcel = isParcel;
@@ -0,0 +1,2 @@
1
+ import { Shipment } from '../models/index.js';
2
+ export declare const isShipment: (v: unknown) => v is Shipment;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isShipment = void 0;
4
+ const object_js_1 = require("./object.js");
5
+ // TODO: finish validation of shipment
6
+ const isShipment = (v) => (0, object_js_1.isObject)(v);
7
+ exports.isShipment = isShipment;
@@ -0,0 +1 @@
1
+ export declare const isNumber: (v: unknown) => v is number;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNumber = void 0;
4
+ const isNumber = (v) => typeof v === 'number';
5
+ exports.isNumber = isNumber;
@@ -0,0 +1 @@
1
+ export declare const isObject: (v: unknown) => v is object;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isObject = void 0;
4
+ const isObject = (v) => !!v && typeof v === 'object';
5
+ exports.isObject = isObject;
@@ -0,0 +1 @@
1
+ export declare const isOptional: <T>(fn: (v: unknown) => v is T) => (v: unknown) => v is T;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isOptional = void 0;
4
+ const isOptional = (fn) => (v) => v === undefined || v === null || fn(v);
5
+ exports.isOptional = isOptional;
@@ -0,0 +1,2 @@
1
+ import { Organization } from '../models/index.js';
2
+ export declare const isOrganization: (v: unknown) => v is Organization;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isOrganization = void 0;
4
+ const number_js_1 = require("./number.js");
5
+ const object_js_1 = require("./object.js");
6
+ const optional_js_1 = require("./optional.js");
7
+ const array_js_1 = require("./array.js");
8
+ const string_js_1 = require("./string.js");
9
+ const carrier_js_1 = require("./carrier.js");
10
+ const services_js_1 = require("./services.js");
11
+ const person_js_1 = require("./person.js");
12
+ const address_js_1 = require("./address.js");
13
+ const validateOrganization = (v) => (0, number_js_1.isNumber)(v.id) &&
14
+ (0, address_js_1.isAddress)(v.address) &&
15
+ (0, optional_js_1.isOptional)(string_js_1.isString)(v.bank_account_number) &&
16
+ (0, array_js_1.isArray)(carrier_js_1.isCarrier)(v.carriers) &&
17
+ (0, optional_js_1.isOptional)(person_js_1.isPerson)(v.contact_person) &&
18
+ (0, string_js_1.isString)(v.created_at) &&
19
+ (0, string_js_1.isString)(v.href) &&
20
+ (0, number_js_1.isNumber)(v.id) &&
21
+ (0, optional_js_1.isOptional)(address_js_1.isAddress)(v.invoice_address) &&
22
+ (0, string_js_1.isString)(v.name) &&
23
+ (0, number_js_1.isNumber)(v.owner_id) &&
24
+ (0, array_js_1.isArray)(services_js_1.isService)(v.services) &&
25
+ (0, string_js_1.isString)(v.tax_id) &&
26
+ (0, string_js_1.isString)(v.updated_at);
27
+ const isOrganization = (v) => (0, object_js_1.isObject)(v) && validateOrganization(v);
28
+ exports.isOrganization = isOrganization;
@@ -0,0 +1,2 @@
1
+ import { Person } from '../models/index.js';
2
+ export declare const isPerson: (v: unknown) => v is Person;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPerson = void 0;
4
+ const address_js_1 = require("./address.js");
5
+ const number_js_1 = require("./number.js");
6
+ const object_js_1 = require("./object.js");
7
+ const optional_js_1 = require("./optional.js");
8
+ const string_js_1 = require("./string.js");
9
+ const validatePerson = (v) => (0, optional_js_1.isOptional)(number_js_1.isNumber)(v.id) &&
10
+ (0, optional_js_1.isOptional)(string_js_1.isString)(v.email) &&
11
+ (0, optional_js_1.isOptional)(string_js_1.isString)(v.first_name) &&
12
+ (0, optional_js_1.isOptional)(string_js_1.isString)(v.last_name) &&
13
+ (0, optional_js_1.isOptional)(string_js_1.isString)(v.phone) &&
14
+ (0, optional_js_1.isOptional)(string_js_1.isString)(v.company_name) &&
15
+ (0, optional_js_1.isOptional)(address_js_1.isAddress)(v.address);
16
+ const isPerson = (v) => (0, object_js_1.isObject)(v) && validatePerson(v);
17
+ exports.isPerson = isPerson;
@@ -0,0 +1,2 @@
1
+ import { Service } from '../models/index.js';
2
+ export declare const isService: (v: unknown) => v is Service;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isService = void 0;
4
+ const mustBeService = (v) => {
5
+ switch (v) {
6
+ case 'inpost_locker_allegro':
7
+ case 'inpost_locker_pass_thru':
8
+ case 'inpost_locker_standard':
9
+ case 'inpost_locker_economy':
10
+ case 'inpost_letter_allegro':
11
+ case 'inpost_courier_palette':
12
+ case 'inpost_courier_allegro':
13
+ case 'inpost_courier_standard':
14
+ case 'inpost_courier_express_1000':
15
+ case 'inpost_courier_express_1200':
16
+ case 'inpost_courier_express_1700':
17
+ case 'inpost_courier_c2c':
18
+ case 'inpost_locker_standard_smart':
19
+ case 'inpost_locker_allegro_smart':
20
+ return true;
21
+ }
22
+ };
23
+ const isService = (v) => !!mustBeService(v);
24
+ exports.isService = isService;
@@ -0,0 +1 @@
1
+ export declare const isString: (v: unknown) => v is string;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isString = void 0;
4
+ const isString = (v) => typeof v === 'string';
5
+ exports.isString = isString;
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@deenruv/inpost",
3
+ "version": "1.0.0",
4
+ "type": "commonjs",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ "./package.json": "./package.json",
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "author": "",
17
+ "license": "ISC",
18
+ "description": "",
19
+ "dependencies": {
20
+ "ts-patch": "^3.2.1",
21
+ "tsx": "^4.19.1"
22
+ },
23
+ "devDependencies": {
24
+ "rimraf": "^5.0.5"
25
+ },
26
+ "scripts": {
27
+ "build": "rimraf dist && tspc --build",
28
+ "test": "tsx --test ./src/index.test.ts"
29
+ }
30
+ }