@myparcel-dev/pdk-admin 2.2.0 → 2.2.2
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 +15 -0
- package/dist/forms/helpers/useFormCapabilities.d.ts +2 -2
- package/dist/forms/shipmentOptions/fieldFactoryRegistry.d.ts +2 -2
- package/dist/forms/shipmentOptions/fields/createInsuranceField.d.ts +1 -1
- package/dist/forms/shipmentOptions/wireProxyCapabilities.d.ts +2 -2
- package/package.json +5 -6
- package/src/forms/helpers/useFormCapabilities.spec.ts +23 -11
- package/src/forms/helpers/useFormCapabilities.ts +8 -17
- package/src/forms/shipmentOptions/createShipmentOptionsForm.ts +1 -1
- package/src/forms/shipmentOptions/fieldFactoryRegistry.ts +2 -2
- package/src/forms/shipmentOptions/fields/createInsuranceField.ts +2 -2
- package/src/forms/shipmentOptions/wireProxyCapabilities.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- MONOWEAVE:BELOW -->
|
|
4
4
|
|
|
5
|
+
## [2.2.2](https://github.com/myparcelnl/js-pdk/compare/@myparcel-dev/pdk-admin@2.2.1...@myparcel-dev/pdk-admin@2.2.2) "@myparcel-dev/pdk-admin" (2026-08-19)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **insurance:** read insurance limits from the flat capabilities format ([#383](https://github.com/myparcelnl/js-pdk/issues/383)) ([8794c46](https://github.com/myparcelnl/js-pdk/commit/8794c46ee0ffce36fdad9b3e7dc95e44ee56af23)), closes [myparcelnl/pdk#511](https://github.com/myparcelnl/pdk/issues/511)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## [2.2.1](https://github.com/myparcelnl/js-pdk/compare/@myparcel-dev/pdk-admin@2.2.0...@myparcel-dev/pdk-admin@2.2.1) "@myparcel-dev/pdk-admin" (2026-08-07)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
5
20
|
## [2.2.0](https://github.com/myparcelnl/js-pdk/compare/@myparcel-dev/pdk-admin@2.1.0...@myparcel-dev/pdk-admin@2.2.0) "@myparcel-dev/pdk-admin" (2026-08-06)
|
|
6
21
|
|
|
7
22
|
|
|
@@ -37,8 +37,8 @@ export type FormCapabilities = {
|
|
|
37
37
|
*/
|
|
38
38
|
hasShipmentOption: (form: FormInstance, option: string) => boolean;
|
|
39
39
|
/**
|
|
40
|
-
* Insurance amount bracket options derived from the currently selected carrier's
|
|
41
|
-
* `
|
|
40
|
+
* Insurance amount bracket options derived from the currently selected carrier's insurance
|
|
41
|
+
* limits (`min` / `max`). Amounts in the context are in cents; emitted values are strings
|
|
42
42
|
* representing cent amounts so they round-trip through form select inputs unchanged.
|
|
43
43
|
*/
|
|
44
44
|
getInsuranceOptions: (form: FormInstance, formatter: Formatter) => SelectOption[];
|
|
@@ -15,7 +15,7 @@ export type FieldFactory = (refs: ShipmentOptionsRefs, fieldName: string) => Int
|
|
|
15
15
|
* `carrier.options`) to its custom factory function.
|
|
16
16
|
*
|
|
17
17
|
* Current exceptions:
|
|
18
|
-
* - `insurance`: renders as a select/dropdown with amount brackets derived from
|
|
19
|
-
* `
|
|
18
|
+
* - `insurance`: renders as a select/dropdown with amount brackets derived from the
|
|
19
|
+
* `min` / `max` limits in the option data.
|
|
20
20
|
*/
|
|
21
21
|
export declare const fieldFactoryRegistry: Record<string, FieldFactory>;
|
|
@@ -4,7 +4,7 @@ import { type ShipmentOptionsRefs } from '../types';
|
|
|
4
4
|
* Custom field factory for the insurance shipment option.
|
|
5
5
|
*
|
|
6
6
|
* Renders as a select/dropdown instead of a TriState toggle. Insurance amount brackets are
|
|
7
|
-
* derived from the currently selected carrier's shipment-scoped
|
|
7
|
+
* derived from the currently selected carrier's shipment-scoped insurance limits (min/max)
|
|
8
8
|
* and refresh automatically whenever that data changes — i.e. on carrier change AND on
|
|
9
9
|
* packageType / deliveryType / weight / cc change, since those all narrow the shipment-scoped
|
|
10
10
|
* capabilities response.
|
|
@@ -13,8 +13,8 @@ import { type CapabilitiesSelection } from '../../actions/composables/queries/ac
|
|
|
13
13
|
* - **Order query** drives the carrier / packageType / deliveryType dropdowns from each
|
|
14
14
|
* carrier's flat union arrays. Refetches only when destination, weight or the recipient
|
|
15
15
|
* business flag change.
|
|
16
|
-
* - **Shipment query** drives per-option metadata (`isRequired`, `requires`, `excludes`,
|
|
17
|
-
* `
|
|
16
|
+
* - **Shipment query** drives per-option metadata (`isRequired`, `requires`, `excludes`, and the
|
|
17
|
+
* insurance `min` / `max`) for the chosen combination. Refetches when any axis of the selection
|
|
18
18
|
* changes; the empty-result case is the invalid-combo signal consumed by
|
|
19
19
|
* `useCapabilitiesAutoClear`.
|
|
20
20
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myparcel-dev/pdk-admin",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/myparcelnl/js-pdk.git",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@myparcel-dev/constants": "^2.9.0",
|
|
40
|
-
"@myparcel-dev/pdk-common": "^2.1.
|
|
40
|
+
"@myparcel-dev/pdk-common": "^2.1.2",
|
|
41
41
|
"@myparcel-dev/sdk": "^5.1.0",
|
|
42
42
|
"@myparcel-dev/vue-form-builder": "1.0.0-beta.42.6",
|
|
43
43
|
"@tanstack/vue-query": "~4.43.0",
|
|
@@ -46,9 +46,7 @@
|
|
|
46
46
|
"lodash-es": "^4.17.21",
|
|
47
47
|
"lodash-unified": "^1.0.3",
|
|
48
48
|
"pinia": "^2.0.0",
|
|
49
|
-
"
|
|
50
|
-
"vue": "3.5.40",
|
|
51
|
-
"vue-tsc": "^3.3.9"
|
|
49
|
+
"vue": "3.4.31"
|
|
52
50
|
},
|
|
53
51
|
"devDependencies": {
|
|
54
52
|
"@myparcel-dev/pdk-build-vite": "1.0.0-alpha.0",
|
|
@@ -56,7 +54,8 @@
|
|
|
56
54
|
"@vue/test-utils": "^2.0.0",
|
|
57
55
|
"typescript": "^5.2.2",
|
|
58
56
|
"vite": "^5.4.10",
|
|
59
|
-
"vitest": "^3.2.6"
|
|
57
|
+
"vitest": "^3.2.6",
|
|
58
|
+
"vue-tsc": "^3.3.9"
|
|
60
59
|
},
|
|
61
60
|
"engines": {
|
|
62
61
|
"node": ">=20"
|
|
@@ -182,11 +182,9 @@ describe('useFormCapabilities', () => {
|
|
|
182
182
|
carrier: 'POSTNL',
|
|
183
183
|
options: {
|
|
184
184
|
insurance: {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
default: {amount: 0, currency: 'EUR'},
|
|
189
|
-
},
|
|
185
|
+
min: {amount: 0, currency: 'EUR'},
|
|
186
|
+
max: {amount: 0, currency: 'EUR'},
|
|
187
|
+
default: {amount: 0, currency: 'EUR'},
|
|
190
188
|
} as never,
|
|
191
189
|
},
|
|
192
190
|
});
|
|
@@ -202,12 +200,10 @@ describe('useFormCapabilities', () => {
|
|
|
202
200
|
carrier: 'POSTNL',
|
|
203
201
|
options: {
|
|
204
202
|
insurance: {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
default: {amount: 0, currency: 'EUR'},
|
|
210
|
-
},
|
|
203
|
+
min: {amount: 0, currency: 'EUR'},
|
|
204
|
+
// max is 1000€ in cents
|
|
205
|
+
max: {amount: 100_000, currency: 'EUR'},
|
|
206
|
+
default: {amount: 0, currency: 'EUR'},
|
|
211
207
|
} as never,
|
|
212
208
|
},
|
|
213
209
|
});
|
|
@@ -223,5 +219,21 @@ describe('useFormCapabilities', () => {
|
|
|
223
219
|
// the boundary semantics — replacing `<` with `<=` on LOW_THRESHOLD would shift these.
|
|
224
220
|
expect(values.slice(1)).toEqual(['0', '25000', '50000', '100000']);
|
|
225
221
|
});
|
|
222
|
+
|
|
223
|
+
it('returns [] when the carrier advertises insurance without limits', async () => {
|
|
224
|
+
// Stored carrier data that predates the flat limits: insurance is offered, but there is
|
|
225
|
+
// no max to build brackets up to, so there is nothing to enumerate into the dropdown.
|
|
226
|
+
const shipment = buildCarrier({
|
|
227
|
+
carrier: 'POSTNL',
|
|
228
|
+
options: {
|
|
229
|
+
insurance: {isRequired: false, isSelectedByDefault: false} as never,
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
queryStore.setQuery(shipmentModifier('order-1'), 'success', [shipment]);
|
|
233
|
+
|
|
234
|
+
const {useFormCapabilities} = await import('./useFormCapabilities');
|
|
235
|
+
|
|
236
|
+
expect(useFormCapabilities().getInsuranceOptions(formStub('POSTNL'), formatter)).toEqual([]);
|
|
237
|
+
});
|
|
226
238
|
});
|
|
227
239
|
});
|
|
@@ -7,14 +7,6 @@ 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
|
-
interface InsuranceAmountData {
|
|
11
|
-
insuredAmount?: {
|
|
12
|
-
min: {amount: number; currency: string};
|
|
13
|
-
max: {amount: number; currency: string};
|
|
14
|
-
default: {amount: number; currency: string};
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
10
|
/**
|
|
19
11
|
* Bag of capability resolvers, each pre-bound to a Pinia store + orderId snapshot captured at
|
|
20
12
|
* the composable's invocation time. Returned by {@link useFormCapabilities}.
|
|
@@ -53,8 +45,8 @@ export type FormCapabilities = {
|
|
|
53
45
|
hasShipmentOption: (form: FormInstance, option: string) => boolean;
|
|
54
46
|
|
|
55
47
|
/**
|
|
56
|
-
* Insurance amount bracket options derived from the currently selected carrier's
|
|
57
|
-
* `
|
|
48
|
+
* Insurance amount bracket options derived from the currently selected carrier's insurance
|
|
49
|
+
* limits (`min` / `max`). Amounts in the context are in cents; emitted values are strings
|
|
58
50
|
* representing cent amounts so they round-trip through form select inputs unchanged.
|
|
59
51
|
*/
|
|
60
52
|
getInsuranceOptions: (form: FormInstance, formatter: Formatter) => SelectOption[];
|
|
@@ -80,11 +72,10 @@ export type FormCapabilities = {
|
|
|
80
72
|
* window focus, so we read `query.data` live on every resolver call rather than snapshotting
|
|
81
73
|
* the carriers array at setup time.
|
|
82
74
|
*/
|
|
75
|
+
// eslint-disable-next-line max-lines-per-function
|
|
83
76
|
export const useFormCapabilities = (): FormCapabilities => {
|
|
84
77
|
const queryStore = useQueryStore();
|
|
85
|
-
const dynamicContextQuery = queryStore.get(BackendEndpoint.FetchContext, AdminContextKey.Dynamic)
|
|
86
|
-
BackendEndpoint.FetchContext
|
|
87
|
-
>;
|
|
78
|
+
const dynamicContextQuery = queryStore.get(BackendEndpoint.FetchContext, AdminContextKey.Dynamic);
|
|
88
79
|
const orderId = getOrderId();
|
|
89
80
|
|
|
90
81
|
const orderModifier = typeof orderId === 'string' ? `${orderId}.order` : undefined;
|
|
@@ -97,7 +88,7 @@ export const useFormCapabilities = (): FormCapabilities => {
|
|
|
97
88
|
|
|
98
89
|
if (toValue(query.status) !== 'success') return undefined;
|
|
99
90
|
|
|
100
|
-
return
|
|
91
|
+
return toValue(query.data) ?? [];
|
|
101
92
|
};
|
|
102
93
|
|
|
103
94
|
const liveDynamicCarriers = (): CarrierModel[] => {
|
|
@@ -145,10 +136,10 @@ export const useFormCapabilities = (): FormCapabilities => {
|
|
|
145
136
|
const STEP_THRESHOLD = 500;
|
|
146
137
|
|
|
147
138
|
const carrier = getCarrierCapabilitiesForShipment(form);
|
|
148
|
-
const insuranceData =
|
|
139
|
+
const insuranceData = carrier?.options?.insurance;
|
|
149
140
|
|
|
150
|
-
const min = insuranceData
|
|
151
|
-
const max = insuranceData
|
|
141
|
+
const min = insuranceData?.min?.amount ? insuranceData.min.amount / 100 : 0;
|
|
142
|
+
const max = insuranceData?.max?.amount ? insuranceData.max.amount / 100 : 0;
|
|
152
143
|
|
|
153
144
|
if (max === 0) return [];
|
|
154
145
|
|
|
@@ -86,7 +86,7 @@ export const createShipmentOptionsForm = (orders?: OneOrMore<Plugin.ModelPdkOrde
|
|
|
86
86
|
* `hasShipmentOption`, which checks whether the currently selected carrier
|
|
87
87
|
* supports each option.
|
|
88
88
|
*
|
|
89
|
-
* Runtime carrier-specific data (isRequired,
|
|
89
|
+
* Runtime carrier-specific data (isRequired, insurance limits, etc.) is read
|
|
90
90
|
* from the currently selected carrier via `getCarrier(form)`, not from
|
|
91
91
|
* creation-time option data.
|
|
92
92
|
*/
|
|
@@ -18,8 +18,8 @@ export type FieldFactory = (refs: ShipmentOptionsRefs, fieldName: string) => Int
|
|
|
18
18
|
* `carrier.options`) to its custom factory function.
|
|
19
19
|
*
|
|
20
20
|
* Current exceptions:
|
|
21
|
-
* - `insurance`: renders as a select/dropdown with amount brackets derived from
|
|
22
|
-
* `
|
|
21
|
+
* - `insurance`: renders as a select/dropdown with amount brackets derived from the
|
|
22
|
+
* `min` / `max` limits in the option data.
|
|
23
23
|
*/
|
|
24
24
|
export const fieldFactoryRegistry: Record<string, FieldFactory> = {
|
|
25
25
|
insurance: createInsuranceField,
|
|
@@ -13,7 +13,7 @@ import {createRef} from './createRef';
|
|
|
13
13
|
* Custom field factory for the insurance shipment option.
|
|
14
14
|
*
|
|
15
15
|
* Renders as a select/dropdown instead of a TriState toggle. Insurance amount brackets are
|
|
16
|
-
* derived from the currently selected carrier's shipment-scoped
|
|
16
|
+
* derived from the currently selected carrier's shipment-scoped insurance limits (min/max)
|
|
17
17
|
* and refresh automatically whenever that data changes — i.e. on carrier change AND on
|
|
18
18
|
* packageType / deliveryType / weight / cc change, since those all narrow the shipment-scoped
|
|
19
19
|
* capabilities response.
|
|
@@ -39,7 +39,7 @@ export const createInsuranceField = (
|
|
|
39
39
|
|
|
40
40
|
// Watch the shipment-scoped carrier capabilities directly. The resolver tracks both the
|
|
41
41
|
// selected carrier (via `form.getValue(FIELD_CARRIER)`) and the shipment-capabilities
|
|
42
|
-
// query data, so any axis change that updates
|
|
42
|
+
// query data, so any axis change that updates the insurance limits triggers a refresh.
|
|
43
43
|
stopWatcher = watch(
|
|
44
44
|
() => capabilities.getCarrierCapabilitiesForShipment(field.form),
|
|
45
45
|
() => {
|
|
@@ -47,8 +47,8 @@ const resolveOrderInput = (form: FormInstance, order: Plugin.ModelContextOrderDa
|
|
|
47
47
|
* - **Order query** drives the carrier / packageType / deliveryType dropdowns from each
|
|
48
48
|
* carrier's flat union arrays. Refetches only when destination, weight or the recipient
|
|
49
49
|
* business flag change.
|
|
50
|
-
* - **Shipment query** drives per-option metadata (`isRequired`, `requires`, `excludes`,
|
|
51
|
-
* `
|
|
50
|
+
* - **Shipment query** drives per-option metadata (`isRequired`, `requires`, `excludes`, and the
|
|
51
|
+
* insurance `min` / `max`) for the chosen combination. Refetches when any axis of the selection
|
|
52
52
|
* changes; the empty-result case is the invalid-combo signal consumed by
|
|
53
53
|
* `useCapabilitiesAutoClear`.
|
|
54
54
|
*
|