@deenruv/inpost 1.0.16 → 1.0.17-dev.5
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/dist/api/shipments/index.d.ts +1 -1
- package/dist/index.test.js +21 -9
- package/dist/validators/optional.d.ts +1 -1
- package/package.json +1 -1
- package/src/index.test.ts +29 -10
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -7,7 +7,7 @@ export declare class Shipment {
|
|
|
7
7
|
label(args?: {
|
|
8
8
|
format?: 'Pdf' | 'Zpl' | 'Epl';
|
|
9
9
|
type?: 'normal' | 'A6' | 'dpi300';
|
|
10
|
-
}): Promise<ReadableStream<Uint8Array
|
|
10
|
+
}): Promise<ReadableStream<Uint8Array<ArrayBuffer>> | null>;
|
|
11
11
|
buy(body: {
|
|
12
12
|
offer_id: number;
|
|
13
13
|
}): Promise<import("../../index.js").Shipment>;
|
package/dist/index.test.js
CHANGED
|
@@ -9,6 +9,15 @@ const promises_1 = require("fs/promises");
|
|
|
9
9
|
const node_path_1 = require("node:path");
|
|
10
10
|
const node_stream_1 = require("node:stream");
|
|
11
11
|
const { INPOST_HOST: host = "sandbox-api-shipx-pl.easypack24.net", INPOST_API_KEY: apiKey, } = process.env;
|
|
12
|
+
const shipmentId = (shipment) => {
|
|
13
|
+
(0, node_assert_1.ok)(typeof shipment.id === "number", "Expected shipment id to be present");
|
|
14
|
+
return shipment.id;
|
|
15
|
+
};
|
|
16
|
+
const firstOfferId = (shipment) => {
|
|
17
|
+
const offerId = shipment.offers?.[0]?.id;
|
|
18
|
+
(0, node_assert_1.ok)(typeof offerId === "number", "Expected shipment first offer id to be present");
|
|
19
|
+
return offerId;
|
|
20
|
+
};
|
|
12
21
|
(0, node_test_1.describe)("inpost client tests", { skip: !apiKey }, () => {
|
|
13
22
|
const client = new index_js_1.Client({ host, apiKey });
|
|
14
23
|
(0, node_test_1.it)("lists organizations", () => (0, node_assert_1.doesNotReject)(client.organizations().list()));
|
|
@@ -65,23 +74,25 @@ const { INPOST_HOST: host = "sandbox-api-shipx-pl.easypack24.net", INPOST_API_KE
|
|
|
65
74
|
while (!shipment.status || shipment.status === "created") {
|
|
66
75
|
console.log("Waiting for shipment to be created...");
|
|
67
76
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
68
|
-
shipment = await client.shipments().get(shipment
|
|
77
|
+
shipment = await client.shipments().get(shipmentId(shipment)).fetch();
|
|
69
78
|
}
|
|
79
|
+
const offerId = firstOfferId(shipment);
|
|
70
80
|
shipment = await client
|
|
71
81
|
.shipments()
|
|
72
|
-
.get(shipment
|
|
73
|
-
.buy({ offer_id:
|
|
74
|
-
let found = shipment.transactions?.find((t) => t.status === "success" && t.offer_id ===
|
|
82
|
+
.get(shipmentId(shipment))
|
|
83
|
+
.buy({ offer_id: offerId });
|
|
84
|
+
let found = shipment.transactions?.find((t) => t.status === "success" && t.offer_id === offerId);
|
|
75
85
|
while (!found) {
|
|
76
86
|
console.log("Waiting for transaction to succeed...");
|
|
77
87
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
78
|
-
shipment = await client.shipments().get(shipment
|
|
88
|
+
shipment = await client.shipments().get(shipmentId(shipment)).fetch();
|
|
79
89
|
found = shipment.transactions?.find((t) => t.status === "success");
|
|
80
90
|
if (!found) {
|
|
91
|
+
const retryOfferId = firstOfferId(shipment);
|
|
81
92
|
await client
|
|
82
93
|
.shipments()
|
|
83
|
-
.get(shipment
|
|
84
|
-
.buy({ offer_id:
|
|
94
|
+
.get(shipmentId(shipment))
|
|
95
|
+
.buy({ offer_id: retryOfferId });
|
|
85
96
|
}
|
|
86
97
|
}
|
|
87
98
|
while (!shipment.status ||
|
|
@@ -89,10 +100,11 @@ const { INPOST_HOST: host = "sandbox-api-shipx-pl.easypack24.net", INPOST_API_KE
|
|
|
89
100
|
shipment.status === "offer_selected") {
|
|
90
101
|
console.log("Waiting for shipment to be ready...");
|
|
91
102
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
92
|
-
shipment = await client.shipments().get(shipment
|
|
103
|
+
shipment = await client.shipments().get(shipmentId(shipment)).fetch();
|
|
93
104
|
}
|
|
94
105
|
const tmp = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), "test-inpost-label"));
|
|
95
|
-
const label = await client.shipments().get(shipment
|
|
106
|
+
const label = await client.shipments().get(shipmentId(shipment)).label();
|
|
107
|
+
(0, node_assert_1.ok)(label, "Expected shipment label response body to be present");
|
|
96
108
|
await label.pipeTo(node_stream_1.Writable.toWeb((0, fs_1.createWriteStream)((0, node_path_1.join)(tmp, "label.pdf"))));
|
|
97
109
|
await (0, promises_1.rm)(tmp, { force: true, recursive: true });
|
|
98
110
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const isOptional: <T>(fn: (v: unknown) => v is T) => (v: unknown) => v is T;
|
|
1
|
+
export declare const isOptional: <T>(fn: (v: unknown) => v is T) => (v: unknown) => v is T | undefined | null;
|
package/package.json
CHANGED
package/src/index.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it } from "node:test";
|
|
2
|
-
import { doesNotReject, notEqual } from "node:assert";
|
|
2
|
+
import { doesNotReject, notEqual, ok } from "node:assert";
|
|
3
3
|
import { Client, CountryCode } from "./index.js";
|
|
4
4
|
import { createWriteStream } from "fs";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
@@ -15,6 +15,22 @@ const {
|
|
|
15
15
|
INPOST_API_KEY: string;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
type ShipmentWithGeneratedFields = {
|
|
19
|
+
id?: number;
|
|
20
|
+
offers?: Array<{ id: number }>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const shipmentId = (shipment: ShipmentWithGeneratedFields) => {
|
|
24
|
+
ok(typeof shipment.id === "number", "Expected shipment id to be present");
|
|
25
|
+
return shipment.id;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const firstOfferId = (shipment: ShipmentWithGeneratedFields) => {
|
|
29
|
+
const offerId = shipment.offers?.[0]?.id;
|
|
30
|
+
ok(typeof offerId === "number", "Expected shipment first offer id to be present");
|
|
31
|
+
return offerId;
|
|
32
|
+
};
|
|
33
|
+
|
|
18
34
|
describe("inpost client tests", { skip: !apiKey }, () => {
|
|
19
35
|
const client = new Client({ host, apiKey });
|
|
20
36
|
it("lists organizations", () => doesNotReject(client.organizations().list()));
|
|
@@ -81,28 +97,30 @@ describe("inpost client tests", { skip: !apiKey }, () => {
|
|
|
81
97
|
while (!shipment.status || shipment.status === "created") {
|
|
82
98
|
console.log("Waiting for shipment to be created...");
|
|
83
99
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
84
|
-
shipment = await client.shipments().get(shipment
|
|
100
|
+
shipment = await client.shipments().get(shipmentId(shipment)).fetch();
|
|
85
101
|
}
|
|
86
102
|
|
|
103
|
+
const offerId = firstOfferId(shipment);
|
|
87
104
|
shipment = await client
|
|
88
105
|
.shipments()
|
|
89
|
-
.get(shipment
|
|
90
|
-
.buy({ offer_id:
|
|
106
|
+
.get(shipmentId(shipment))
|
|
107
|
+
.buy({ offer_id: offerId });
|
|
91
108
|
|
|
92
109
|
let found = shipment.transactions?.find(
|
|
93
|
-
(t) => t.status === "success" && t.offer_id ===
|
|
110
|
+
(t) => t.status === "success" && t.offer_id === offerId,
|
|
94
111
|
);
|
|
95
112
|
|
|
96
113
|
while (!found) {
|
|
97
114
|
console.log("Waiting for transaction to succeed...");
|
|
98
115
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
99
|
-
shipment = await client.shipments().get(shipment
|
|
116
|
+
shipment = await client.shipments().get(shipmentId(shipment)).fetch();
|
|
100
117
|
found = shipment.transactions?.find((t) => t.status === "success");
|
|
101
118
|
if (!found) {
|
|
119
|
+
const retryOfferId = firstOfferId(shipment);
|
|
102
120
|
await client
|
|
103
121
|
.shipments()
|
|
104
|
-
.get(shipment
|
|
105
|
-
.buy({ offer_id:
|
|
122
|
+
.get(shipmentId(shipment))
|
|
123
|
+
.buy({ offer_id: retryOfferId });
|
|
106
124
|
}
|
|
107
125
|
}
|
|
108
126
|
|
|
@@ -113,10 +131,11 @@ describe("inpost client tests", { skip: !apiKey }, () => {
|
|
|
113
131
|
) {
|
|
114
132
|
console.log("Waiting for shipment to be ready...");
|
|
115
133
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
116
|
-
shipment = await client.shipments().get(shipment
|
|
134
|
+
shipment = await client.shipments().get(shipmentId(shipment)).fetch();
|
|
117
135
|
}
|
|
118
136
|
const tmp = await mkdtemp(join(tmpdir(), "test-inpost-label"));
|
|
119
|
-
const label = await client.shipments().get(shipment
|
|
137
|
+
const label = await client.shipments().get(shipmentId(shipment)).label();
|
|
138
|
+
ok(label, "Expected shipment label response body to be present");
|
|
120
139
|
await label.pipeTo(
|
|
121
140
|
Writable.toWeb(
|
|
122
141
|
createWriteStream(join(tmp, "label.pdf")),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["./src/error.ts","./src/index.test.ts","./src/index.ts","./src/api/organizations.ts","./src/api/shipments.ts","./src/api/organizations/index.ts","./src/api/organizations/shipments.ts","./src/api/shipments/index.ts","./src/middleware/auth.ts","./src/middleware/endpoint.ts","./src/middleware/expect_200.ts","./src/middleware/get.ts","./src/middleware/index.ts","./src/middleware/json_request.ts","./src/middleware/json_response.ts","./src/middleware/middleware.ts","./src/middleware/post.ts","./src/middleware/values.ts","./src/models/address.ts","./src/models/carrier.ts","./src/models/country_code.ts","./src/models/currency_code.ts","./src/models/index.ts","./src/models/money.ts","./src/models/offer.ts","./src/models/organization.ts","./src/models/parcel.ts","./src/models/person.ts","./src/models/service.ts","./src/models/shipment.ts","./src/models/transaction.ts","./src/validators/address.ts","./src/validators/array.ts","./src/validators/carrier.ts","./src/validators/is_country_code.ts","./src/validators/is_currency_code.ts","./src/validators/is_money.ts","./src/validators/is_parcel.ts","./src/validators/is_shipment.ts","./src/validators/number.ts","./src/validators/object.ts","./src/validators/optional.ts","./src/validators/organization.ts","./src/validators/person.ts","./src/validators/services.ts","./src/validators/string.ts"],"version":"6.0.3"}
|