@doswiftly/cli 0.2.6 → 1.0.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 +650 -0
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +6 -1
- package/dist/commands/deploy.js.map +1 -1
- package/package.json +1 -1
- package/templates/storefront-nextjs-shadcn/.github/workflows/build-template.yml +2 -1
- package/templates/storefront-nextjs-shadcn/.github/workflows/deploy.yml +5 -1
- package/templates/storefront-nextjs-shadcn/.github/workflows/preview.yml +3 -1
- package/templates/storefront-nextjs-shadcn/app/[locale]/account/addresses/page.tsx +10 -10
- package/templates/storefront-nextjs-shadcn/app/[locale]/account/loyalty/page.tsx +1 -1
- package/templates/storefront-nextjs-shadcn/app/[locale]/account/orders/[id]/page.tsx +9 -9
- package/templates/storefront-nextjs-shadcn/app/[locale]/account/orders/[id]/tracking/page.tsx +1 -1
- package/templates/storefront-nextjs-shadcn/app/[locale]/account/orders/page.tsx +2 -2
- package/templates/storefront-nextjs-shadcn/app/[locale]/account/settings/page.tsx +3 -3
- package/templates/storefront-nextjs-shadcn/app/[locale]/categories/page.tsx +1 -1
- package/templates/storefront-nextjs-shadcn/app/[locale]/checkout/page.tsx +74 -74
- package/templates/storefront-nextjs-shadcn/app/[locale]/products/[slug]/product-client.tsx +1 -1
- package/templates/storefront-nextjs-shadcn/app/[locale]/products/products-client.tsx +4 -4
- package/templates/storefront-nextjs-shadcn/app/api/auth/whoami/route.ts +6 -0
- package/templates/storefront-nextjs-shadcn/components/account/address-form.tsx +43 -43
- package/templates/storefront-nextjs-shadcn/components/account/address-list.tsx +9 -9
- package/templates/storefront-nextjs-shadcn/components/account/customer-info.fragment.graphql +5 -5
- package/templates/storefront-nextjs-shadcn/components/account/order-details.tsx +8 -8
- package/templates/storefront-nextjs-shadcn/components/account/order-history.tsx +2 -2
- package/templates/storefront-nextjs-shadcn/components/account/order-summary.fragment.graphql +15 -13
- package/templates/storefront-nextjs-shadcn/components/cart/cart-line.fragment.graphql +6 -6
- package/templates/storefront-nextjs-shadcn/components/discount/discount-code-input.tsx +10 -10
- package/templates/storefront-nextjs-shadcn/components/gift-card/gift-card-input.tsx +9 -9
- package/templates/storefront-nextjs-shadcn/components/order/delivery-estimate.tsx +2 -2
- package/templates/storefront-nextjs-shadcn/components/product/product-card.tsx +1 -1
- package/templates/storefront-nextjs-shadcn/components/seo/product-json-ld.ts +1 -1
- package/templates/storefront-nextjs-shadcn/hooks/use-auth-sync.ts +43 -25
- package/templates/storefront-nextjs-shadcn/hooks/use-cart-actions.ts +1 -1
- package/templates/storefront-nextjs-shadcn/hooks/use-cart-sync.ts +14 -14
- package/templates/storefront-nextjs-shadcn/lib/graphql/hooks.ts +101 -112
- package/templates/storefront-nextjs-shadcn/lib/graphql/query-keys.ts +2 -2
- package/templates/storefront-nextjs-shadcn/lib/graphql/server.ts +29 -12
- package/templates/storefront-nextjs-shadcn/lib/graphql/types.ts +1 -1
- package/templates/storefront-nextjs-shadcn/messages/en.json +6 -6
- package/templates/storefront-nextjs-shadcn/messages/pl.json +6 -6
- package/templates/storefront-nextjs-shadcn/package.json +4 -1
- package/templates/storefront-nextjs-shadcn/stores/checkout-store.ts +8 -8
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
CollectionsDocument,
|
|
17
17
|
CategoriesDocument,
|
|
18
18
|
CategoryDocument,
|
|
19
|
-
|
|
19
|
+
ProductFiltersDocument,
|
|
20
20
|
CartDocument,
|
|
21
21
|
CartCreateDocument,
|
|
22
22
|
CartLinesAddDocument,
|
|
@@ -25,16 +25,16 @@ import {
|
|
|
25
25
|
CartDiscountCodesUpdateDocument,
|
|
26
26
|
CheckoutDocument,
|
|
27
27
|
CheckoutCreateDocument,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
CheckoutUpdateShippingAddressDocument,
|
|
29
|
+
CheckoutUpdateBillingAddressDocument,
|
|
30
|
+
CheckoutUpdateEmailDocument,
|
|
31
|
+
CheckoutSelectShippingRateDocument,
|
|
32
|
+
CheckoutApplyDiscountCodeDocument,
|
|
33
|
+
CheckoutRemoveDiscountCodeDocument,
|
|
34
34
|
CheckoutCompleteDocument,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
CheckoutApplyGiftCardDocument,
|
|
36
|
+
CheckoutRemoveGiftCardDocument,
|
|
37
|
+
CheckoutUpdateGiftCardRecipientDocument,
|
|
38
38
|
CustomerDocument,
|
|
39
39
|
CustomerProfileDocument,
|
|
40
40
|
CustomerOrderDocument,
|
|
@@ -70,8 +70,8 @@ import type {
|
|
|
70
70
|
CategoryQueryVariables,
|
|
71
71
|
Category,
|
|
72
72
|
ProductFilterInput,
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
ProductFiltersQuery,
|
|
74
|
+
ProductFiltersQueryVariables,
|
|
75
75
|
AvailableFiltersInput,
|
|
76
76
|
CartQuery,
|
|
77
77
|
CartQueryVariables,
|
|
@@ -89,26 +89,26 @@ import type {
|
|
|
89
89
|
CheckoutQueryVariables,
|
|
90
90
|
CheckoutCreateMutation,
|
|
91
91
|
CheckoutCreateMutationVariables,
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
92
|
+
CheckoutUpdateShippingAddressMutation,
|
|
93
|
+
CheckoutUpdateShippingAddressMutationVariables,
|
|
94
|
+
CheckoutUpdateBillingAddressMutation,
|
|
95
|
+
CheckoutUpdateBillingAddressMutationVariables,
|
|
96
|
+
CheckoutUpdateEmailMutation,
|
|
97
|
+
CheckoutUpdateEmailMutationVariables,
|
|
98
|
+
CheckoutSelectShippingRateMutation,
|
|
99
|
+
CheckoutSelectShippingRateMutationVariables,
|
|
100
|
+
CheckoutApplyDiscountCodeMutation,
|
|
101
|
+
CheckoutApplyDiscountCodeMutationVariables,
|
|
102
|
+
CheckoutRemoveDiscountCodeMutation,
|
|
103
|
+
CheckoutRemoveDiscountCodeMutationVariables,
|
|
104
104
|
CheckoutCompleteMutation,
|
|
105
105
|
CheckoutCompleteMutationVariables,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
106
|
+
CheckoutApplyGiftCardMutation,
|
|
107
|
+
CheckoutApplyGiftCardMutationVariables,
|
|
108
|
+
CheckoutRemoveGiftCardMutation,
|
|
109
|
+
CheckoutRemoveGiftCardMutationVariables,
|
|
110
|
+
CheckoutUpdateGiftCardRecipientMutation,
|
|
111
|
+
CheckoutUpdateGiftCardRecipientMutationVariables,
|
|
112
112
|
CustomerQuery,
|
|
113
113
|
CustomerQueryVariables,
|
|
114
114
|
CustomerProfileQuery,
|
|
@@ -454,11 +454,11 @@ export function useCategories(
|
|
|
454
454
|
]);
|
|
455
455
|
};
|
|
456
456
|
|
|
457
|
-
const allCategories = flattenCategories(data.categories.
|
|
457
|
+
const allCategories = flattenCategories(data.categories.nodes as Category[]);
|
|
458
458
|
|
|
459
459
|
return {
|
|
460
460
|
categories: allCategories,
|
|
461
|
-
|
|
461
|
+
nodes: data.categories.nodes,
|
|
462
462
|
totalCount: data.categories.totalCount,
|
|
463
463
|
};
|
|
464
464
|
},
|
|
@@ -471,20 +471,20 @@ export function useCategories(
|
|
|
471
471
|
// ============================================================================
|
|
472
472
|
|
|
473
473
|
/**
|
|
474
|
-
* Fetch
|
|
474
|
+
* Fetch product filters for product listing (dynamic attributes, price range, categories).
|
|
475
475
|
* Context-aware: pass categoryId, collectionId, or searchQuery to scope filters.
|
|
476
476
|
*
|
|
477
477
|
* @example
|
|
478
478
|
* ```typescript
|
|
479
|
-
* const { data } =
|
|
480
|
-
* data?.
|
|
481
|
-
* data?.
|
|
482
|
-
* data?.
|
|
479
|
+
* const { data } = useProductFilters({ categoryId: 'some-id' });
|
|
480
|
+
* data?.productFilters.attributes // dynamic attribute filters with counts
|
|
481
|
+
* data?.productFilters.priceRange // { min, max } in context
|
|
482
|
+
* data?.productFilters.categories // category filters with counts
|
|
483
483
|
* ```
|
|
484
484
|
*/
|
|
485
|
-
export function
|
|
485
|
+
export function useProductFilters(
|
|
486
486
|
input?: AvailableFiltersInput,
|
|
487
|
-
options?: Omit<UseQueryOptions<
|
|
487
|
+
options?: Omit<UseQueryOptions<ProductFiltersQuery>, 'queryKey' | 'queryFn'>
|
|
488
488
|
) {
|
|
489
489
|
const execute = useExecute();
|
|
490
490
|
const currency = useCurrencyStore((s) => s.currency);
|
|
@@ -493,8 +493,8 @@ export function useAvailableFilters(
|
|
|
493
493
|
return useQuery({
|
|
494
494
|
queryKey: queryKeys.filters.forContext(input as Record<string, unknown>, currency, language),
|
|
495
495
|
queryFn: () => {
|
|
496
|
-
const variables:
|
|
497
|
-
return execute<
|
|
496
|
+
const variables: ProductFiltersQueryVariables = { input: input || null };
|
|
497
|
+
return execute<ProductFiltersQuery>(ProductFiltersDocument.toString(), variables);
|
|
498
498
|
},
|
|
499
499
|
staleTime: 60_000, // Filters change infrequently, cache for 1 min
|
|
500
500
|
...options,
|
|
@@ -694,15 +694,15 @@ export function useCheckoutCreate(
|
|
|
694
694
|
/**
|
|
695
695
|
* Update checkout shipping address
|
|
696
696
|
*/
|
|
697
|
-
export function
|
|
698
|
-
options?: UseMutationOptions<
|
|
697
|
+
export function useCheckoutUpdateShippingAddress(
|
|
698
|
+
options?: UseMutationOptions<CheckoutUpdateShippingAddressMutation, Error, CheckoutUpdateShippingAddressMutationVariables>
|
|
699
699
|
) {
|
|
700
700
|
const execute = useExecute();
|
|
701
701
|
const queryClient = useQueryClient();
|
|
702
702
|
|
|
703
703
|
return useMutation({
|
|
704
|
-
mutationFn: (variables:
|
|
705
|
-
execute<
|
|
704
|
+
mutationFn: (variables: CheckoutUpdateShippingAddressMutationVariables) =>
|
|
705
|
+
execute<CheckoutUpdateShippingAddressMutation>(CheckoutUpdateShippingAddressDocument.toString(), variables),
|
|
706
706
|
onMutate: async () => {
|
|
707
707
|
await queryClient.cancelQueries({ queryKey: queryKeys.checkout.all() });
|
|
708
708
|
},
|
|
@@ -716,15 +716,15 @@ export function useCheckoutShippingAddressUpdate(
|
|
|
716
716
|
/**
|
|
717
717
|
* Update checkout billing address
|
|
718
718
|
*/
|
|
719
|
-
export function
|
|
720
|
-
options?: UseMutationOptions<
|
|
719
|
+
export function useCheckoutUpdateBillingAddress(
|
|
720
|
+
options?: UseMutationOptions<CheckoutUpdateBillingAddressMutation, Error, CheckoutUpdateBillingAddressMutationVariables>
|
|
721
721
|
) {
|
|
722
722
|
const execute = useExecute();
|
|
723
723
|
const queryClient = useQueryClient();
|
|
724
724
|
|
|
725
725
|
return useMutation({
|
|
726
|
-
mutationFn: (variables:
|
|
727
|
-
execute<
|
|
726
|
+
mutationFn: (variables: CheckoutUpdateBillingAddressMutationVariables) =>
|
|
727
|
+
execute<CheckoutUpdateBillingAddressMutation>(CheckoutUpdateBillingAddressDocument.toString(), variables),
|
|
728
728
|
onMutate: async () => {
|
|
729
729
|
await queryClient.cancelQueries({ queryKey: queryKeys.checkout.all() });
|
|
730
730
|
},
|
|
@@ -738,15 +738,15 @@ export function useCheckoutBillingAddressUpdate(
|
|
|
738
738
|
/**
|
|
739
739
|
* Update checkout email
|
|
740
740
|
*/
|
|
741
|
-
export function
|
|
742
|
-
options?: UseMutationOptions<
|
|
741
|
+
export function useCheckoutUpdateEmail(
|
|
742
|
+
options?: UseMutationOptions<CheckoutUpdateEmailMutation, Error, CheckoutUpdateEmailMutationVariables>
|
|
743
743
|
) {
|
|
744
744
|
const execute = useExecute();
|
|
745
745
|
const queryClient = useQueryClient();
|
|
746
746
|
|
|
747
747
|
return useMutation({
|
|
748
|
-
mutationFn: (variables:
|
|
749
|
-
execute<
|
|
748
|
+
mutationFn: (variables: CheckoutUpdateEmailMutationVariables) =>
|
|
749
|
+
execute<CheckoutUpdateEmailMutation>(CheckoutUpdateEmailDocument.toString(), variables),
|
|
750
750
|
onMutate: async () => {
|
|
751
751
|
await queryClient.cancelQueries({ queryKey: queryKeys.checkout.all() });
|
|
752
752
|
},
|
|
@@ -760,15 +760,15 @@ export function useCheckoutEmailUpdate(
|
|
|
760
760
|
/**
|
|
761
761
|
* Update checkout shipping line (select shipping method)
|
|
762
762
|
*/
|
|
763
|
-
export function
|
|
764
|
-
options?: UseMutationOptions<
|
|
763
|
+
export function useCheckoutSelectShippingRate(
|
|
764
|
+
options?: UseMutationOptions<CheckoutSelectShippingRateMutation, Error, CheckoutSelectShippingRateMutationVariables>
|
|
765
765
|
) {
|
|
766
766
|
const execute = useExecute();
|
|
767
767
|
const queryClient = useQueryClient();
|
|
768
768
|
|
|
769
769
|
return useMutation({
|
|
770
|
-
mutationFn: (variables:
|
|
771
|
-
execute<
|
|
770
|
+
mutationFn: (variables: CheckoutSelectShippingRateMutationVariables) =>
|
|
771
|
+
execute<CheckoutSelectShippingRateMutation>(CheckoutSelectShippingRateDocument.toString(), variables),
|
|
772
772
|
onMutate: async () => {
|
|
773
773
|
await queryClient.cancelQueries({ queryKey: queryKeys.checkout.all() });
|
|
774
774
|
},
|
|
@@ -782,15 +782,15 @@ export function useCheckoutShippingLineUpdate(
|
|
|
782
782
|
/**
|
|
783
783
|
* Apply discount code to checkout
|
|
784
784
|
*/
|
|
785
|
-
export function
|
|
786
|
-
options?: UseMutationOptions<
|
|
785
|
+
export function useCheckoutApplyDiscountCode(
|
|
786
|
+
options?: UseMutationOptions<CheckoutApplyDiscountCodeMutation, Error, CheckoutApplyDiscountCodeMutationVariables>
|
|
787
787
|
) {
|
|
788
788
|
const execute = useExecute();
|
|
789
789
|
const queryClient = useQueryClient();
|
|
790
790
|
|
|
791
791
|
return useMutation({
|
|
792
|
-
mutationFn: (variables:
|
|
793
|
-
execute<
|
|
792
|
+
mutationFn: (variables: CheckoutApplyDiscountCodeMutationVariables) =>
|
|
793
|
+
execute<CheckoutApplyDiscountCodeMutation>(CheckoutApplyDiscountCodeDocument.toString(), variables),
|
|
794
794
|
onMutate: async () => {
|
|
795
795
|
await queryClient.cancelQueries({ queryKey: queryKeys.checkout.all() });
|
|
796
796
|
},
|
|
@@ -804,15 +804,15 @@ export function useCheckoutDiscountCodeApply(
|
|
|
804
804
|
/**
|
|
805
805
|
* Remove discount code from checkout
|
|
806
806
|
*/
|
|
807
|
-
export function
|
|
808
|
-
options?: UseMutationOptions<
|
|
807
|
+
export function useCheckoutRemoveDiscountCode(
|
|
808
|
+
options?: UseMutationOptions<CheckoutRemoveDiscountCodeMutation, Error, CheckoutRemoveDiscountCodeMutationVariables>
|
|
809
809
|
) {
|
|
810
810
|
const execute = useExecute();
|
|
811
811
|
const queryClient = useQueryClient();
|
|
812
812
|
|
|
813
813
|
return useMutation({
|
|
814
|
-
mutationFn: (variables:
|
|
815
|
-
execute<
|
|
814
|
+
mutationFn: (variables: CheckoutRemoveDiscountCodeMutationVariables) =>
|
|
815
|
+
execute<CheckoutRemoveDiscountCodeMutation>(CheckoutRemoveDiscountCodeDocument.toString(), variables),
|
|
816
816
|
onMutate: async () => {
|
|
817
817
|
await queryClient.cancelQueries({ queryKey: queryKeys.checkout.all() });
|
|
818
818
|
},
|
|
@@ -849,15 +849,15 @@ export function useCheckoutComplete(
|
|
|
849
849
|
/**
|
|
850
850
|
* Apply gift card code to checkout
|
|
851
851
|
*/
|
|
852
|
-
export function
|
|
853
|
-
options?: UseMutationOptions<
|
|
852
|
+
export function useCheckoutApplyGiftCard(
|
|
853
|
+
options?: UseMutationOptions<CheckoutApplyGiftCardMutation, Error, CheckoutApplyGiftCardMutationVariables>
|
|
854
854
|
) {
|
|
855
855
|
const execute = useExecute();
|
|
856
856
|
const queryClient = useQueryClient();
|
|
857
857
|
|
|
858
858
|
return useMutation({
|
|
859
|
-
mutationFn: (variables:
|
|
860
|
-
execute<
|
|
859
|
+
mutationFn: (variables: CheckoutApplyGiftCardMutationVariables) =>
|
|
860
|
+
execute<CheckoutApplyGiftCardMutation>(CheckoutApplyGiftCardDocument.toString(), variables),
|
|
861
861
|
onMutate: async () => {
|
|
862
862
|
await queryClient.cancelQueries({ queryKey: queryKeys.checkout.all() });
|
|
863
863
|
},
|
|
@@ -871,15 +871,15 @@ export function useCheckoutGiftCardApply(
|
|
|
871
871
|
/**
|
|
872
872
|
* Remove gift card from checkout
|
|
873
873
|
*/
|
|
874
|
-
export function
|
|
875
|
-
options?: UseMutationOptions<
|
|
874
|
+
export function useCheckoutRemoveGiftCard(
|
|
875
|
+
options?: UseMutationOptions<CheckoutRemoveGiftCardMutation, Error, CheckoutRemoveGiftCardMutationVariables>
|
|
876
876
|
) {
|
|
877
877
|
const execute = useExecute();
|
|
878
878
|
const queryClient = useQueryClient();
|
|
879
879
|
|
|
880
880
|
return useMutation({
|
|
881
|
-
mutationFn: (variables:
|
|
882
|
-
execute<
|
|
881
|
+
mutationFn: (variables: CheckoutRemoveGiftCardMutationVariables) =>
|
|
882
|
+
execute<CheckoutRemoveGiftCardMutation>(CheckoutRemoveGiftCardDocument.toString(), variables),
|
|
883
883
|
onMutate: async () => {
|
|
884
884
|
await queryClient.cancelQueries({ queryKey: queryKeys.checkout.all() });
|
|
885
885
|
},
|
|
@@ -893,15 +893,15 @@ export function useCheckoutGiftCardRemove(
|
|
|
893
893
|
/**
|
|
894
894
|
* Update gift card recipient data on checkout line item
|
|
895
895
|
*/
|
|
896
|
-
export function
|
|
897
|
-
options?: UseMutationOptions<
|
|
896
|
+
export function useCheckoutUpdateGiftCardRecipient(
|
|
897
|
+
options?: UseMutationOptions<CheckoutUpdateGiftCardRecipientMutation, Error, CheckoutUpdateGiftCardRecipientMutationVariables>
|
|
898
898
|
) {
|
|
899
899
|
const execute = useExecute();
|
|
900
900
|
const queryClient = useQueryClient();
|
|
901
901
|
|
|
902
902
|
return useMutation({
|
|
903
|
-
mutationFn: (variables:
|
|
904
|
-
execute<
|
|
903
|
+
mutationFn: (variables: CheckoutUpdateGiftCardRecipientMutationVariables) =>
|
|
904
|
+
execute<CheckoutUpdateGiftCardRecipientMutation>(CheckoutUpdateGiftCardRecipientDocument.toString(), variables),
|
|
905
905
|
onMutate: async () => {
|
|
906
906
|
await queryClient.cancelQueries({ queryKey: queryKeys.checkout.all() });
|
|
907
907
|
},
|
|
@@ -925,15 +925,14 @@ export function useCustomer(
|
|
|
925
925
|
options?: Omit<UseQueryOptions<CustomerQuery>, 'queryKey' | 'queryFn' | 'enabled'>
|
|
926
926
|
) {
|
|
927
927
|
const execute = useExecute();
|
|
928
|
-
|
|
928
|
+
// Token nie jest argumentem mutacji (auth context via httpOnly cookie / Bearer header).
|
|
929
|
+
// `isAuthenticated` flag (persisted) używamy do gate query — uniknąć round-trip dla guesta.
|
|
930
|
+
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
|
|
929
931
|
|
|
930
932
|
return useQuery({
|
|
931
|
-
queryKey: queryKeys.customer.detail(
|
|
932
|
-
queryFn: () =>
|
|
933
|
-
|
|
934
|
-
customerAccessToken: accessToken!,
|
|
935
|
-
} as CustomerQueryVariables),
|
|
936
|
-
enabled: !!accessToken,
|
|
933
|
+
queryKey: queryKeys.customer.detail(isAuthenticated ? 'me' : 'guest'),
|
|
934
|
+
queryFn: () => execute<CustomerQuery>(CustomerDocument.toString()),
|
|
935
|
+
enabled: isAuthenticated,
|
|
937
936
|
...options,
|
|
938
937
|
});
|
|
939
938
|
}
|
|
@@ -946,15 +945,12 @@ export function useCustomerProfile(
|
|
|
946
945
|
options?: Omit<UseQueryOptions<CustomerProfileQuery>, 'queryKey' | 'queryFn' | 'enabled'>
|
|
947
946
|
) {
|
|
948
947
|
const execute = useExecute();
|
|
949
|
-
const
|
|
948
|
+
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
|
|
950
949
|
|
|
951
950
|
return useQuery({
|
|
952
|
-
queryKey: queryKeys.customer.detail(
|
|
953
|
-
queryFn: () =>
|
|
954
|
-
|
|
955
|
-
customerAccessToken: accessToken!,
|
|
956
|
-
} as CustomerProfileQueryVariables),
|
|
957
|
-
enabled: !!accessToken,
|
|
951
|
+
queryKey: queryKeys.customer.detail(isAuthenticated ? 'me' : 'guest'),
|
|
952
|
+
queryFn: () => execute<CustomerProfileQuery>(CustomerProfileDocument.toString()),
|
|
953
|
+
enabled: isAuthenticated,
|
|
958
954
|
...options,
|
|
959
955
|
});
|
|
960
956
|
}
|
|
@@ -968,7 +964,7 @@ export function useCustomerOrder(
|
|
|
968
964
|
options?: Omit<UseQueryOptions<CustomerOrderQuery>, 'queryKey' | 'queryFn' | 'enabled'>
|
|
969
965
|
) {
|
|
970
966
|
const execute = useExecute();
|
|
971
|
-
const
|
|
967
|
+
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
|
|
972
968
|
const currency = useCurrencyStore((s) => s.currency);
|
|
973
969
|
|
|
974
970
|
return useQuery({
|
|
@@ -976,9 +972,8 @@ export function useCustomerOrder(
|
|
|
976
972
|
queryFn: () =>
|
|
977
973
|
execute<CustomerOrderQuery>(CustomerOrderDocument.toString(), {
|
|
978
974
|
orderId,
|
|
979
|
-
customerAccessToken: accessToken!,
|
|
980
975
|
} as CustomerOrderQueryVariables),
|
|
981
|
-
enabled:
|
|
976
|
+
enabled: isAuthenticated && !!orderId,
|
|
982
977
|
...options,
|
|
983
978
|
});
|
|
984
979
|
}
|
|
@@ -991,14 +986,12 @@ export function useCustomerUpdate(
|
|
|
991
986
|
options?: UseMutationOptions<CustomerUpdateMutation, Error, CustomerUpdateInput>
|
|
992
987
|
) {
|
|
993
988
|
const execute = useExecute();
|
|
994
|
-
const { accessToken } = useAuthStore();
|
|
995
989
|
const queryClient = useQueryClient();
|
|
996
990
|
|
|
997
991
|
return useMutation({
|
|
998
992
|
mutationFn: (customer: CustomerUpdateInput) =>
|
|
999
993
|
execute<CustomerUpdateMutation>(CustomerUpdateDocument.toString(), {
|
|
1000
994
|
customer,
|
|
1001
|
-
customerAccessToken: accessToken!,
|
|
1002
995
|
} as CustomerUpdateMutationVariables),
|
|
1003
996
|
onSettled: () => {
|
|
1004
997
|
queryClient.invalidateQueries({ queryKey: queryKeys.customer.all() });
|
|
@@ -1014,14 +1007,13 @@ export function useCustomerAddressCreate(
|
|
|
1014
1007
|
options?: UseMutationOptions<CustomerAddressCreateMutation, Error, { address: Record<string, unknown> }>
|
|
1015
1008
|
) {
|
|
1016
1009
|
const execute = useExecute();
|
|
1017
|
-
const { accessToken } = useAuthStore();
|
|
1018
1010
|
const queryClient = useQueryClient();
|
|
1019
1011
|
|
|
1020
1012
|
return useMutation({
|
|
1021
1013
|
mutationFn: ({ address }: { address: Record<string, unknown> }) =>
|
|
1022
1014
|
execute<CustomerAddressCreateMutation>(
|
|
1023
1015
|
CustomerAddressCreateDocument.toString(),
|
|
1024
|
-
{ address
|
|
1016
|
+
{ address } as CustomerAddressCreateMutationVariables,
|
|
1025
1017
|
),
|
|
1026
1018
|
onSettled: () => {
|
|
1027
1019
|
queryClient.invalidateQueries({ queryKey: queryKeys.customer.all() });
|
|
@@ -1037,14 +1029,13 @@ export function useCustomerAddressUpdate(
|
|
|
1037
1029
|
options?: UseMutationOptions<CustomerAddressUpdateMutation, Error, { id: string; address: Record<string, unknown> }>
|
|
1038
1030
|
) {
|
|
1039
1031
|
const execute = useExecute();
|
|
1040
|
-
const { accessToken } = useAuthStore();
|
|
1041
1032
|
const queryClient = useQueryClient();
|
|
1042
1033
|
|
|
1043
1034
|
return useMutation({
|
|
1044
1035
|
mutationFn: ({ id, address }: { id: string; address: Record<string, unknown> }) =>
|
|
1045
1036
|
execute<CustomerAddressUpdateMutation>(
|
|
1046
1037
|
CustomerAddressUpdateDocument.toString(),
|
|
1047
|
-
{ id, address
|
|
1038
|
+
{ id, address } as CustomerAddressUpdateMutationVariables,
|
|
1048
1039
|
),
|
|
1049
1040
|
onSettled: () => {
|
|
1050
1041
|
queryClient.invalidateQueries({ queryKey: queryKeys.customer.all() });
|
|
@@ -1060,14 +1051,13 @@ export function useCustomerAddressDelete(
|
|
|
1060
1051
|
options?: UseMutationOptions<CustomerAddressDeleteMutation, Error, string>
|
|
1061
1052
|
) {
|
|
1062
1053
|
const execute = useExecute();
|
|
1063
|
-
const { accessToken } = useAuthStore();
|
|
1064
1054
|
const queryClient = useQueryClient();
|
|
1065
1055
|
|
|
1066
1056
|
return useMutation({
|
|
1067
1057
|
mutationFn: (id: string) =>
|
|
1068
1058
|
execute<CustomerAddressDeleteMutation>(
|
|
1069
1059
|
CustomerAddressDeleteDocument.toString(),
|
|
1070
|
-
{ id
|
|
1060
|
+
{ id } as CustomerAddressDeleteMutationVariables,
|
|
1071
1061
|
),
|
|
1072
1062
|
onSettled: () => {
|
|
1073
1063
|
queryClient.invalidateQueries({ queryKey: queryKeys.customer.all() });
|
|
@@ -1083,14 +1073,13 @@ export function useCustomerDefaultAddressUpdate(
|
|
|
1083
1073
|
options?: UseMutationOptions<CustomerDefaultAddressUpdateMutation, Error, string>
|
|
1084
1074
|
) {
|
|
1085
1075
|
const execute = useExecute();
|
|
1086
|
-
const { accessToken } = useAuthStore();
|
|
1087
1076
|
const queryClient = useQueryClient();
|
|
1088
1077
|
|
|
1089
1078
|
return useMutation({
|
|
1090
1079
|
mutationFn: (addressId: string) =>
|
|
1091
1080
|
execute<CustomerDefaultAddressUpdateMutation>(
|
|
1092
1081
|
CustomerDefaultAddressUpdateDocument.toString(),
|
|
1093
|
-
{ addressId
|
|
1082
|
+
{ addressId } as CustomerDefaultAddressUpdateMutationVariables,
|
|
1094
1083
|
),
|
|
1095
1084
|
onSettled: () => {
|
|
1096
1085
|
queryClient.invalidateQueries({ queryKey: queryKeys.customer.all() });
|
|
@@ -1144,13 +1133,13 @@ export function useLoyaltyMember(
|
|
|
1144
1133
|
options?: Omit<UseQueryOptions<LoyaltyMemberQuery>, 'queryKey' | 'queryFn' | 'enabled'>
|
|
1145
1134
|
) {
|
|
1146
1135
|
const execute = useExecute();
|
|
1147
|
-
const
|
|
1136
|
+
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
|
|
1148
1137
|
const currency = useCurrencyStore((s) => s.currency);
|
|
1149
1138
|
|
|
1150
1139
|
return useQuery({
|
|
1151
1140
|
queryKey: queryKeys.loyalty.member(currency),
|
|
1152
1141
|
queryFn: () => execute<LoyaltyMemberQuery>(LoyaltyMemberDocument.toString()),
|
|
1153
|
-
enabled:
|
|
1142
|
+
enabled: isAuthenticated,
|
|
1154
1143
|
...options,
|
|
1155
1144
|
});
|
|
1156
1145
|
}
|
|
@@ -1162,13 +1151,13 @@ export function useLoyaltyRewards(
|
|
|
1162
1151
|
options?: Omit<UseQueryOptions<LoyaltyRewardsQuery>, 'queryKey' | 'queryFn' | 'enabled'>
|
|
1163
1152
|
) {
|
|
1164
1153
|
const execute = useExecute();
|
|
1165
|
-
const
|
|
1154
|
+
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
|
|
1166
1155
|
const currency = useCurrencyStore((s) => s.currency);
|
|
1167
1156
|
|
|
1168
1157
|
return useQuery({
|
|
1169
1158
|
queryKey: queryKeys.loyalty.rewards(currency),
|
|
1170
1159
|
queryFn: () => execute<LoyaltyRewardsQuery>(LoyaltyRewardsDocument.toString()),
|
|
1171
|
-
enabled:
|
|
1160
|
+
enabled: isAuthenticated,
|
|
1172
1161
|
...options,
|
|
1173
1162
|
});
|
|
1174
1163
|
}
|
|
@@ -1181,7 +1170,7 @@ export function useLoyaltyTransactions(
|
|
|
1181
1170
|
options?: Omit<UseQueryOptions<LoyaltyTransactionsQuery>, 'queryKey' | 'queryFn' | 'enabled'>
|
|
1182
1171
|
) {
|
|
1183
1172
|
const execute = useExecute();
|
|
1184
|
-
const
|
|
1173
|
+
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
|
|
1185
1174
|
const currency = useCurrencyStore((s) => s.currency);
|
|
1186
1175
|
|
|
1187
1176
|
return useQuery({
|
|
@@ -1193,7 +1182,7 @@ export function useLoyaltyTransactions(
|
|
|
1193
1182
|
};
|
|
1194
1183
|
return execute<LoyaltyTransactionsQuery>(LoyaltyTransactionsDocument.toString(), graphqlVariables);
|
|
1195
1184
|
},
|
|
1196
|
-
enabled:
|
|
1185
|
+
enabled: isAuthenticated,
|
|
1197
1186
|
...options,
|
|
1198
1187
|
});
|
|
1199
1188
|
}
|
|
@@ -1220,12 +1209,12 @@ export function useReferralStats(
|
|
|
1220
1209
|
options?: Omit<UseQueryOptions<ReferralStatsQuery>, 'queryKey' | 'queryFn' | 'enabled'>
|
|
1221
1210
|
) {
|
|
1222
1211
|
const execute = useExecute();
|
|
1223
|
-
const
|
|
1212
|
+
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
|
|
1224
1213
|
|
|
1225
1214
|
return useQuery({
|
|
1226
1215
|
queryKey: queryKeys.loyalty.referralStats(),
|
|
1227
1216
|
queryFn: () => execute<ReferralStatsQuery>(ReferralStatsDocument.toString()),
|
|
1228
|
-
enabled:
|
|
1217
|
+
enabled: isAuthenticated,
|
|
1229
1218
|
...options,
|
|
1230
1219
|
});
|
|
1231
1220
|
}
|
|
@@ -54,9 +54,9 @@ export const queryKeys = {
|
|
|
54
54
|
},
|
|
55
55
|
|
|
56
56
|
filters: {
|
|
57
|
-
all: () => ['
|
|
57
|
+
all: () => ['ProductFilters'] as const,
|
|
58
58
|
forContext: (input?: Record<string, unknown> | null, currency?: Currency, language?: Language) =>
|
|
59
|
-
['
|
|
59
|
+
['ProductFilters', input, currency, language] as const,
|
|
60
60
|
},
|
|
61
61
|
|
|
62
62
|
cart: {
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
CollectionDocument,
|
|
16
16
|
CategoriesDocument,
|
|
17
17
|
CategoryDocument,
|
|
18
|
-
|
|
18
|
+
ProductFiltersDocument,
|
|
19
19
|
CustomerDocument,
|
|
20
20
|
} from '@/generated/graphql';
|
|
21
21
|
|
|
@@ -35,8 +35,8 @@ import type {
|
|
|
35
35
|
CategoriesQuery,
|
|
36
36
|
CategoryQuery,
|
|
37
37
|
CategoryQueryVariables,
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
ProductFiltersQuery,
|
|
39
|
+
ProductFiltersQueryVariables,
|
|
40
40
|
AvailableFiltersInput,
|
|
41
41
|
CustomerQuery,
|
|
42
42
|
CustomerQueryVariables,
|
|
@@ -193,21 +193,38 @@ export const fetchCategory = cache(async (slugOrId: string): Promise<CategoryQue
|
|
|
193
193
|
});
|
|
194
194
|
|
|
195
195
|
/**
|
|
196
|
-
* Fetch
|
|
196
|
+
* Fetch product filters for product listing (SSR)
|
|
197
197
|
*/
|
|
198
|
-
export const
|
|
198
|
+
export const fetchProductFilters = cache(async (
|
|
199
199
|
input?: AvailableFiltersInput,
|
|
200
|
-
): Promise<
|
|
201
|
-
const variables:
|
|
202
|
-
return request(
|
|
200
|
+
): Promise<ProductFiltersQuery> => {
|
|
201
|
+
const variables: ProductFiltersQueryVariables = { input: input || null };
|
|
202
|
+
return request(ProductFiltersDocument, variables);
|
|
203
203
|
});
|
|
204
204
|
|
|
205
205
|
/**
|
|
206
|
-
* Fetch customer data (requires
|
|
206
|
+
* Fetch customer data (requires authenticated session — httpOnly cookie OR explicit Bearer token).
|
|
207
|
+
*
|
|
208
|
+
* Server Components: czytaj `customerAccessToken` cookie via Next.js `cookies()` API,
|
|
209
|
+
* forward jako `Authorization: Bearer` do backend. Klient nie ma JS-access do cookie
|
|
210
|
+
* (XSS-safe), ale Next.js server może go odczytać via `cookies().get()`.
|
|
211
|
+
*
|
|
212
|
+
* @param accessToken Optional — gdy SSR helper ma już token (np. po login redirect SSR);
|
|
213
|
+
* domyślnie czyta z `cookies()` (App Router).
|
|
207
214
|
*/
|
|
208
|
-
export const fetchCustomer = cache(async (accessToken
|
|
209
|
-
|
|
210
|
-
|
|
215
|
+
export const fetchCustomer = cache(async (accessToken?: string): Promise<CustomerQuery> => {
|
|
216
|
+
let token = accessToken;
|
|
217
|
+
if (!token) {
|
|
218
|
+
const { cookies } = await import('next/headers');
|
|
219
|
+
const cookieStore = await cookies();
|
|
220
|
+
token = cookieStore.get('customerAccessToken')?.value;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return request(
|
|
224
|
+
CustomerDocument,
|
|
225
|
+
{} as CustomerQueryVariables,
|
|
226
|
+
token ? { Authorization: `Bearer ${token}` } : undefined,
|
|
227
|
+
);
|
|
211
228
|
});
|
|
212
229
|
|
|
213
230
|
// ============================================================================
|
|
@@ -241,15 +241,15 @@
|
|
|
241
241
|
"firstName": "First Name",
|
|
242
242
|
"lastName": "Last Name",
|
|
243
243
|
"company": "Company",
|
|
244
|
-
"
|
|
245
|
-
"
|
|
246
|
-
"
|
|
247
|
-
"
|
|
248
|
-
"
|
|
244
|
+
"streetLine1": "Address",
|
|
245
|
+
"streetLine1Placeholder": "Street and number",
|
|
246
|
+
"streetLine2": "Apartment, floor",
|
|
247
|
+
"postalCode": "Postal Code",
|
|
248
|
+
"postalCodePlaceholder": "00000",
|
|
249
249
|
"city": "City",
|
|
250
250
|
"country": "Country",
|
|
251
251
|
"countryPlaceholder": "Select country",
|
|
252
|
-
"
|
|
252
|
+
"state": "State/Province",
|
|
253
253
|
"phone": "Phone"
|
|
254
254
|
},
|
|
255
255
|
"validation": {
|
|
@@ -241,15 +241,15 @@
|
|
|
241
241
|
"firstName": "Imię",
|
|
242
242
|
"lastName": "Nazwisko",
|
|
243
243
|
"company": "Firma",
|
|
244
|
-
"
|
|
245
|
-
"
|
|
246
|
-
"
|
|
247
|
-
"
|
|
248
|
-
"
|
|
244
|
+
"streetLine1": "Adres",
|
|
245
|
+
"streetLine1Placeholder": "Ulica i numer",
|
|
246
|
+
"streetLine2": "Mieszkanie, piętro",
|
|
247
|
+
"postalCode": "Kod pocztowy",
|
|
248
|
+
"postalCodePlaceholder": "00-000",
|
|
249
249
|
"city": "Miasto",
|
|
250
250
|
"country": "Kraj",
|
|
251
251
|
"countryPlaceholder": "Wybierz kraj",
|
|
252
|
-
"
|
|
252
|
+
"state": "Województwo",
|
|
253
253
|
"phone": "Telefon"
|
|
254
254
|
},
|
|
255
255
|
"validation": {
|