@teamnovu/kit-shopware-composables 0.0.9 → 0.0.11

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/inject.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ShopwareClient } from '@teamnovu/kit-shopware-api-client';
2
2
  import { InjectionKey } from 'vue';
3
3
  import { Operations } from './query/types/operations';
4
- export declare const shopwareClientKey: InjectionKey<ShopwareClient<never>>;
4
+ export declare const shopwareClientKey: InjectionKey<ShopwareClient<Operations>>;
5
5
  export declare function useShopwareQueryClient(): ShopwareClient<Operations>;
package/dist/keys.d.ts CHANGED
@@ -2,6 +2,9 @@ import { MaybeRef } from 'vue';
2
2
  export declare const contextKeys: {
3
3
  all: () => readonly ["context"];
4
4
  };
5
+ export declare const languageKey: {
6
+ all: () => readonly ["language"];
7
+ };
5
8
  export declare const categoryKeys: {
6
9
  all: () => readonly ["category"];
7
10
  lists: () => readonly ["category", "list"];
@@ -1,2 +1,3 @@
1
1
  export * from './useReadContextQuery';
2
2
  export * from './useUpdateContextMutation';
3
+ export * from './useReadLanguageQuery';
@@ -0,0 +1,13 @@
1
+ import { OperationOptions } from '../types/query';
2
+ import { UndefinedInitialQueryOptions, UseQueryReturnType } from '@tanstack/vue-query';
3
+ import { BrandedResponse } from '@teamnovu/kit-shopware-api-client';
4
+ import { Operations } from '..';
5
+ declare const readLanguageOperation = "readLanguages post /language";
6
+ export declare function useReadLanguageQueryOptions(options?: OperationOptions<typeof readLanguageOperation>): UndefinedInitialQueryOptions<BrandedResponse<Operations, "readLanguages post /language">, Error, BrandedResponse<Operations, "readLanguages post /language">, readonly ["language"]> & {
7
+ queryKey: readonly ["language"] & {
8
+ [dataTagSymbol]: BrandedResponse<Operations, "readLanguages post /language">;
9
+ [dataTagErrorSymbol]: Error;
10
+ };
11
+ };
12
+ export declare function useReadLanguageQuery(options?: OperationOptions<typeof readLanguageOperation>): UseQueryReturnType<BrandedResponse<Operations, "readLanguages post /language">, Error>;
13
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamnovu/kit-shopware-composables",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "A collection of composables for the Shopware API",
5
5
  "main": "dist/index.mjs",
6
6
  "module": "dist/index.mjs",
@@ -17,7 +17,7 @@
17
17
  "peerDependencies": {
18
18
  "@tanstack/vue-query": "^5.85.3",
19
19
  "vue": "^3.0.0",
20
- "@teamnovu/kit-shopware-api-client": "0.0.7"
20
+ "@teamnovu/kit-shopware-api-client": "0.0.9"
21
21
  },
22
22
  "repository": {
23
23
  "type": "git",
@@ -1,6 +1,6 @@
1
1
  import type { GenericRecord } from '#store-types'
2
- import type { MaybeRef } from 'vue'
3
2
  import { computed, unref } from 'vue'
3
+ import { useReadContextQuery } from '../../query'
4
4
 
5
5
  interface SeoUrlEntity {
6
6
  extensions?: {
@@ -8,11 +8,21 @@ interface SeoUrlEntity {
8
8
  }
9
9
  }
10
10
 
11
- export const getSeoUrl = <T extends SeoUrlEntity>(entity: T, languageId: string) => {
12
- const urls = entity.extensions?.novuSeoUrls as Record<string, string>
11
+ const getSeoUrl = <T extends SeoUrlEntity>(entity: T, languageId: string | string[]) => {
12
+ const urls = entity?.extensions?.novuSeoUrls as Record<string, string>
13
+ if (Array.isArray(languageId)) {
14
+ const matchedId = languageId.find(id => !!urls?.[id])
15
+ return matchedId ? urls?.[matchedId] ?? '' : ''
16
+ }
13
17
  return urls?.[languageId] ?? ''
14
18
  }
15
19
 
16
- export const useSeoUrl = <T extends SeoUrlEntity>(entity: MaybeRef<T>, languageId: MaybeRef<string>) => {
17
- return computed(() => getSeoUrl(unref(entity), unref(languageId)))
20
+ export const useSeoUrl = <T extends SeoUrlEntity>() => {
21
+ const contextQuery = useReadContextQuery()
22
+ const contextLanguageChain = computed(() => contextQuery.data?.value?.context?.languageIdChain ?? [])
23
+
24
+ return (entity: T, languageId: string) => {
25
+ const languageChain = [languageId, ...contextLanguageChain.value]
26
+ return getSeoUrl(unref(entity), unref(languageChain))
27
+ }
18
28
  }
package/src/inject.ts CHANGED
@@ -3,7 +3,7 @@ import type { InjectionKey } from 'vue'
3
3
  import { inject } from 'vue'
4
4
  import type { Operations } from './query/types/operations'
5
5
 
6
- export const shopwareClientKey = Symbol('shopwareClient') as InjectionKey<ShopwareClient<never>>
6
+ export const shopwareClientKey = Symbol('shopwareClient') as InjectionKey<ShopwareClient<Operations>>
7
7
 
8
8
  export function useShopwareQueryClient() {
9
9
  const client = inject(shopwareClientKey)
package/src/keys.ts CHANGED
@@ -4,6 +4,10 @@ export const contextKeys = {
4
4
  all: () => ['context'] as const,
5
5
  }
6
6
 
7
+ export const languageKey = {
8
+ all: () => ['language'] as const,
9
+ }
10
+
7
11
  export const categoryKeys = {
8
12
  all: () => ['category'] as const,
9
13
  lists: () => [...categoryKeys.all(), 'list'] as const,
@@ -1,2 +1,3 @@
1
1
  export * from './useReadContextQuery'
2
2
  export * from './useUpdateContextMutation'
3
+ export * from './useReadLanguageQuery'
@@ -0,0 +1,28 @@
1
+ import { queryOptions, useQuery } from '@tanstack/vue-query'
2
+ import { useShopwareQueryClient } from '../../inject'
3
+ import { languageKey } from '../../keys'
4
+ import { unrefOptions } from '../../util'
5
+ import type { OperationKey, OperationOptions } from '../types/query'
6
+
7
+ const readLanguageOperation = 'readLanguages post /language' satisfies OperationKey
8
+
9
+ export function useReadLanguageQueryOptions(
10
+ options?: OperationOptions<typeof readLanguageOperation>,
11
+ ) {
12
+ const client = useShopwareQueryClient()
13
+
14
+ return queryOptions({
15
+ queryKey: languageKey.all(),
16
+ queryFn: ({ signal }) =>
17
+ client.query(readLanguageOperation, {
18
+ ...unrefOptions(options),
19
+ signal,
20
+ }),
21
+ })
22
+ }
23
+
24
+ export function useReadLanguageQuery(
25
+ options?: OperationOptions<typeof readLanguageOperation>,
26
+ ) {
27
+ return useQuery(useReadLanguageQueryOptions(options))
28
+ }
@@ -27,7 +27,7 @@ export function useLoginCustomerMutation(
27
27
  const contextToken = response.headers.get('sw-context-token')
28
28
 
29
29
  if (contextToken) {
30
- client.setContextToken(contextToken)
30
+ client.contextToken = contextToken
31
31
  }
32
32
 
33
33
  return response.json()
@@ -25,7 +25,7 @@ export function useRegisterConfirmMutation(
25
25
  const contextToken = response.headers.get('sw-context-token')
26
26
 
27
27
  if (contextToken) {
28
- client.setContextToken(contextToken)
28
+ client.contextToken = contextToken
29
29
  }
30
30
 
31
31
  return response.json() as Promise<never>