@myparcel-dev/pdk-admin 2.4.0 → 2.4.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.
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- MONOWEAVE:BELOW -->
|
|
4
4
|
|
|
5
|
+
## [2.4.1](https://github.com/myparcelnl/js-pdk/compare/@myparcel-dev/pdk-admin@2.4.0...@myparcel-dev/pdk-admin@2.4.1) "@myparcel-dev/pdk-admin" (2026-11-06)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **admin:** offer the €100 insurance tier in the shipment options form ([#520](https://github.com/myparcelnl/js-pdk/issues/520)) ([498b0db](https://github.com/myparcelnl/js-pdk/commit/498b0db6087bb0836c89c328be5cc1550ade35ff)), closes [myparcelnl/prestashop#269](https://github.com/myparcelnl/prestashop/issues/269) [myparcelnl/prestashop#238](https://github.com/myparcelnl/prestashop/issues/238)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
5
15
|
## [2.4.0](https://github.com/myparcelnl/js-pdk/compare/@myparcel-dev/pdk-admin@2.3.0...@myparcel-dev/pdk-admin@2.4.0) "@myparcel-dev/pdk-admin" (2026-10-22)
|
|
6
16
|
|
|
7
17
|
|
package/package.json
CHANGED
|
@@ -195,14 +195,21 @@ describe('useFormCapabilities', () => {
|
|
|
195
195
|
expect(useFormCapabilities().getInsuranceOptions(formStub('POSTNL'), formatter)).toEqual([]);
|
|
196
196
|
});
|
|
197
197
|
|
|
198
|
-
|
|
198
|
+
// Same cases as InsuranceTierMathTest in the PHP PDK, so both sides offer the same tiers.
|
|
199
|
+
it.each([
|
|
200
|
+
[100, 100, ['100']],
|
|
201
|
+
[500, 100, ['500']],
|
|
202
|
+
[0, 200_000, ['0', '10000', '25000', '50000', '100000', '150000', '200000']],
|
|
203
|
+
[30_000, 100_000, ['30000', '50000', '100000']],
|
|
204
|
+
[50_000, 150_000, ['50000', '100000', '150000']],
|
|
205
|
+
[0, 37_500, ['0', '10000', '25000', '37500']],
|
|
206
|
+
])('builds the tier ladder for min %i and max %i', async (min, max, expected) => {
|
|
199
207
|
const shipment = buildCarrier({
|
|
200
208
|
carrier: 'POSTNL',
|
|
201
209
|
options: {
|
|
202
210
|
insurance: {
|
|
203
|
-
min: {amount:
|
|
204
|
-
|
|
205
|
-
max: {amount: 100_000, currency: 'EUR'},
|
|
211
|
+
min: {amount: min, currency: 'EUR'},
|
|
212
|
+
max: {amount: max, currency: 'EUR'},
|
|
206
213
|
default: {amount: 0, currency: 'EUR'},
|
|
207
214
|
} as never,
|
|
208
215
|
},
|
|
@@ -210,14 +217,13 @@ describe('useFormCapabilities', () => {
|
|
|
210
217
|
queryStore.setQuery(shipmentModifier('order-1'), 'success', [shipment]);
|
|
211
218
|
|
|
212
219
|
const {useFormCapabilities} = await import('./useFormCapabilities');
|
|
213
|
-
const
|
|
214
|
-
|
|
220
|
+
const values = useFormCapabilities()
|
|
221
|
+
.getInsuranceOptions(formStub('POSTNL'), formatter)
|
|
222
|
+
.map((o) => o.value);
|
|
215
223
|
|
|
216
224
|
// First entry is the inherit default; subsequent values are cent amounts as strings.
|
|
217
225
|
expect(values[0]).toBe(TriState.Inherit);
|
|
218
|
-
|
|
219
|
-
// the boundary semantics — replacing `<` with `<=` on LOW_THRESHOLD would shift these.
|
|
220
|
-
expect(values.slice(1)).toEqual(['0', '25000', '50000', '100000']);
|
|
226
|
+
expect(values.slice(1)).toEqual(expected);
|
|
221
227
|
});
|
|
222
228
|
|
|
223
229
|
it('returns [] when the carrier advertises insurance without limits', async () => {
|
|
@@ -7,6 +7,30 @@ import {type AdminContext, type SelectOption} from '../../types';
|
|
|
7
7
|
import {useQueryStore, type ResolvedQuery} from '../../stores';
|
|
8
8
|
import {Format, type Formatter} from '../../composables';
|
|
9
9
|
|
|
10
|
+
const INSURANCE_FLOOR_TIERS = [10_000, 25_000, 50_000];
|
|
11
|
+
const INSURANCE_STEP = 50_000;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Build the insurance tier ladder for a min/max range, in cents. Mirrors
|
|
15
|
+
* `InsuranceTierMath::buildTiers` in the PHP PDK, so the dropdown offers the same amounts the
|
|
16
|
+
* backend accepts: min, the floor tiers €100, €250 and €500, then €500 steps, then max.
|
|
17
|
+
*/
|
|
18
|
+
const buildInsuranceTiers = (min: number, max: number): number[] => {
|
|
19
|
+
if (min >= max) {
|
|
20
|
+
return [min];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const tiers = [min, ...INSURANCE_FLOOR_TIERS.filter((tier) => tier > min && tier < max)];
|
|
24
|
+
|
|
25
|
+
for (let tier = Math.max(min, INSURANCE_STEP) + INSURANCE_STEP; tier < max; tier += INSURANCE_STEP) {
|
|
26
|
+
tiers.push(tier);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
tiers.push(max);
|
|
30
|
+
|
|
31
|
+
return [...new Set(tiers)];
|
|
32
|
+
};
|
|
33
|
+
|
|
10
34
|
/**
|
|
11
35
|
* Bag of capability resolvers, each pre-bound to a Pinia store + orderId snapshot captured at
|
|
12
36
|
* the composable's invocation time. Returned by {@link useFormCapabilities}.
|
|
@@ -129,25 +153,15 @@ export const useFormCapabilities = (): FormCapabilities => {
|
|
|
129
153
|
};
|
|
130
154
|
|
|
131
155
|
const getInsuranceOptions = (form: FormInstance, formatter: Formatter): SelectOption[] => {
|
|
132
|
-
// Insurance bracket steps: €250 increments below €500, €500 increments above. Switching
|
|
133
|
-
// step size at the threshold keeps the dropdown short for high-value shipments.
|
|
134
|
-
const STEP_BELOW_THRESHOLD = 250;
|
|
135
|
-
const STEP_ABOVE_THRESHOLD = 500;
|
|
136
|
-
const STEP_THRESHOLD = 500;
|
|
137
|
-
|
|
138
156
|
const carrier = getCarrierCapabilitiesForShipment(form);
|
|
139
157
|
const insuranceData = carrier?.options?.insurance;
|
|
140
158
|
|
|
141
|
-
const min = insuranceData?.min?.amount
|
|
142
|
-
const max = insuranceData?.max?.amount
|
|
159
|
+
const min = insuranceData?.min?.amount ?? 0;
|
|
160
|
+
const max = insuranceData?.max?.amount ?? 0;
|
|
143
161
|
|
|
144
162
|
if (max === 0) return [];
|
|
145
163
|
|
|
146
|
-
const insurancePossibilities
|
|
147
|
-
|
|
148
|
-
for (let i = min; i <= max; i += i < STEP_THRESHOLD ? STEP_BELOW_THRESHOLD : STEP_ABOVE_THRESHOLD) {
|
|
149
|
-
insurancePossibilities.push(i * 100);
|
|
150
|
-
}
|
|
164
|
+
const insurancePossibilities = buildInsuranceTiers(min, max);
|
|
151
165
|
|
|
152
166
|
return [
|
|
153
167
|
{label: 'option_default', value: TriState.Inherit},
|