@shopickup/adapters-foxpost 0.0.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 (47) hide show
  1. package/README.md +48 -0
  2. package/dist/capabilities/index.d.ts +9 -0
  3. package/dist/capabilities/index.d.ts.map +1 -0
  4. package/dist/capabilities/index.js +8 -0
  5. package/dist/capabilities/label.d.ts +27 -0
  6. package/dist/capabilities/label.d.ts.map +1 -0
  7. package/dist/capabilities/label.js +370 -0
  8. package/dist/capabilities/parcels.d.ts +21 -0
  9. package/dist/capabilities/parcels.d.ts.map +1 -0
  10. package/dist/capabilities/parcels.js +233 -0
  11. package/dist/capabilities/pickup-points.d.ts +38 -0
  12. package/dist/capabilities/pickup-points.d.ts.map +1 -0
  13. package/dist/capabilities/pickup-points.js +225 -0
  14. package/dist/capabilities/track.d.ts +16 -0
  15. package/dist/capabilities/track.d.ts.map +1 -0
  16. package/dist/capabilities/track.js +99 -0
  17. package/dist/client/index.d.ts +17 -0
  18. package/dist/client/index.d.ts.map +1 -0
  19. package/dist/client/index.js +30 -0
  20. package/dist/errors.d.ts +34 -0
  21. package/dist/errors.d.ts.map +1 -0
  22. package/dist/errors.js +165 -0
  23. package/dist/index.d.ts +119 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +151 -0
  26. package/dist/mappers/index.d.ts +108 -0
  27. package/dist/mappers/index.d.ts.map +1 -0
  28. package/dist/mappers/index.js +270 -0
  29. package/dist/mappers/trackStatus.d.ts +58 -0
  30. package/dist/mappers/trackStatus.d.ts.map +1 -0
  31. package/dist/mappers/trackStatus.js +290 -0
  32. package/dist/types/generated.d.ts +177 -0
  33. package/dist/types/generated.d.ts.map +1 -0
  34. package/dist/types/generated.js +9 -0
  35. package/dist/types/index.d.ts +7 -0
  36. package/dist/types/index.d.ts.map +1 -0
  37. package/dist/types/index.js +6 -0
  38. package/dist/utils/httpUtils.d.ts +18 -0
  39. package/dist/utils/httpUtils.d.ts.map +1 -0
  40. package/dist/utils/httpUtils.js +33 -0
  41. package/dist/utils/resolveBaseUrl.d.ts +23 -0
  42. package/dist/utils/resolveBaseUrl.d.ts.map +1 -0
  43. package/dist/utils/resolveBaseUrl.js +19 -0
  44. package/dist/validation.d.ts +1723 -0
  45. package/dist/validation.d.ts.map +1 -0
  46. package/dist/validation.js +799 -0
  47. package/package.json +68 -0
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Generated types for Foxpost API
3
+ * This file was generated from hu-foxpost.openapi.yaml
4
+ *
5
+ * NOTE: This is a manual stub. In production, use openapi-typescript to generate
6
+ * these types automatically:
7
+ * npx openapi-typescript ../../carrier-docs/hu-foxpost/hu-foxpost.openapi.yaml --output ./src/types/generated.ts
8
+ */
9
+ /**
10
+ * Request to create a parcel
11
+ */
12
+ export interface CreateParcelRequest {
13
+ /** Name of recipient (required) */
14
+ recipientName: string;
15
+ /** Phone of recipient (required) */
16
+ recipientPhone: string;
17
+ /** Email of recipient (required) */
18
+ recipientEmail: string;
19
+ /** Size of the parcel: xs, s, m, l, xl */
20
+ size?: "xs" | "s" | "m" | "l" | "xl";
21
+ /** Country code (defaults to HU) */
22
+ recipientCountry?: string;
23
+ /** City of recipient (required for HD - home delivery) */
24
+ recipientCity?: string;
25
+ /** Postal code (required for HD) */
26
+ recipientZip?: string;
27
+ /** Street address (required for HD) */
28
+ recipientAddress?: string;
29
+ /** Cash on delivery amount */
30
+ cod?: number;
31
+ /** Delivery note for courier */
32
+ deliveryNote?: string;
33
+ /** Comment about parcel contents */
34
+ comment?: string;
35
+ /** Whether Foxpost will print the label */
36
+ label?: boolean;
37
+ /** Whether parcel is fragile */
38
+ fragile?: boolean;
39
+ /** Unique barcode (if customer provides one) */
40
+ uniqueBarcode?: string;
41
+ /** Reference code for tracking */
42
+ refCode?: string;
43
+ /** APM (automated parcel machine) ID for redirect */
44
+ destination?: string;
45
+ }
46
+ /**
47
+ * Field validation error
48
+ */
49
+ export interface FieldError {
50
+ /** Field name that has error */
51
+ field: string;
52
+ /** Validation error message */
53
+ message: string;
54
+ }
55
+ /**
56
+ * Response from parcel creation
57
+ */
58
+ export interface CreateResponse {
59
+ /** Whether all parcels were created successfully */
60
+ valid: boolean;
61
+ /** List of created parcels */
62
+ parcels: Package[];
63
+ }
64
+ /**
65
+ * Created parcel details
66
+ */
67
+ export interface Package {
68
+ /** Barcode assigned to this parcel */
69
+ barcode?: string;
70
+ /** Reference code */
71
+ refCode?: string;
72
+ /** Unique barcode if provided */
73
+ uniqueBarcode?: string;
74
+ /** Validation errors if any */
75
+ errors?: FieldError[];
76
+ }
77
+ /**
78
+ * Request to get batch tracking
79
+ */
80
+ export interface BatchTrackRequest {
81
+ barcodes: string[];
82
+ }
83
+ /**
84
+ * Tracking status response
85
+ */
86
+ export interface Statuses {
87
+ /** Barcode of the parcel */
88
+ barcode: string;
89
+ /** When parcel was created */
90
+ createdAt: string;
91
+ /** List of tracking events */
92
+ statuses: TrackDTO[];
93
+ }
94
+ /**
95
+ * Single tracking event
96
+ */
97
+ export interface TrackDTO {
98
+ /** Track event ID */
99
+ trackId?: number;
100
+ /** Status code */
101
+ status?: string;
102
+ /** Human-readable status name */
103
+ longName?: string;
104
+ /** When this status occurred */
105
+ statusDate?: string;
106
+ /** Location information */
107
+ location?: string;
108
+ }
109
+ /**
110
+ * Tracking response for single parcel (NEW /api/tracking/{barcode} endpoint)
111
+ * Based on Foxpost API v1 documentation section 6.3
112
+ */
113
+ export interface TrackingResponse {
114
+ /** Tracking number */
115
+ trackingNumber?: string;
116
+ /** The queried parcel's clFoxId */
117
+ clFox: string;
118
+ /** Expected delivery date (yyyy-mm-dd) */
119
+ estimatedDelivery: string | null;
120
+ /** Parcel type: "NORMAL", "RE", "XRE", "IRE", "C2B" */
121
+ parcelType: "NORMAL" | "RE" | "XRE" | "IRE" | "C2B";
122
+ /** Related (previous) parcel clFox for returns (RE, XRE, IRE only) */
123
+ relatedParcel: string | null;
124
+ /** Delivery type: "APM", "HD", "COLLECT" */
125
+ sendType: "APM" | "HD" | "COLLECT";
126
+ /** Array of tracking traces in reverse chronological order (latest first) */
127
+ traces: TraceDTO[];
128
+ }
129
+ /**
130
+ * Single tracking trace/event from the new tracking endpoint
131
+ */
132
+ export interface TraceDTO {
133
+ /** Long human-readable status name */
134
+ longName?: string;
135
+ /** Short status code/name */
136
+ shortName?: string;
137
+ /** Status code */
138
+ status?: string;
139
+ /** When this status occurred */
140
+ statusDate?: string;
141
+ /** Status station ID reference on foxpost.hu */
142
+ statusStatidionId?: string;
143
+ }
144
+ /**
145
+ * Tracking response for single parcel (LEGACY /tracking endpoint - keep for backwards compatibility)
146
+ */
147
+ export interface Tracking {
148
+ /** Barcode of the parcel */
149
+ barcode: string;
150
+ /** When parcel was created */
151
+ createdAt: string;
152
+ /** List of tracking events */
153
+ statuses: TrackDTO[];
154
+ }
155
+ /**
156
+ * Label information
157
+ */
158
+ export interface LabelInfo {
159
+ /** Barcode */
160
+ barcode: string;
161
+ /** Whether label can be generated */
162
+ canGenerate?: boolean;
163
+ /** PDF content if available */
164
+ pdf?: string;
165
+ }
166
+ /**
167
+ * API Error response
168
+ */
169
+ export interface ApiError {
170
+ /** Timestamp of error */
171
+ timestamp?: string;
172
+ /** Error code */
173
+ error?: string;
174
+ /** HTTP status */
175
+ status?: number;
176
+ }
177
+ //# sourceMappingURL=generated.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated.d.ts","sourceRoot":"","sources":["../../src/types/generated.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,mCAAmC;IACnC,aAAa,EAAE,MAAM,CAAC;IAEtB,oCAAoC;IACpC,cAAc,EAAE,MAAM,CAAC;IAEvB,oCAAoC;IACpC,cAAc,EAAE,MAAM,CAAC;IAEvB,0CAA0C;IAC1C,IAAI,CAAC,EAAE,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC;IAErC,oC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BAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,4BAA4B;IAC5B,OAAO,EAAE,MAAM,CAAC;IAEhB,8BAA8B;IAC9B,SAAS,EAAE,MAAM,CAAC;IAElB,8BAA8B;IAC9B,QAAQ,EAAE,QAAQ,EAAE,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,cAAc;IACd,OAAO,EAAE,MAAM,CAAC;IAEhB,qCAAqC;IACrC,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,+BAA+B;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,yBAAyB;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,iBAAiB;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,kBAAkB;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Generated types for Foxpost API
3
+ * This file was generated from hu-foxpost.openapi.yaml
4
+ *
5
+ * NOTE: This is a manual stub. In production, use openapi-typescript to generate
6
+ * these types automatically:
7
+ * npx openapi-typescript ../../carrier-docs/hu-foxpost/hu-foxpost.openapi.yaml --output ./src/types/generated.ts
8
+ */
9
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Generated types from OpenAPI will be placed here
3
+ * To regenerate: npm run codegen
4
+ */
5
+ export * from './generated.js';
6
+ export type { CreateParcelRequest, CreateResponse, TrackDTO, Tracking } from './generated.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,gBAAgB,CAAC;AAG/B,YAAY,EAAE,mBAAmB,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Generated types from OpenAPI will be placed here
3
+ * To regenerate: npm run codegen
4
+ */
5
+ // Export generated types
6
+ export * from './generated.js';
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Foxpost HTTP Client Utilities
3
+ * Thin utilities for building Foxpost API requests
4
+ */
5
+ import type { FoxpostCredentials } from '../validation.js';
6
+ /**
7
+ * Build standard Foxpost auth headers
8
+ * Requires both Basic auth (username:password) and API key
9
+ * Uses capitalized "Api-key" header (Foxpost recommended format)
10
+ */
11
+ export declare function buildFoxpostHeaders(credentials: FoxpostCredentials): Record<string, string>;
12
+ /**
13
+ * Build Foxpost headers for binary responses (e.g., PDF)
14
+ * Uses capitalized "Api-key" header (Foxpost recommended format)
15
+ * Sets Accept-Encoding to application/pdf so Foxpost returns JSON on errors
16
+ */
17
+ export declare function buildFoxpostBinaryHeaders(credentials: FoxpostCredentials): Record<string, string>;
18
+ //# sourceMappingURL=httpUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpUtils.d.ts","sourceRoot":"","sources":["../../src/utils/httpUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAU3F;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAWjG"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Foxpost HTTP Client Utilities
3
+ * Thin utilities for building Foxpost API requests
4
+ */
5
+ /**
6
+ * Build standard Foxpost auth headers
7
+ * Requires both Basic auth (username:password) and API key
8
+ * Uses capitalized "Api-key" header (Foxpost recommended format)
9
+ */
10
+ export function buildFoxpostHeaders(credentials) {
11
+ const { apiKey, basicUsername, basicPassword } = credentials;
12
+ const basicAuth = Buffer.from(`${basicUsername}:${basicPassword}`).toString("base64");
13
+ return {
14
+ "Content-Type": "application/json",
15
+ "Authorization": `Basic ${basicAuth}`,
16
+ ...(apiKey && { "Api-key": apiKey }),
17
+ };
18
+ }
19
+ /**
20
+ * Build Foxpost headers for binary responses (e.g., PDF)
21
+ * Uses capitalized "Api-key" header (Foxpost recommended format)
22
+ * Sets Accept-Encoding to application/pdf so Foxpost returns JSON on errors
23
+ */
24
+ export function buildFoxpostBinaryHeaders(credentials) {
25
+ const { apiKey, basicUsername, basicPassword } = credentials;
26
+ const basicAuth = Buffer.from(`${basicUsername}:${basicPassword}`).toString("base64");
27
+ return {
28
+ "Accept-Encoding": "application/pdf",
29
+ "Content-Type": "application/json",
30
+ "Authorization": `Basic ${basicAuth}`,
31
+ ...(apiKey && { "Api-key": apiKey }),
32
+ };
33
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Factory that creates a resolver function bound to production and test base URLs.
3
+ *
4
+ * This removes duplication of base URL strings across capability files while keeping
5
+ * per-call decision logic explicit and testable.
6
+ *
7
+ * Usage:
8
+ * const resolveBaseUrl = createResolveBaseUrl(prodUrl, testUrl);
9
+ * const url = resolveBaseUrl(req.options); // returns test or prod based on useTestApi flag
10
+ *
11
+ * @param prodBaseUrl Production API base URL
12
+ * @param testBaseUrl Test/sandbox API base URL
13
+ * @returns A pure resolver function that accepts request options and returns the appropriate URL
14
+ */
15
+ export declare function createResolveBaseUrl(prodBaseUrl: string, testBaseUrl: string): (opts?: {
16
+ useTestApi?: boolean;
17
+ }) => string;
18
+ /**
19
+ * Type definition for the resolver function returned by createResolveBaseUrl.
20
+ * Useful for typing capability function parameters.
21
+ */
22
+ export type ResolveBaseUrl = ReturnType<typeof createResolveBaseUrl>;
23
+ //# sourceMappingURL=resolveBaseUrl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveBaseUrl.d.ts","sourceRoot":"","sources":["../../src/utils/resolveBaseUrl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,IACnE,OAAO;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,KAAG,MAAM,CAGjD;AAED;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Factory that creates a resolver function bound to production and test base URLs.
3
+ *
4
+ * This removes duplication of base URL strings across capability files while keeping
5
+ * per-call decision logic explicit and testable.
6
+ *
7
+ * Usage:
8
+ * const resolveBaseUrl = createResolveBaseUrl(prodUrl, testUrl);
9
+ * const url = resolveBaseUrl(req.options); // returns test or prod based on useTestApi flag
10
+ *
11
+ * @param prodBaseUrl Production API base URL
12
+ * @param testBaseUrl Test/sandbox API base URL
13
+ * @returns A pure resolver function that accepts request options and returns the appropriate URL
14
+ */
15
+ export function createResolveBaseUrl(prodBaseUrl, testBaseUrl) {
16
+ return (opts) => {
17
+ return opts?.useTestApi ? testBaseUrl : prodBaseUrl;
18
+ };
19
+ }