@myparcel-dev/pdk-admin 2.2.7 → 2.4.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/CHANGELOG.md +28 -0
- package/dist/actions/composables/mutations/orders/useExportOrdersMutation.d.ts +1 -1
- package/dist/actions/print/resolvePrintParameters.d.ts +1 -0
- package/dist/composables/language/useLanguage.d.ts +6 -0
- package/dist/pdk/PdkAdmin.d.ts +26 -2
- package/dist/pdk/boot.d.ts +5 -0
- package/dist/sdk/index.d.ts +1 -0
- package/dist/sdk/requestHeaders.d.ts +10 -0
- package/dist/services/mutations/getModalMutationOptions.d.ts +7 -1
- package/dist/services/mutations/index.d.ts +1 -0
- package/dist/services/mutations/modalMutationToken.d.ts +16 -0
- package/dist/services/print/createPdfObjectUrl.d.ts +2 -0
- package/dist/services/print/index.d.ts +3 -0
- package/dist/services/print/labelsNotification.d.ts +5 -0
- package/dist/services/print/pollLabelPdf.d.ts +9 -0
- package/dist/stores/useModalStore.d.ts +9 -1
- package/dist/stores/useNotificationStore.d.ts +15 -0
- package/dist/types/actions/endpoints.types.d.ts +1 -1
- package/dist/types/actions/parameters.types.d.ts +3 -0
- package/dist/types/admin.types.d.ts +10 -0
- package/dist/types/common.types.d.ts +7 -0
- package/dist/types/configuration.types.d.ts +12 -0
- package/dist/types/sdk.types.d.ts +14 -1
- package/dist/utils/encodeArrayParameter.d.ts +1 -0
- package/package.json +2 -2
- package/src/actions/composables/mutations/orders/useExportOrdersMutation.spec.ts +75 -0
- package/src/actions/composables/mutations/orders/useExportOrdersMutation.ts +17 -6
- package/src/actions/print/openOrPrintPdf.spec.ts +119 -0
- package/src/actions/print/openOrPrintPdf.ts +48 -3
- package/src/actions/print/resolvePrintParameters.ts +13 -3
- package/src/components/common/TabNavigation.spec.ts +78 -0
- package/src/components/common/TabNavigation.vue +7 -5
- package/src/composables/language/resetLanguageCache.spec.ts +24 -0
- package/src/composables/language/useLanguage.ts +13 -0
- package/src/pdk/PdkAdmin.spec.ts +97 -0
- package/src/pdk/PdkAdmin.ts +63 -7
- package/src/pdk/boot.ts +13 -3
- package/src/pdk/createPdkAdmin.spec.ts +75 -0
- package/src/pdk/createPdkAdmin.ts +2 -0
- package/src/pdk/instance/plugins/createStorePlugin.spec.ts +44 -0
- package/src/pdk/instance/plugins/createStorePlugin.ts +12 -7
- package/src/pdk/instance/plugins/createVueQueryPlugin.spec.ts +29 -0
- package/src/pdk/instance/plugins/createVueQueryPlugin.ts +7 -7
- package/src/pdk/setupAdminApp.ts +3 -0
- package/src/sdk/composables/usePdkAdminApi.ts +3 -0
- package/src/sdk/index.ts +1 -0
- package/src/sdk/requestHeaders.spec.ts +54 -0
- package/src/sdk/requestHeaders.ts +36 -0
- package/src/services/mutations/getModalMutationOptions.spec.ts +59 -0
- package/src/services/mutations/getModalMutationOptions.ts +23 -15
- package/src/services/mutations/index.ts +1 -0
- package/src/services/mutations/modalMutationToken.ts +27 -0
- package/src/services/print/createPdfObjectUrl.ts +6 -0
- package/src/services/print/index.ts +3 -0
- package/src/services/print/labelsNotification.ts +52 -0
- package/src/services/print/pollLabelPdf.spec.ts +58 -0
- package/src/services/print/pollLabelPdf.ts +47 -0
- package/src/stores/useModalStore.spec.ts +33 -0
- package/src/stores/useModalStore.ts +13 -1
- package/src/stores/useNotificationStore.spec.ts +30 -0
- package/src/stores/useNotificationStore.ts +1 -1
- package/src/types/actions/endpoints.types.ts +1 -0
- package/src/types/actions/parameters.types.ts +2 -0
- package/src/types/admin.types.ts +12 -0
- package/src/types/common.types.ts +7 -0
- package/src/types/configuration.types.ts +14 -0
- package/src/types/sdk.types.ts +16 -0
- package/src/utils/encodeArrayParameter.spec.ts +26 -0
- package/src/utils/encodeArrayParameter.ts +2 -1
|
@@ -24,6 +24,13 @@ export interface PdkNotification {
|
|
|
24
24
|
timeout?: boolean | number;
|
|
25
25
|
title?: string;
|
|
26
26
|
variant: Variant;
|
|
27
|
+
/** Shows a spinner next to the content. */
|
|
28
|
+
loading?: boolean;
|
|
29
|
+
/** Shows a button that runs onClick. */
|
|
30
|
+
action?: {
|
|
31
|
+
label: string;
|
|
32
|
+
onClick(): void;
|
|
33
|
+
};
|
|
27
34
|
}
|
|
28
35
|
|
|
29
36
|
export type ResolvedNotification = PdkNotification & {
|
|
@@ -2,6 +2,7 @@ import {type PiniaPluginContext} from 'pinia';
|
|
|
2
2
|
import {type FormConfiguration, type InteractiveElementInstance} from '@myparcel-dev/vue-form-builder';
|
|
3
3
|
import {type MakeOptional} from '@myparcel-dev/ts-utils';
|
|
4
4
|
import {type LogLevel} from '../services';
|
|
5
|
+
import {type RequestHeadersProvider} from '../sdk/requestHeaders';
|
|
5
6
|
import {type FORM_KEYS} from '../forms';
|
|
6
7
|
import {type FormatterObject} from '../composables';
|
|
7
8
|
import {type AdminContextObject} from './context.types';
|
|
@@ -109,6 +110,19 @@ export type AdminConfiguration = {
|
|
|
109
110
|
* Callback to generate a field id.
|
|
110
111
|
*/
|
|
111
112
|
generateFieldId(element: InteractiveElementInstance): string;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Gives extra headers for every request to the PDK backend endpoint, for
|
|
116
|
+
* example a short-lived bearer token. Called once per request.
|
|
117
|
+
*/
|
|
118
|
+
getRequestHeaders?: RequestHeadersProvider;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Read and write the active tab in window.location.hash. Turn it off when the
|
|
122
|
+
* host app routes with the hash, such as the Shopware administration.
|
|
123
|
+
* Defaults to true.
|
|
124
|
+
*/
|
|
125
|
+
useLocationHash?: boolean;
|
|
112
126
|
};
|
|
113
127
|
|
|
114
128
|
export type AdminConfigurationPreset = Omit<Partial<AdminConfiguration>, 'components'>;
|
package/src/types/sdk.types.ts
CHANGED
|
@@ -17,12 +17,18 @@ import {type WebhookDefinition} from './common.types';
|
|
|
17
17
|
|
|
18
18
|
export type PdfUrlResponse = {
|
|
19
19
|
url: string;
|
|
20
|
+
/** Hash of the `/pdfs/{hash}` link for the whole batch, not a label id. Poll it with fetchLabelPdf. */
|
|
21
|
+
labelId?: string;
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
export type PdfDataResponse = {
|
|
23
25
|
data: string;
|
|
24
26
|
};
|
|
25
27
|
|
|
28
|
+
export type PdfPendingResponse = {
|
|
29
|
+
pending: true;
|
|
30
|
+
};
|
|
31
|
+
|
|
26
32
|
interface BasePrintDefinition extends PdkEndpointDefinition {
|
|
27
33
|
formattedResponse: PdfUrlResponse | PdfDataResponse;
|
|
28
34
|
parameters: {
|
|
@@ -149,6 +155,15 @@ interface PrintOrdersDefinition extends BasePrintDefinition {
|
|
|
149
155
|
name: BackendEndpoint.PrintOrders;
|
|
150
156
|
}
|
|
151
157
|
|
|
158
|
+
interface FetchLabelPdfDefinition extends PdkEndpointDefinition {
|
|
159
|
+
formattedResponse: PdfDataResponse | PdfPendingResponse;
|
|
160
|
+
name: BackendEndpoint.FetchLabelPdf;
|
|
161
|
+
parameters: {
|
|
162
|
+
labelId: string;
|
|
163
|
+
};
|
|
164
|
+
response: PdfDataResponse | PdfPendingResponse;
|
|
165
|
+
}
|
|
166
|
+
|
|
152
167
|
interface FetchWebhooksDefinition extends PdkEndpointDefinition {
|
|
153
168
|
name: BackendEndpoint.FetchWebhooks;
|
|
154
169
|
parameters: never;
|
|
@@ -247,6 +262,7 @@ export type BackendEndpointDefinition =
|
|
|
247
262
|
| DeleteWebhooksDefinition
|
|
248
263
|
| ExportOrdersDefinition
|
|
249
264
|
| FetchContextDefinition
|
|
265
|
+
| FetchLabelPdfDefinition
|
|
250
266
|
| FetchOrdersDefinition
|
|
251
267
|
| FetchProductsDefinition
|
|
252
268
|
| FetchShipmentsDefinition
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {describe, expect, it} from 'vitest';
|
|
2
|
+
import {encodeArrayParameter} from './encodeArrayParameter';
|
|
3
|
+
|
|
4
|
+
describe('encodeArrayParameter', () => {
|
|
5
|
+
it('returns a single value unchanged', () => {
|
|
6
|
+
expect(encodeArrayParameter('290')).toBe('290');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// A raw `;` is rewritten to `&` by some proxies (e.g. Traefik), which drops every id after the first.
|
|
10
|
+
it('joins multiple values with an encoded semicolon', () => {
|
|
11
|
+
expect(encodeArrayParameter(['290', 289, '288'])).toBe('290%3B289%3B288');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('skips undefined and null values', () => {
|
|
15
|
+
expect(encodeArrayParameter(['290', undefined, '288'])).toBe('290%3B288');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('returns an empty string for no value', () => {
|
|
19
|
+
expect(encodeArrayParameter(undefined)).toBe('');
|
|
20
|
+
expect(encodeArrayParameter(null)).toBe('');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('encodes characters that would break the query string', () => {
|
|
24
|
+
expect(encodeArrayParameter(['a&b', 'c#d'])).toBe('a%26b%3Bc%23d');
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {isDef} from '@vueuse/core';
|
|
2
2
|
import {type OneOrMore, toArray} from '@myparcel-dev/ts-utils';
|
|
3
3
|
|
|
4
|
+
/** Joins values with `;` and URL-encodes the result, because the SDK appends parameters to the URL raw. */
|
|
4
5
|
export const encodeArrayParameter = (parameter?: null | OneOrMore<string | number | undefined>): string => {
|
|
5
|
-
return toArray(parameter).filter(isDef).join(';');
|
|
6
|
+
return encodeURIComponent(toArray(parameter).filter(isDef).join(';'));
|
|
6
7
|
};
|