medusa-inpost-fulfillment 0.1.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.
- package/.medusa/server/lib/client.d.ts +24 -0
- package/.medusa/server/lib/client.d.ts.map +1 -0
- package/.medusa/server/lib/client.js +90 -0
- package/.medusa/server/lib/client.js.map +1 -0
- package/.medusa/server/lib/types.d.ts +77 -0
- package/.medusa/server/lib/types.d.ts.map +1 -0
- package/.medusa/server/lib/types.js +9 -0
- package/.medusa/server/lib/types.js.map +1 -0
- package/.medusa/server/providers/inpost/index.d.ts +3 -0
- package/.medusa/server/providers/inpost/index.d.ts.map +1 -0
- package/.medusa/server/providers/inpost/index.js +11 -0
- package/.medusa/server/providers/inpost/index.js.map +1 -0
- package/.medusa/server/providers/inpost/service.d.ts +32 -0
- package/.medusa/server/providers/inpost/service.d.ts.map +1 -0
- package/.medusa/server/providers/inpost/service.js +289 -0
- package/.medusa/server/providers/inpost/service.js.map +1 -0
- package/.medusa/server/src/admin/index.js +22 -0
- package/.medusa/server/src/admin/index.mjs +23 -0
- package/README.md +177 -0
- package/package.json +47 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { InPostPluginOptions, InPostShipmentRequest, InPostShipmentResponse } from "./types";
|
|
2
|
+
export declare class InPostShipXClient {
|
|
3
|
+
private apiToken;
|
|
4
|
+
private baseUrl;
|
|
5
|
+
private organizationId;
|
|
6
|
+
constructor(options: InPostPluginOptions);
|
|
7
|
+
private request;
|
|
8
|
+
createShipment(data: InPostShipmentRequest): Promise<InPostShipmentResponse>;
|
|
9
|
+
buyShipment(id: number, offerId: number): Promise<InPostShipmentResponse>;
|
|
10
|
+
getShipment(id: number): Promise<InPostShipmentResponse>;
|
|
11
|
+
cancelShipment(id: number): Promise<void>;
|
|
12
|
+
getLabel(id: number, format?: "pdf" | "zpl"): Promise<Buffer>;
|
|
13
|
+
createDispatchOrder(shipmentIds: number[], address: {
|
|
14
|
+
street: string;
|
|
15
|
+
building_number: string;
|
|
16
|
+
city: string;
|
|
17
|
+
post_code: string;
|
|
18
|
+
country_code?: string;
|
|
19
|
+
}, comment?: string): Promise<{
|
|
20
|
+
id: number;
|
|
21
|
+
status: string;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/lib/client.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAKjB,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,cAAc,CAAS;gBAEnB,OAAO,EAAE,mBAAmB;YAM1B,OAAO;IA+Df,cAAc,CAClB,IAAI,EAAE,qBAAqB,GAC1B,OAAO,CAAC,sBAAsB,CAAC;IAQ5B,WAAW,CACf,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,sBAAsB,CAAC;IAQ5B,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAOxD,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOzC,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,GAAE,KAAK,GAAG,KAAa,GAAG,OAAO,CAAC,MAAM,CAAC;IASpE,mBAAmB,CACvB,WAAW,EAAE,MAAM,EAAE,EACrB,OAAO,EAAE;QACP,MAAM,EAAE,MAAM,CAAC;QACf,eAAe,EAAE,MAAM,CAAC;QACxB,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,EACD,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAY3C"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InPostShipXClient = void 0;
|
|
4
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
5
|
+
const SANDBOX_BASE_URL = "https://sandbox-api-shipx-pl.easypack24.net";
|
|
6
|
+
const PRODUCTION_BASE_URL = "https://api-shipx-pl.easypack24.net";
|
|
7
|
+
class InPostShipXClient {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.baseUrl = options.sandbox ? SANDBOX_BASE_URL : PRODUCTION_BASE_URL;
|
|
10
|
+
this.organizationId = options.organizationId;
|
|
11
|
+
this.apiToken = options.apiToken;
|
|
12
|
+
}
|
|
13
|
+
async request(method, path, body, responseType = "json") {
|
|
14
|
+
const headers = {
|
|
15
|
+
Authorization: `Bearer ${this.apiToken}`,
|
|
16
|
+
"Content-Type": "application/json",
|
|
17
|
+
};
|
|
18
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
19
|
+
method,
|
|
20
|
+
headers,
|
|
21
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
22
|
+
});
|
|
23
|
+
if (!response.ok) {
|
|
24
|
+
const errorText = await response.text();
|
|
25
|
+
let errorMessage = `InPost API error: ${response.status} ${response.statusText}`;
|
|
26
|
+
try {
|
|
27
|
+
const errorJson = JSON.parse(errorText);
|
|
28
|
+
if (errorJson.details) {
|
|
29
|
+
errorMessage += ` - ${JSON.stringify(errorJson.details)}`;
|
|
30
|
+
}
|
|
31
|
+
else if (errorJson.message) {
|
|
32
|
+
errorMessage += ` - ${errorJson.message}`;
|
|
33
|
+
}
|
|
34
|
+
else if (errorJson.error) {
|
|
35
|
+
errorMessage += ` - ${errorJson.error}`;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
errorMessage += ` - ${errorText}`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
if (errorText) {
|
|
43
|
+
errorMessage += ` - ${errorText}`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (response.status === 401 || response.status === 403) {
|
|
47
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_ALLOWED, errorMessage);
|
|
48
|
+
}
|
|
49
|
+
if (response.status === 404) {
|
|
50
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_FOUND, errorMessage);
|
|
51
|
+
}
|
|
52
|
+
if (response.status === 422) {
|
|
53
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, errorMessage);
|
|
54
|
+
}
|
|
55
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.UNEXPECTED_STATE, errorMessage);
|
|
56
|
+
}
|
|
57
|
+
if (responseType === "buffer") {
|
|
58
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
59
|
+
return Buffer.from(arrayBuffer);
|
|
60
|
+
}
|
|
61
|
+
if (response.status === 204) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
return response.json();
|
|
65
|
+
}
|
|
66
|
+
async createShipment(data) {
|
|
67
|
+
return this.request("POST", `/v1/organizations/${this.organizationId}/shipments`, data);
|
|
68
|
+
}
|
|
69
|
+
async buyShipment(id, offerId) {
|
|
70
|
+
return this.request("POST", `/v1/shipments/${id}/buy`, { offer_id: offerId });
|
|
71
|
+
}
|
|
72
|
+
async getShipment(id) {
|
|
73
|
+
return this.request("GET", `/v1/shipments/${id}`);
|
|
74
|
+
}
|
|
75
|
+
async cancelShipment(id) {
|
|
76
|
+
return this.request("DELETE", `/v1/shipments/${id}`);
|
|
77
|
+
}
|
|
78
|
+
async getLabel(id, format = "pdf") {
|
|
79
|
+
return this.request("GET", `/v1/shipments/${id}/label?format=${format}`, undefined, "buffer");
|
|
80
|
+
}
|
|
81
|
+
async createDispatchOrder(shipmentIds, address, comment) {
|
|
82
|
+
return this.request("POST", `/v1/organizations/${this.organizationId}/dispatch_orders`, {
|
|
83
|
+
shipments: shipmentIds,
|
|
84
|
+
address,
|
|
85
|
+
...(comment && { comment }),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.InPostShipXClient = InPostShipXClient;
|
|
90
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/lib/client.ts"],"names":[],"mappings":";;;AAAA,qDAAwD;AAOxD,MAAM,gBAAgB,GAAG,6CAA6C,CAAC;AACvE,MAAM,mBAAmB,GAAG,qCAAqC,CAAC;AAElE,MAAa,iBAAiB;IAK5B,YAAY,OAA4B;QACtC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,mBAAmB,CAAC;QACxE,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;QAC7C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IACnC,CAAC;IAEO,KAAK,CAAC,OAAO,CACnB,MAAiC,EACjC,IAAY,EACZ,IAAc,EACd,eAAkC,MAAM;QAExC,MAAM,OAAO,GAA2B;YACtC,aAAa,EAAE,UAAU,IAAI,CAAC,QAAQ,EAAE;YACxC,cAAc,EAAE,kBAAkB;SACnC,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,EAAE,EAAE;YACrD,MAAM;YACN,OAAO;YACP,IAAI,EAAE,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;SAC5D,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,SA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IACJ,CAAC;IAED,KAAK,CAAC,mBAAmB,CACvB,WAAqB,EACrB,OAMC,EACD,OAAgB;QAEhB,OAAO,IAAI,CAAC,OAAO,CACjB,MAAM,EACN,qBAAqB,IAAI,CAAC,cAAc,kBAAkB,EAC1D;YACE,SAAS,EAAE,WAAW;YACtB,OAAO;YACP,GAAG,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC;SAC5B,CACF,CAAC;IACJ,CAAC;CAEF;AA5ID,8CA4IC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export interface InPostPluginOptions {
|
|
2
|
+
apiToken: string;
|
|
3
|
+
organizationId: string;
|
|
4
|
+
sandbox?: boolean;
|
|
5
|
+
defaultParcelTemplate?: "small" | "medium" | "large";
|
|
6
|
+
sender?: InPostPerson;
|
|
7
|
+
}
|
|
8
|
+
export interface InPostAddress {
|
|
9
|
+
street: string;
|
|
10
|
+
building_number: string;
|
|
11
|
+
city: string;
|
|
12
|
+
post_code: string;
|
|
13
|
+
country_code: string;
|
|
14
|
+
}
|
|
15
|
+
export interface InPostPerson {
|
|
16
|
+
company_name?: string;
|
|
17
|
+
first_name?: string;
|
|
18
|
+
last_name?: string;
|
|
19
|
+
email: string;
|
|
20
|
+
phone: string;
|
|
21
|
+
address?: InPostAddress;
|
|
22
|
+
}
|
|
23
|
+
export type InPostParcelTemplate = "small" | "medium" | "large";
|
|
24
|
+
export interface InPostParcelDimensions {
|
|
25
|
+
length: number;
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
unit?: "mm" | "cm" | "in";
|
|
29
|
+
}
|
|
30
|
+
export interface InPostParcelWeight {
|
|
31
|
+
amount: number;
|
|
32
|
+
unit?: "kg" | "lbs" | "g";
|
|
33
|
+
}
|
|
34
|
+
export interface InPostParcel {
|
|
35
|
+
template?: InPostParcelTemplate;
|
|
36
|
+
dimensions?: InPostParcelDimensions;
|
|
37
|
+
weight?: InPostParcelWeight;
|
|
38
|
+
}
|
|
39
|
+
export declare enum InPostService {
|
|
40
|
+
inpost_locker_standard = "inpost_locker_standard",
|
|
41
|
+
inpost_courier_standard = "inpost_courier_standard"
|
|
42
|
+
}
|
|
43
|
+
export interface InPostShipmentRequest {
|
|
44
|
+
receiver: InPostPerson;
|
|
45
|
+
sender?: InPostPerson;
|
|
46
|
+
parcels: InPostParcel[];
|
|
47
|
+
service: InPostService;
|
|
48
|
+
reference?: string;
|
|
49
|
+
custom_attributes?: {
|
|
50
|
+
target_point?: string;
|
|
51
|
+
sending_method?: string;
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export interface InPostOffer {
|
|
56
|
+
id: number;
|
|
57
|
+
status: string;
|
|
58
|
+
rate?: number;
|
|
59
|
+
currency?: string;
|
|
60
|
+
expires_at?: string;
|
|
61
|
+
}
|
|
62
|
+
export interface InPostShipmentResponse {
|
|
63
|
+
id: number;
|
|
64
|
+
status: string;
|
|
65
|
+
tracking_number: string;
|
|
66
|
+
href: string;
|
|
67
|
+
parcels: InPostParcel[];
|
|
68
|
+
receiver?: InPostPerson;
|
|
69
|
+
sender?: InPostPerson;
|
|
70
|
+
service?: string;
|
|
71
|
+
reference?: string;
|
|
72
|
+
offers?: InPostOffer[];
|
|
73
|
+
selected_offer?: InPostOffer;
|
|
74
|
+
created_at?: string;
|
|
75
|
+
updated_at?: string;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAA;IAChB,cAAc,EAAE,MAAM,CAAA;IACtB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,qBAAqB,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAA;IACpD,MAAM,CAAC,EAAE,YAAY,CAAA;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ClB,YAAY,CAAC,EAAE,MAAM,CAAA;QACrB,cAAc,CAAC,EAAE,MAAM,CAAA;QACvB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KACvB,CAAA;CACF;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,eAAe,EAAE,MAAM,CAAA;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,YAAY,EAAE,CAAA;IACvB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,MAAM,CAAC,EAAE,YAAY,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,WAAW,EAAE,CAAA;IACtB,cAAc,CAAC,EAAE,WAAW,CAAA;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InPostService = void 0;
|
|
4
|
+
var InPostService;
|
|
5
|
+
(function (InPostService) {
|
|
6
|
+
InPostService["inpost_locker_standard"] = "inpost_locker_standard";
|
|
7
|
+
InPostService["inpost_courier_standard"] = "inpost_courier_standard";
|
|
8
|
+
})(InPostService || (exports.InPostService = InPostService = {}));
|
|
9
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/lib/types.ts"],"names":[],"mappings":";;;AA6CA,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,kEAAiD,CAAA;IACjD,oEAAmD,CAAA;AACrD,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/providers/inpost/index.ts"],"names":[],"mappings":";AAGA,wBAEE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
7
|
+
const service_1 = __importDefault(require("./service"));
|
|
8
|
+
exports.default = (0, utils_1.ModuleProvider)(utils_1.Modules.FULFILLMENT, {
|
|
9
|
+
services: [service_1.default],
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/providers/inpost/index.ts"],"names":[],"mappings":";;;;;AAAA,qDAAmE;AACnE,wDAAwD;AAExD,kBAAe,IAAA,sBAAc,EAAC,eAAO,CAAC,WAAW,EAAE;IACjD,QAAQ,EAAE,CAAC,iBAAgC,CAAC;CAC7C,CAAC,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Logger } from "@medusajs/framework/types";
|
|
2
|
+
import { AbstractFulfillmentProviderService } from "@medusajs/framework/utils";
|
|
3
|
+
import { CalculatedShippingOptionPrice, CalculateShippingOptionPriceDTO, CreateFulfillmentResult, CreateShippingOptionDTO, FulfillmentDTO, FulfillmentItemDTO, FulfillmentOrderDTO, ValidateFulfillmentDataContext } from "@medusajs/types";
|
|
4
|
+
import { InPostPluginOptions, InPostService } from "../../lib/types";
|
|
5
|
+
type InjectedDependencies = {
|
|
6
|
+
logger: Logger;
|
|
7
|
+
};
|
|
8
|
+
declare class InPostFulfillmentProviderService extends AbstractFulfillmentProviderService {
|
|
9
|
+
static identifier: string;
|
|
10
|
+
private client;
|
|
11
|
+
private logger;
|
|
12
|
+
private options;
|
|
13
|
+
constructor({ logger }: InjectedDependencies, options: InPostPluginOptions);
|
|
14
|
+
getFulfillmentOptions(): Promise<{
|
|
15
|
+
id: InPostService;
|
|
16
|
+
name: string;
|
|
17
|
+
is_return: boolean;
|
|
18
|
+
}[]>;
|
|
19
|
+
validateOption(data: Record<string, unknown>): Promise<boolean>;
|
|
20
|
+
validateFulfillmentData(optionData: Record<string, unknown>, data: Record<string, unknown>, context: ValidateFulfillmentDataContext): Promise<Record<string, unknown>>;
|
|
21
|
+
canCalculate(_data: CreateShippingOptionDTO): Promise<boolean>;
|
|
22
|
+
calculatePrice(_optionData: CalculateShippingOptionPriceDTO["optionData"], _data: CalculateShippingOptionPriceDTO["data"], _context: CalculateShippingOptionPriceDTO["context"]): Promise<CalculatedShippingOptionPrice>;
|
|
23
|
+
createFulfillment(data: Record<string, unknown>, _items: Partial<Omit<FulfillmentItemDTO, "fulfillment">>[], order: Partial<FulfillmentOrderDTO> | undefined, fulfillment: Partial<Omit<FulfillmentDTO, "provider_id" | "data" | "items">>): Promise<CreateFulfillmentResult>;
|
|
24
|
+
cancelFulfillment(data: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
25
|
+
createReturnFulfillment(fulfillment: Record<string, unknown>): Promise<CreateFulfillmentResult>;
|
|
26
|
+
getFulfillmentDocuments(data: Record<string, unknown>): Promise<any>;
|
|
27
|
+
getReturnDocuments(data: Record<string, unknown>): Promise<any>;
|
|
28
|
+
getShipmentDocuments(data: Record<string, unknown>): Promise<any>;
|
|
29
|
+
retrieveDocuments(fulfillmentData: Record<string, unknown>, documentType: string): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export default InPostFulfillmentProviderService;
|
|
32
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../src/providers/inpost/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EACL,kCAAkC,EAEnC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,6BAA6B,EAC7B,+BAA+B,EAC/B,uBAAuB,EACvB,uBAAuB,EACvB,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,8BAA8B,EAC/B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAIL,mBAAmB,EACnB,aAAa,EAEd,MAAM,iBAAiB,CAAC;AAEzB,KAAK,oBAAoB,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,cAAM,gCAAiC,SAAQ,kCAAkC;IAC/E,MAAM,CAAC,UAAU,SAAY;IAE7B,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAsB;gBAEzB,EAAE,MAAM,EAAE,EAAE,oBAAoB,EAAE,OAAO,EAAE,mBAAmB;IAqBpE,qBAAqB;;;;;IAerB,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAI/D,uBAAuB,CAC3B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAmE7B,YAAY,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,OAAO,CAAC;IAI9D,cAAc,CAClB,WAAW,EAAE,+BAA+B,CAAC,YAAY,CAAC,EAC1D,KAAK,EAA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|
|
3
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
4
|
+
const client_1 = require("../../lib/client");
|
|
5
|
+
const types_1 = require("../../lib/types");
|
|
6
|
+
class InPostFulfillmentProviderService extends utils_1.AbstractFulfillmentProviderService {
|
|
7
|
+
constructor({ logger }, options) {
|
|
8
|
+
super();
|
|
9
|
+
if (!options.apiToken) {
|
|
10
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "InPost fulfillment provider: missing required option `apiToken`");
|
|
11
|
+
}
|
|
12
|
+
if (!options.organizationId) {
|
|
13
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "InPost fulfillment provider: missing required option `organizationId`");
|
|
14
|
+
}
|
|
15
|
+
this.logger = logger;
|
|
16
|
+
this.options = options;
|
|
17
|
+
this.client = new client_1.InPostShipXClient(options);
|
|
18
|
+
}
|
|
19
|
+
async getFulfillmentOptions() {
|
|
20
|
+
return [
|
|
21
|
+
{
|
|
22
|
+
id: types_1.InPostService.inpost_locker_standard,
|
|
23
|
+
name: "InPost Paczkomat (locker delivery)",
|
|
24
|
+
is_return: false,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: types_1.InPostService.inpost_courier_standard,
|
|
28
|
+
name: "InPost Courier (home delivery)",
|
|
29
|
+
is_return: false,
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
async validateOption(data) {
|
|
34
|
+
return Object.values(types_1.InPostService).includes(data.id);
|
|
35
|
+
}
|
|
36
|
+
async validateFulfillmentData(optionData, data, context) {
|
|
37
|
+
const serviceId = optionData.id;
|
|
38
|
+
const isLockerService = serviceId === types_1.InPostService.inpost_locker_standard;
|
|
39
|
+
if (isLockerService && !data.target_point) {
|
|
40
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "InPost locker delivery requires `target_point` (Paczkomat machine ID) in fulfillment data");
|
|
41
|
+
}
|
|
42
|
+
const items = context.items;
|
|
43
|
+
let parcelDimensions;
|
|
44
|
+
if (items?.length) {
|
|
45
|
+
let totalWeight = 0;
|
|
46
|
+
let maxLength = 0;
|
|
47
|
+
let maxWidth = 0;
|
|
48
|
+
let totalHeight = 0;
|
|
49
|
+
for (const item of items) {
|
|
50
|
+
const qty = item.quantity || 1;
|
|
51
|
+
const v = item.variant;
|
|
52
|
+
if (v) {
|
|
53
|
+
totalWeight += (v.weight || 0) * qty;
|
|
54
|
+
maxLength = Math.max(maxLength, v.length || 0);
|
|
55
|
+
maxWidth = Math.max(maxWidth, v.width || 0);
|
|
56
|
+
totalHeight += (v.height || 0) * qty;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (totalWeight > 0 || maxLength > 0 || maxWidth > 0 || totalHeight > 0) {
|
|
60
|
+
parcelDimensions = {
|
|
61
|
+
length: maxLength,
|
|
62
|
+
width: maxWidth,
|
|
63
|
+
height: totalHeight,
|
|
64
|
+
weight: totalWeight,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
...data,
|
|
70
|
+
service_type: serviceId,
|
|
71
|
+
target_point: data.target_point,
|
|
72
|
+
...(parcelDimensions && { parcel_dimensions: parcelDimensions }),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
async canCalculate(_data) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
async calculatePrice(_optionData, _data, _context) {
|
|
79
|
+
return { calculated_amount: 0, is_calculated_price_tax_inclusive: true };
|
|
80
|
+
}
|
|
81
|
+
async createFulfillment(data, _items, order, fulfillment) {
|
|
82
|
+
const shippingAddress = order?.shipping_address;
|
|
83
|
+
if (!shippingAddress) {
|
|
84
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "InPost fulfillment: shipping address is required");
|
|
85
|
+
}
|
|
86
|
+
const email = order?.email ||
|
|
87
|
+
order?.customer?.email ||
|
|
88
|
+
data.email ||
|
|
89
|
+
"";
|
|
90
|
+
if (!email) {
|
|
91
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "InPost fulfillment: receiver email is required. Ensure the order has an email address.");
|
|
92
|
+
}
|
|
93
|
+
// Normalize Polish postal code to XX-XXX format
|
|
94
|
+
let postCode = shippingAddress.postal_code || "";
|
|
95
|
+
if (/^\d{5}$/.test(postCode)) {
|
|
96
|
+
postCode = `${postCode.slice(0, 2)}-${postCode.slice(2)}`;
|
|
97
|
+
}
|
|
98
|
+
const receiver = {
|
|
99
|
+
first_name: shippingAddress.first_name || undefined,
|
|
100
|
+
last_name: shippingAddress.last_name || undefined,
|
|
101
|
+
email,
|
|
102
|
+
phone: shippingAddress.phone || "",
|
|
103
|
+
address: {
|
|
104
|
+
street: shippingAddress.address_1 || "",
|
|
105
|
+
building_number: shippingAddress.address_2 || "1",
|
|
106
|
+
city: shippingAddress.city || "",
|
|
107
|
+
post_code: postCode,
|
|
108
|
+
country_code: (shippingAddress.country_code || "PL").toUpperCase(),
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
const serviceType = data.service_type ||
|
|
112
|
+
types_1.InPostService.inpost_locker_standard;
|
|
113
|
+
const isLockerService = serviceType === types_1.InPostService.inpost_locker_standard;
|
|
114
|
+
let parcel;
|
|
115
|
+
if (isLockerService) {
|
|
116
|
+
const template = (data.parcel_template ||
|
|
117
|
+
this.options.defaultParcelTemplate ||
|
|
118
|
+
"small");
|
|
119
|
+
parcel = { template };
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
const dims = data.parcel_dimensions;
|
|
123
|
+
parcel = {
|
|
124
|
+
dimensions: {
|
|
125
|
+
length: dims?.length || 200,
|
|
126
|
+
width: dims?.width || 200,
|
|
127
|
+
height: dims?.height || 100,
|
|
128
|
+
unit: "mm",
|
|
129
|
+
},
|
|
130
|
+
weight: {
|
|
131
|
+
amount: dims?.weight || 1,
|
|
132
|
+
unit: "kg",
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const customAttributes = isLockerService
|
|
137
|
+
? {
|
|
138
|
+
target_point: data.target_point,
|
|
139
|
+
sending_method: "parcel_locker",
|
|
140
|
+
}
|
|
141
|
+
: {
|
|
142
|
+
sending_method: "dispatch_order",
|
|
143
|
+
};
|
|
144
|
+
const shipmentRequest = {
|
|
145
|
+
receiver,
|
|
146
|
+
...(this.options.sender && { sender: this.options.sender }),
|
|
147
|
+
parcels: [parcel],
|
|
148
|
+
service: serviceType,
|
|
149
|
+
reference: order?.id || fulfillment.id,
|
|
150
|
+
custom_attributes: customAttributes,
|
|
151
|
+
};
|
|
152
|
+
try {
|
|
153
|
+
const shipment = await this.client.createShipment(shipmentRequest);
|
|
154
|
+
// Poll until shipment is confirmed or offers are ready
|
|
155
|
+
let current = shipment;
|
|
156
|
+
for (let i = 0; i < 15; i++) {
|
|
157
|
+
if (current.status === "confirmed")
|
|
158
|
+
break;
|
|
159
|
+
const hasOffers = current.offers?.some((o) => o.status === "available");
|
|
160
|
+
if (hasOffers || current.status === "offers_prepared")
|
|
161
|
+
break;
|
|
162
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
163
|
+
current = await this.client.getShipment(shipment.id);
|
|
164
|
+
}
|
|
165
|
+
// If not yet confirmed, try the offer flow (select + buy)
|
|
166
|
+
if (current.status !== "confirmed") {
|
|
167
|
+
const offer = current.offers?.find((o) => o.status === "available") ||
|
|
168
|
+
current.selected_offer ||
|
|
169
|
+
current.offers?.[0];
|
|
170
|
+
if (!offer) {
|
|
171
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.UNEXPECTED_STATE, `InPost fulfillment: shipment ${shipment.id} stuck in status "${current.status}" with no available offers`);
|
|
172
|
+
}
|
|
173
|
+
current = await this.client.buyShipment(shipment.id, offer.id);
|
|
174
|
+
}
|
|
175
|
+
let dispatchOrderId;
|
|
176
|
+
if (!isLockerService) {
|
|
177
|
+
const senderAddress = this.options.sender?.address;
|
|
178
|
+
if (!senderAddress) {
|
|
179
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "InPost fulfillment: `sender.address` is required in plugin options for courier shipments (needed to create a dispatch order)");
|
|
180
|
+
}
|
|
181
|
+
const dispatchOrder = await this.client.createDispatchOrder([current.id], {
|
|
182
|
+
street: senderAddress.street,
|
|
183
|
+
building_number: senderAddress.building_number,
|
|
184
|
+
city: senderAddress.city,
|
|
185
|
+
post_code: senderAddress.post_code,
|
|
186
|
+
country_code: senderAddress.country_code || "PL",
|
|
187
|
+
});
|
|
188
|
+
dispatchOrderId = dispatchOrder.id;
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
data: {
|
|
192
|
+
shipment_id: current.id,
|
|
193
|
+
tracking_number: current.tracking_number,
|
|
194
|
+
status: current.status,
|
|
195
|
+
service_type: serviceType,
|
|
196
|
+
target_point: data.target_point,
|
|
197
|
+
...(dispatchOrderId && { dispatch_order_id: dispatchOrderId }),
|
|
198
|
+
},
|
|
199
|
+
labels: [],
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
this.logger.error("InPost createFulfillment failed", error);
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
async cancelFulfillment(data) {
|
|
208
|
+
const shipmentId = data.shipment_id;
|
|
209
|
+
if (!shipmentId) {
|
|
210
|
+
this.logger.error("InPost cancelFulfillment: no shipment_id in data, skipping cancellation");
|
|
211
|
+
return {};
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
await this.client.cancelShipment(shipmentId);
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
this.logger.error("InPost cancelFulfillment failed", error);
|
|
218
|
+
throw error;
|
|
219
|
+
}
|
|
220
|
+
return {};
|
|
221
|
+
}
|
|
222
|
+
async createReturnFulfillment(fulfillment) {
|
|
223
|
+
// Medusa's default return flow doesn't provide enough data to create
|
|
224
|
+
// an InPost return shipment (no target_point for locker, no order address).
|
|
225
|
+
// Return shipments should be created manually in InPost Manager.
|
|
226
|
+
this.logger.info("InPost createReturnFulfillment - skipping InPost API call, return shipment should be created manually in InPost Manager");
|
|
227
|
+
return {
|
|
228
|
+
data: {
|
|
229
|
+
note: "Return shipment not created automatically. Please create it manually in InPost Manager.",
|
|
230
|
+
},
|
|
231
|
+
labels: [],
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
// Note: base class declares Promise<never[]> which appears incorrect; we
|
|
235
|
+
// return real document objects, so we use `any` here to satisfy the override.
|
|
236
|
+
async getFulfillmentDocuments(data) {
|
|
237
|
+
const shipmentId = data.shipment_id;
|
|
238
|
+
if (!shipmentId) {
|
|
239
|
+
return [];
|
|
240
|
+
}
|
|
241
|
+
try {
|
|
242
|
+
const labelBuffer = await this.client.getLabel(shipmentId, "pdf");
|
|
243
|
+
return [
|
|
244
|
+
{
|
|
245
|
+
base64: labelBuffer.toString("base64"),
|
|
246
|
+
name: `inpost-label-${shipmentId}.pdf`,
|
|
247
|
+
type: "application/pdf",
|
|
248
|
+
},
|
|
249
|
+
];
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
this.logger.error("InPost getFulfillmentDocuments failed", error);
|
|
253
|
+
throw error;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
async getReturnDocuments(data) {
|
|
257
|
+
const shipmentId = data.return_shipment_id ||
|
|
258
|
+
data.shipment_id;
|
|
259
|
+
if (!shipmentId) {
|
|
260
|
+
return [];
|
|
261
|
+
}
|
|
262
|
+
try {
|
|
263
|
+
const labelBuffer = await this.client.getLabel(shipmentId, "pdf");
|
|
264
|
+
return [
|
|
265
|
+
{
|
|
266
|
+
base64: labelBuffer.toString("base64"),
|
|
267
|
+
name: `inpost-return-label-${shipmentId}.pdf`,
|
|
268
|
+
type: "application/pdf",
|
|
269
|
+
},
|
|
270
|
+
];
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
this.logger.error("InPost getReturnDocuments failed", error);
|
|
274
|
+
throw error;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
async getShipmentDocuments(data) {
|
|
278
|
+
return this.getFulfillmentDocuments(data);
|
|
279
|
+
}
|
|
280
|
+
async retrieveDocuments(fulfillmentData, documentType) {
|
|
281
|
+
if (documentType === "invoice") {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
await this.getFulfillmentDocuments(fulfillmentData);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
InPostFulfillmentProviderService.identifier = "inpost";
|
|
288
|
+
exports.default = InPostFulfillmentProviderService;
|
|
289
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../../src/providers/inpost/service.ts"],"names":[],"mappings":";;AACA,qDAGmC;AAWnC,6CAAqD;AACrD,2CAOyB;AAMzB,MAAM,gCAAiC,SAAQ,0CAAkC;IAO/E,YAAY,EAAE,MAAM,EAAwB,EAAE,OAA4B;QACxE,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YACtB,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,iEAAiE,CAClE,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;YAC5B,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,uEAAuE,CACxE,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,IAAI,0BAAiB,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,qBAAqB;QACzB,OAAO;YACL;gBACE,EAAE,EAAE,qBAAa,CAAC,sBAAsB;gBACx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IAAI,CAAC,kBAAyC;YAC9C,IAAI,CAAC,WAAkC,CAAC;QAE3C,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,IAAI,CAAC;YACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;YAClE,OAAO;gBACL;oBACE,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC;oBACtC,IAAI,EAAE,uBAAuB,UAAU,MAAM;oBAC7C,IAAI,EAAE,iBAAiB;iBACxB;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,kCAAkC,EAAE,KAAc,CAAC,CAAC;YACtE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,IAA6B;QACtD,OAAO,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,iBAAiB,CACrB,eAAwC,EACxC,YAAoB;QAEpB,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YAC/B,OAAO;QACT,CAAC;QACD,MAAM,IAAI,CAAC,uBAAuB,CAAC,eAAe,CAAC,CAAC;IACtD,CAAC;;AArZM,2CAAU,GAAG,QAAQ,CAAC;AAwZ/B,kBAAe,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const widgetModule = { widgets: [] };
|
|
3
|
+
const routeModule = {
|
|
4
|
+
routes: []
|
|
5
|
+
};
|
|
6
|
+
const menuItemModule = {
|
|
7
|
+
menuItems: []
|
|
8
|
+
};
|
|
9
|
+
const formModule = { customFields: {} };
|
|
10
|
+
const displayModule = {
|
|
11
|
+
displays: {}
|
|
12
|
+
};
|
|
13
|
+
const i18nModule = { resources: {} };
|
|
14
|
+
const plugin = {
|
|
15
|
+
widgetModule,
|
|
16
|
+
routeModule,
|
|
17
|
+
menuItemModule,
|
|
18
|
+
formModule,
|
|
19
|
+
displayModule,
|
|
20
|
+
i18nModule
|
|
21
|
+
};
|
|
22
|
+
module.exports = plugin;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const widgetModule = { widgets: [] };
|
|
2
|
+
const routeModule = {
|
|
3
|
+
routes: []
|
|
4
|
+
};
|
|
5
|
+
const menuItemModule = {
|
|
6
|
+
menuItems: []
|
|
7
|
+
};
|
|
8
|
+
const formModule = { customFields: {} };
|
|
9
|
+
const displayModule = {
|
|
10
|
+
displays: {}
|
|
11
|
+
};
|
|
12
|
+
const i18nModule = { resources: {} };
|
|
13
|
+
const plugin = {
|
|
14
|
+
widgetModule,
|
|
15
|
+
routeModule,
|
|
16
|
+
menuItemModule,
|
|
17
|
+
formModule,
|
|
18
|
+
displayModule,
|
|
19
|
+
i18nModule
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
plugin as default
|
|
23
|
+
};
|
package/README.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# medusa-inpost-fulfillment
|
|
2
|
+
|
|
3
|
+
InPost fulfillment provider plugin for [MedusaJS v2](https://medusajs.com/). Integrates with the [InPost ShipX API](https://dokumentacja-inpost.atlassian.net/wiki/spaces/PL/pages/622754/API+ShipX) to support Paczkomat locker and courier delivery.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Paczkomat locker delivery** (`inpost_locker_standard`) — ships to a selected InPost locker machine
|
|
8
|
+
- **Courier delivery** (`inpost_courier_standard`) — ships to the receiver's address with automatic dispatch order creation
|
|
9
|
+
- Automatic offer selection and purchase (for prepaid accounts)
|
|
10
|
+
- Shipment label retrieval (PDF/ZPL)
|
|
11
|
+
- Shipment cancellation
|
|
12
|
+
- Polish postal code normalization (5 digits to XX-XXX format)
|
|
13
|
+
- Parcel dimensions aggregated from cart item variants
|
|
14
|
+
|
|
15
|
+
## Prerequisites
|
|
16
|
+
|
|
17
|
+
- MedusaJS v2 (`@medusajs/framework` ^2.5.0)
|
|
18
|
+
- Node.js >= 20
|
|
19
|
+
- InPost ShipX API credentials ([register here](https://manager.paczkomaty.pl/))
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install medusa-inpost-fulfillment
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Configuration
|
|
28
|
+
|
|
29
|
+
Add the plugin to your `medusa-config.ts`:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { defineConfig } from "@medusajs/framework/utils";
|
|
33
|
+
|
|
34
|
+
export default defineConfig({
|
|
35
|
+
// ...
|
|
36
|
+
plugins: [
|
|
37
|
+
{
|
|
38
|
+
resolve: "@medusajs/medusa/fulfillment",
|
|
39
|
+
options: {
|
|
40
|
+
providers: [
|
|
41
|
+
{
|
|
42
|
+
resolve: "medusa-inpost-fulfillment/providers/inpost",
|
|
43
|
+
id: "inpost",
|
|
44
|
+
options: {
|
|
45
|
+
// Required
|
|
46
|
+
apiToken: process.env.INPOST_API_TOKEN,
|
|
47
|
+
organizationId: process.env.INPOST_ORGANIZATION_ID,
|
|
48
|
+
|
|
49
|
+
// Optional — use InPost sandbox environment (default: false)
|
|
50
|
+
sandbox: true,
|
|
51
|
+
|
|
52
|
+
// Optional — default parcel template for locker shipments
|
|
53
|
+
// "small" | "medium" | "large" (default: "small")
|
|
54
|
+
defaultParcelTemplate: "small",
|
|
55
|
+
|
|
56
|
+
// Required for courier shipments — sender details
|
|
57
|
+
sender: {
|
|
58
|
+
company_name: "My Store",
|
|
59
|
+
first_name: "John",
|
|
60
|
+
last_name: "Doe",
|
|
61
|
+
email: "shipping@mystore.com",
|
|
62
|
+
phone: "500100200",
|
|
63
|
+
address: {
|
|
64
|
+
street: "Marszalkowska",
|
|
65
|
+
building_number: "1",
|
|
66
|
+
city: "Warsaw",
|
|
67
|
+
post_code: "00-001",
|
|
68
|
+
country_code: "PL",
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Environment variables
|
|
81
|
+
|
|
82
|
+
| Variable | Description |
|
|
83
|
+
| ------------------------ | --------------------------- |
|
|
84
|
+
| `INPOST_API_TOKEN` | Your InPost ShipX API token |
|
|
85
|
+
| `INPOST_ORGANIZATION_ID` | Your InPost organization ID |
|
|
86
|
+
|
|
87
|
+
## Shipping options
|
|
88
|
+
|
|
89
|
+
After installing the plugin, create shipping options in the Medusa admin that use the InPost fulfillment provider. The plugin exposes two services:
|
|
90
|
+
|
|
91
|
+
| Service ID | Description |
|
|
92
|
+
| ------------------------- | ------------------------- |
|
|
93
|
+
| `inpost_locker_standard` | Paczkomat locker delivery |
|
|
94
|
+
| `inpost_courier_standard` | Courier home delivery |
|
|
95
|
+
|
|
96
|
+
## Where to find your shipments
|
|
97
|
+
|
|
98
|
+
InPost uses different apps for locker and courier shipments:
|
|
99
|
+
|
|
100
|
+
- **Locker (Paczkomat) shipments** — visible in [Manager Paczek](https://manager.paczkomaty.pl) (sandbox: [sandbox-manager.paczkomaty.pl](https://sandbox-manager.paczkomaty.pl))
|
|
101
|
+
- **Courier shipments** — visible in **WebTrucker** at [kurier.inpost.pl](https://kurier.inpost.pl) under "Przesyłki do nadania" (Shipments to send), and later under "Monitoring" once InPost processes them
|
|
102
|
+
|
|
103
|
+
> **Note on sandbox for courier shipments:** WebTrucker has no sandbox equivalent, so courier shipments created in sandbox will not appear in any UI. In sandbox, a correctly created courier shipment will simply reach status `confirmed` via the API — that is the sandbox success criterion. Only production courier shipments are visible in WebTrucker.
|
|
104
|
+
|
|
105
|
+
## Storefront integration
|
|
106
|
+
|
|
107
|
+
### Locker delivery
|
|
108
|
+
|
|
109
|
+
For Paczkomat locker delivery, the storefront must pass `target_point` (the Paczkomat machine ID) when adding a shipping method to the cart:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
await sdk.store.cart.addShippingMethod(cartId, {
|
|
113
|
+
option_id: lockerShippingOptionId,
|
|
114
|
+
data: {
|
|
115
|
+
target_point: "WAW123", // Paczkomat machine ID
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
You can use the [InPost Geowidget](https://dokumentacja-inpost.atlassian.net/wiki/spaces/PL/pages/622594/Geowidget) to let customers pick a Paczkomat on a map.
|
|
121
|
+
|
|
122
|
+
### Courier delivery
|
|
123
|
+
|
|
124
|
+
For courier delivery, no additional data is needed — the receiver address is taken from the cart's shipping address:
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
await sdk.store.cart.addShippingMethod(cartId, {
|
|
128
|
+
option_id: courierShippingOptionId,
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Parcel dimensions
|
|
133
|
+
|
|
134
|
+
For courier shipments, the plugin aggregates parcel dimensions from cart item variants (the `weight`, `length`, `height`, and `width` fields on product variants). If no dimensions are set, defaults are used (200x200x100mm, 1kg).
|
|
135
|
+
|
|
136
|
+
For locker shipments, a parcel template (`small`, `medium`, or `large`) is used instead, configurable via the `defaultParcelTemplate` option or per-shipment via `parcel_template` in fulfillment data.
|
|
137
|
+
|
|
138
|
+
## How it works
|
|
139
|
+
|
|
140
|
+
### Fulfillment flow
|
|
141
|
+
|
|
142
|
+
1. **Create shipment** — sends parcel, receiver, and sender data to InPost ShipX API
|
|
143
|
+
2. **Offer handling** — for prepaid accounts, the plugin polls for offers, selects the first available one, and purchases it
|
|
144
|
+
3. **Dispatch order** (courier only) — creates a dispatch order to schedule courier pickup from the sender's address
|
|
145
|
+
4. **Return data** — stores `shipment_id`, `tracking_number`, and `dispatch_order_id` in the fulfillment data
|
|
146
|
+
|
|
147
|
+
### Cancellation
|
|
148
|
+
|
|
149
|
+
When a fulfillment is cancelled in Medusa, the plugin cancels the corresponding shipment in InPost.
|
|
150
|
+
|
|
151
|
+
### Labels
|
|
152
|
+
|
|
153
|
+
The plugin supports retrieving shipment labels as PDF documents through Medusa's fulfillment documents API.
|
|
154
|
+
|
|
155
|
+
### Returns
|
|
156
|
+
|
|
157
|
+
Return shipments are not created automatically — they should be created manually in InPost Manager, as Medusa's return flow does not provide sufficient data (e.g., target locker for locker returns).
|
|
158
|
+
|
|
159
|
+
## Options reference
|
|
160
|
+
|
|
161
|
+
| Option | Type | Required | Default | Description |
|
|
162
|
+
| ----------------------- | -------------------------------- | ----------- | --------- | ----------------------------------------------- |
|
|
163
|
+
| `apiToken` | `string` | Yes | — | InPost ShipX API token |
|
|
164
|
+
| `organizationId` | `string` | Yes | — | InPost organization ID |
|
|
165
|
+
| `sandbox` | `boolean` | No | `false` | Use sandbox API environment |
|
|
166
|
+
| `defaultParcelTemplate` | `"small" \| "medium" \| "large"` | No | `"small"` | Default parcel template for locker shipments |
|
|
167
|
+
| `sender` | `object` | For courier | — | Sender details (required for courier shipments) |
|
|
168
|
+
| `sender.company_name` | `string` | No | — | Sender company name |
|
|
169
|
+
| `sender.first_name` | `string` | No | — | Sender first name |
|
|
170
|
+
| `sender.last_name` | `string` | No | — | Sender last name |
|
|
171
|
+
| `sender.email` | `string` | Yes | — | Sender email |
|
|
172
|
+
| `sender.phone` | `string` | Yes | — | Sender phone number |
|
|
173
|
+
| `sender.address` | `object` | Yes | — | Sender address |
|
|
174
|
+
|
|
175
|
+
## License
|
|
176
|
+
|
|
177
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "medusa-inpost-fulfillment",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "InPost fulfillment provider for MedusaJS v2 - Paczkomat locker and courier integration via ShipX API",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"medusa-plugin-integration",
|
|
8
|
+
"medusa-v2",
|
|
9
|
+
"medusa-plugin-shipping",
|
|
10
|
+
"inpost",
|
|
11
|
+
"paczkomat",
|
|
12
|
+
"shipx"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
"./package.json": "./package.json",
|
|
16
|
+
"./providers/*": "./.medusa/server/providers/*/index.js",
|
|
17
|
+
"./*": "./.medusa/server/*.js"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
".medusa",
|
|
21
|
+
"!.medusa/server/**/__tests__/**",
|
|
22
|
+
"!.medusa/server/**/__mocks__/**"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "medusa plugin:build",
|
|
26
|
+
"dev": "medusa plugin:develop",
|
|
27
|
+
"publish:local": "medusa plugin:publish"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@medusajs/cli": "^2.5.0",
|
|
31
|
+
"@medusajs/framework": "^2.5.0",
|
|
32
|
+
"@medusajs/medusa": "^2.5.0",
|
|
33
|
+
"@swc/core": "^1.7.28",
|
|
34
|
+
"typescript": "^5.0.0",
|
|
35
|
+
"ts-node": "^10.9.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@medusajs/framework": "^2.5.0"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/bystrol/medusa-inpost-fulfillment.git"
|
|
43
|
+
},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=20"
|
|
46
|
+
}
|
|
47
|
+
}
|