@myparcel-dev/pdk-admin 2.3.0 → 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.
Files changed (42) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/actions/composables/mutations/orders/useExportOrdersMutation.d.ts +1 -1
  3. package/dist/composables/language/useLanguage.d.ts +6 -0
  4. package/dist/pdk/PdkAdmin.d.ts +26 -2
  5. package/dist/pdk/boot.d.ts +5 -0
  6. package/dist/sdk/index.d.ts +1 -0
  7. package/dist/sdk/requestHeaders.d.ts +10 -0
  8. package/dist/services/mutations/getModalMutationOptions.d.ts +7 -1
  9. package/dist/services/mutations/index.d.ts +1 -0
  10. package/dist/services/mutations/modalMutationToken.d.ts +16 -0
  11. package/dist/stores/useModalStore.d.ts +9 -1
  12. package/dist/types/admin.types.d.ts +10 -0
  13. package/dist/types/configuration.types.d.ts +12 -0
  14. package/package.json +2 -2
  15. package/src/actions/composables/mutations/orders/useExportOrdersMutation.spec.ts +75 -0
  16. package/src/actions/composables/mutations/orders/useExportOrdersMutation.ts +17 -6
  17. package/src/components/common/TabNavigation.spec.ts +78 -0
  18. package/src/components/common/TabNavigation.vue +7 -5
  19. package/src/composables/language/resetLanguageCache.spec.ts +24 -0
  20. package/src/composables/language/useLanguage.ts +13 -0
  21. package/src/pdk/PdkAdmin.spec.ts +97 -0
  22. package/src/pdk/PdkAdmin.ts +63 -7
  23. package/src/pdk/boot.ts +13 -3
  24. package/src/pdk/createPdkAdmin.spec.ts +75 -0
  25. package/src/pdk/createPdkAdmin.ts +2 -0
  26. package/src/pdk/instance/plugins/createStorePlugin.spec.ts +44 -0
  27. package/src/pdk/instance/plugins/createStorePlugin.ts +12 -7
  28. package/src/pdk/instance/plugins/createVueQueryPlugin.spec.ts +29 -0
  29. package/src/pdk/instance/plugins/createVueQueryPlugin.ts +7 -7
  30. package/src/pdk/setupAdminApp.ts +3 -0
  31. package/src/sdk/composables/usePdkAdminApi.ts +3 -0
  32. package/src/sdk/index.ts +1 -0
  33. package/src/sdk/requestHeaders.spec.ts +54 -0
  34. package/src/sdk/requestHeaders.ts +36 -0
  35. package/src/services/mutations/getModalMutationOptions.spec.ts +59 -0
  36. package/src/services/mutations/getModalMutationOptions.ts +23 -15
  37. package/src/services/mutations/index.ts +1 -0
  38. package/src/services/mutations/modalMutationToken.ts +27 -0
  39. package/src/stores/useModalStore.spec.ts +33 -0
  40. package/src/stores/useModalStore.ts +13 -1
  41. package/src/types/admin.types.ts +12 -0
  42. package/src/types/configuration.types.ts +14 -0
@@ -0,0 +1,33 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ import {beforeEach, describe, expect, it} from 'vitest';
4
+ import {createPinia, setActivePinia} from 'pinia';
5
+ import {AdminModalKey} from '../data';
6
+ import {useModalStore} from './useModalStore';
7
+
8
+ describe('useModalStore', () => {
9
+ beforeEach(() => {
10
+ setActivePinia(createPinia());
11
+ });
12
+
13
+ it('gives every opened modal a new token', () => {
14
+ const modalStore = useModalStore();
15
+
16
+ modalStore.open(AdminModalKey.ShipmentOptions);
17
+ const first = modalStore.token;
18
+
19
+ modalStore.open(AdminModalKey.ShipmentOptions);
20
+
21
+ expect(first).toEqual({modal: AdminModalKey.ShipmentOptions});
22
+ expect(modalStore.token).not.toBe(first);
23
+ });
24
+
25
+ it('removes the token when the modal closes', () => {
26
+ const modalStore = useModalStore();
27
+
28
+ modalStore.open(AdminModalKey.PrintOptions);
29
+ modalStore.close();
30
+
31
+ expect(modalStore.token).toBeNull();
32
+ });
33
+ });
@@ -1,4 +1,4 @@
1
- import {ref, type Ref, type UnwrapNestedRefs} from 'vue';
1
+ import {ref, type Ref, shallowRef, type UnwrapNestedRefs} from 'vue';
2
2
  import {defineStore} from 'pinia';
3
3
  import {type AdminModalContext} from '../types';
4
4
  import {type AdminModalKey, NotificationCategory} from '../data';
@@ -9,10 +9,17 @@ type ModalOpenFn = <K extends AdminModalKey>(modal: K, context?: AdminModalConte
9
9
 
10
10
  type ModalCloseFn = <K extends AdminModalKey>(modal: K) => void;
11
11
 
12
+ /**
13
+ * Identifies one opened modal. Every open() creates a new object, so a token
14
+ * never matches another modal, also not a modal in another admin instance.
15
+ */
16
+ export type ModalToken = Readonly<{modal: AdminModalKey}>;
17
+
12
18
  type ModalStore = {
13
19
  loading: Ref<boolean>;
14
20
  opened: Ref<AdminModalKey | null>;
15
21
  context: Ref<UnwrapNestedRefs<AdminModalContext>>;
22
+ token: Ref<ModalToken | null>;
16
23
  onOpen(callback: ModalOpenFn): void;
17
24
  onClose(callback: ModalCloseFn): void;
18
25
  open<K extends AdminModalKey>(modal: K, newContext?: AdminModalContext<K>): void;
@@ -24,6 +31,7 @@ export const useModalStore = defineStore('modal', (): ModalStore => {
24
31
 
25
32
  const opened = ref<AdminModalKey | null>(null);
26
33
  const context = ref<AdminModalContext>(null);
34
+ const token = shallowRef<ModalToken | null>(null);
27
35
 
28
36
  const openHooks = ref<ModalOpenFn[]>([]);
29
37
  const closeHooks = ref<ModalCloseFn[]>([]);
@@ -35,6 +43,8 @@ export const useModalStore = defineStore('modal', (): ModalStore => {
35
43
 
36
44
  context,
37
45
 
46
+ token,
47
+
38
48
  onOpen(callback) {
39
49
  openHooks.value.push(callback);
40
50
  },
@@ -49,6 +59,7 @@ export const useModalStore = defineStore('modal', (): ModalStore => {
49
59
  // @ts-ignore
50
60
  context.value = newContext;
51
61
  opened.value = modal;
62
+ token.value = {modal};
52
63
 
53
64
  openHooks.value.forEach((hook) => hook(modal, newContext));
54
65
  },
@@ -59,6 +70,7 @@ export const useModalStore = defineStore('modal', (): ModalStore => {
59
70
 
60
71
  opened.value = null;
61
72
  context.value = null;
73
+ token.value = null;
62
74
  closeHooks.value.forEach((hook) => hook(modal));
63
75
  },
64
76
  };
@@ -1,4 +1,6 @@
1
1
  import {type Component} from 'vue';
2
+ import {type Pinia} from 'pinia';
3
+ import {type QueryClient} from '@tanstack/vue-query';
2
4
  import {type PdkLogger} from '../services';
3
5
  import {
4
6
  type ADMIN_COMPONENT_PREFIX,
@@ -40,6 +42,16 @@ export interface AdminAppConfig {
40
42
  context: AdminContextObject;
41
43
  logger: PdkLogger;
42
44
  view?: AdminView;
45
+
46
+ /**
47
+ * Store of the PdkAdmin instance, shared by its apps. Without it, all apps share one store.
48
+ */
49
+ store?: Pinia;
50
+
51
+ /**
52
+ * Query client of the PdkAdmin instance, shared by its apps. Without it, all apps share one client.
53
+ */
54
+ queryClient?: QueryClient;
43
55
  }
44
56
 
45
57
  export interface AdminInstance extends Omit<AdminAppConfig, 'context'> {
@@ -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'>;