@q2devel/q2-core 1.0.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/dist/api/cart/Cart.service.d.ts +27 -0
- package/dist/api/cart/Cart.service.d.ts.map +1 -0
- package/dist/api/cart/Cart.service.js +205 -0
- package/dist/api/cart/CartService.types.d.ts +156 -0
- package/dist/api/cart/CartService.types.d.ts.map +1 -0
- package/dist/api/cart/CartService.types.js +1 -0
- package/dist/api/checkout/Checkout.service.d.ts +10 -0
- package/dist/api/checkout/Checkout.service.d.ts.map +1 -0
- package/dist/api/checkout/Checkout.service.js +31 -0
- package/dist/api/checkout/CheckoutService.types.d.ts +57 -0
- package/dist/api/checkout/CheckoutService.types.d.ts.map +1 -0
- package/dist/api/checkout/CheckoutService.types.js +1 -0
- package/dist/api/content/getBanners.d.ts +9 -0
- package/dist/api/content/getBanners.d.ts.map +1 -0
- package/dist/api/content/getBanners.js +32 -0
- package/dist/api/content/getBlog.d.ts +11 -0
- package/dist/api/content/getBlog.d.ts.map +1 -0
- package/dist/api/content/getBlog.js +43 -0
- package/dist/api/getTerms.d.ts +10 -0
- package/dist/api/getTerms.d.ts.map +1 -0
- package/dist/api/getTerms.js +38 -0
- package/dist/api/products/getProducts.d.ts +27 -0
- package/dist/api/products/getProducts.d.ts.map +1 -0
- package/dist/api/products/getProducts.js +125 -0
- package/dist/api/user/getUserCart.d.ts +1 -0
- package/dist/api/user/getUserCart.d.ts.map +1 -0
- package/dist/api/user/getUserCart.js +1 -0
- package/dist/api/user/resetPassword.d.ts +8 -0
- package/dist/api/user/resetPassword.d.ts.map +1 -0
- package/dist/api/user/resetPassword.js +4 -0
- package/dist/api/wishlist/Wishlist.service.d.ts +12 -0
- package/dist/api/wishlist/Wishlist.service.d.ts.map +1 -0
- package/dist/api/wishlist/Wishlist.service.js +73 -0
- package/dist/api/wishlist/WishlistService.types.d.ts +77 -0
- package/dist/api/wishlist/WishlistService.types.d.ts.map +1 -0
- package/dist/api/wishlist/WishlistService.types.js +1 -0
- package/dist/context/cart/BasketContext.d.ts +38 -0
- package/dist/context/cart/BasketContext.d.ts.map +1 -0
- package/dist/context/cart/BasketContext.js +408 -0
- package/dist/context.d.ts +14 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +1 -0
- package/dist/hooks/cart/api/useAddToCart.d.ts +4 -0
- package/dist/hooks/cart/api/useAddToCart.d.ts.map +1 -0
- package/dist/hooks/cart/api/useAddToCart.js +17 -0
- package/dist/hooks/cart/api/useClearCart.d.ts +5 -0
- package/dist/hooks/cart/api/useClearCart.d.ts.map +1 -0
- package/dist/hooks/cart/api/useClearCart.js +17 -0
- package/dist/hooks/cart/api/useDeleteCartItem.d.ts +7 -0
- package/dist/hooks/cart/api/useDeleteCartItem.d.ts.map +1 -0
- package/dist/hooks/cart/api/useDeleteCartItem.js +24 -0
- package/dist/hooks/cart/api/useGetCartToken.d.ts +177 -0
- package/dist/hooks/cart/api/useGetCartToken.d.ts.map +1 -0
- package/dist/hooks/cart/api/useGetCartToken.js +42 -0
- package/dist/hooks/cart/api/useGetCurrentCart.d.ts +9 -0
- package/dist/hooks/cart/api/useGetCurrentCart.d.ts.map +1 -0
- package/dist/hooks/cart/api/useGetCurrentCart.js +13 -0
- package/dist/hooks/cart/api/useGetUserCart.d.ts +4 -0
- package/dist/hooks/cart/api/useGetUserCart.d.ts.map +1 -0
- package/dist/hooks/cart/api/useGetUserCart.js +14 -0
- package/dist/hooks/cart/api/useUpdateCart.d.ts +10 -0
- package/dist/hooks/cart/api/useUpdateCart.d.ts.map +1 -0
- package/dist/hooks/cart/api/useUpdateCart.js +22 -0
- package/dist/hooks/checkout/useUpdateCheckout.d.ts +7 -0
- package/dist/hooks/checkout/useUpdateCheckout.d.ts.map +1 -0
- package/dist/hooks/checkout/useUpdateCheckout.js +15 -0
- package/dist/hooks/wishlist/api/useAddToWishlist.d.ts +4 -0
- package/dist/hooks/wishlist/api/useAddToWishlist.d.ts.map +1 -0
- package/dist/hooks/wishlist/api/useAddToWishlist.js +12 -0
- package/dist/hooks/wishlist/api/useCreateWishlist.d.ts +4 -0
- package/dist/hooks/wishlist/api/useCreateWishlist.d.ts.map +1 -0
- package/dist/hooks/wishlist/api/useCreateWishlist.js +15 -0
- package/dist/hooks/wishlist/api/useDeleteWishlist.d.ts +4 -0
- package/dist/hooks/wishlist/api/useDeleteWishlist.d.ts.map +1 -0
- package/dist/hooks/wishlist/api/useDeleteWishlist.js +16 -0
- package/dist/hooks/wishlist/api/useDeleteWishlistItem.d.ts +4 -0
- package/dist/hooks/wishlist/api/useDeleteWishlistItem.d.ts.map +1 -0
- package/dist/hooks/wishlist/api/useDeleteWishlistItem.js +11 -0
- package/dist/hooks/wishlist/api/useGetWishlistItems.d.ts +3 -0
- package/dist/hooks/wishlist/api/useGetWishlistItems.d.ts.map +1 -0
- package/dist/hooks/wishlist/api/useGetWishlistItems.js +9 -0
- package/dist/hooks/wishlist/api/useGetWishlistList.d.ts +4 -0
- package/dist/hooks/wishlist/api/useGetWishlistList.d.ts.map +1 -0
- package/dist/hooks/wishlist/api/useGetWishlistList.js +13 -0
- package/dist/hooks/wishlist/useWishlist.d.ts +22 -0
- package/dist/hooks/wishlist/useWishlist.d.ts.map +1 -0
- package/dist/hooks/wishlist/useWishlist.js +202 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/types/ResetPassword.d.ts +8 -0
- package/dist/types/ResetPassword.d.ts.map +1 -0
- package/dist/types/ResetPassword.js +1 -0
- package/dist/types/Term.d.ts +15 -0
- package/dist/types/Term.d.ts.map +1 -0
- package/dist/types/Term.js +1 -0
- package/dist/types/content/Banners.d.ts +14 -0
- package/dist/types/content/Banners.d.ts.map +1 -0
- package/dist/types/content/Banners.js +1 -0
- package/dist/types/content/Blog.d.ts +12 -0
- package/dist/types/content/Blog.d.ts.map +1 -0
- package/dist/types/content/Blog.js +1 -0
- package/dist/types/content/ResetPassword.d.ts +8 -0
- package/dist/types/content/ResetPassword.d.ts.map +1 -0
- package/dist/types/content/ResetPassword.js +1 -0
- package/dist/types/products/Product.d.ts +69 -0
- package/dist/types/products/Product.d.ts.map +1 -0
- package/dist/types/products/Product.js +1 -0
- package/dist/types/user/ResetPassword.d.ts +8 -0
- package/dist/types/user/ResetPassword.d.ts.map +1 -0
- package/dist/types/user/ResetPassword.js +1 -0
- package/dist/types/wishlist/Wishlist.d.ts +31 -0
- package/dist/types/wishlist/Wishlist.d.ts.map +1 -0
- package/dist/types/wishlist/Wishlist.js +1 -0
- package/dist/utils/generalHelper.d.ts +12 -0
- package/dist/utils/generalHelper.d.ts.map +1 -0
- package/dist/utils/generalHelper.js +37 -0
- package/dist/utils/mapIncludedResources.d.ts +21 -0
- package/dist/utils/mapIncludedResources.d.ts.map +1 -0
- package/dist/utils/mapIncludedResources.js +37 -0
- package/package.json +31 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { CoreContext } from '../../context';
|
|
3
|
+
import { AddToCartRequest, AddToCartResponse, Cart, CartItem, DeleteCartItemRequest, UpdateCartItemRequest } from './CartService.types';
|
|
4
|
+
export declare const getUserCart: (ctx: CoreContext, config?: AxiosRequestConfig) => Promise<Cart>;
|
|
5
|
+
export declare const getCurrentCart: (ctx: CoreContext, activeToken: string, config?: AxiosRequestConfig) => Promise<Cart>;
|
|
6
|
+
export declare const addToCart: (ctx: CoreContext, activeToken: string | undefined, request: AddToCartRequest, config?: AxiosRequestConfig) => Promise<AddToCartResponse>;
|
|
7
|
+
export declare const updateCartItem: (ctx: CoreContext, orderId: string, itemId: string, request: UpdateCartItemRequest, config?: AxiosRequestConfig) => Promise<CartItem>;
|
|
8
|
+
export declare const deleteCartItem: (ctx: CoreContext, orderId: string, request: DeleteCartItemRequest, config?: AxiosRequestConfig) => Promise<void>;
|
|
9
|
+
export declare const clearCart: (ctx: CoreContext, cartId: string, config?: AxiosRequestConfig) => Promise<void>;
|
|
10
|
+
export declare const applyCoupon: (ctx: CoreContext, cartId: string, couponCode: string, config?: AxiosRequestConfig) => Promise<Cart>;
|
|
11
|
+
export declare const removeCoupon: (ctx: CoreContext, cartId: string, couponId: string, config?: AxiosRequestConfig) => Promise<void>;
|
|
12
|
+
export declare const getCartToken: (ctx: CoreContext, config?: AxiosRequestConfig) => Promise<string>;
|
|
13
|
+
export type OrderHistoryResponse = {
|
|
14
|
+
data: Array<{
|
|
15
|
+
id: string;
|
|
16
|
+
drupalOrderId: number;
|
|
17
|
+
cartItems: CartItem[];
|
|
18
|
+
total: {
|
|
19
|
+
number: string;
|
|
20
|
+
currency_code: string;
|
|
21
|
+
formatted: string;
|
|
22
|
+
};
|
|
23
|
+
completed: string;
|
|
24
|
+
}>;
|
|
25
|
+
};
|
|
26
|
+
export declare const getOrderHistory: (ctx: CoreContext, config?: AxiosRequestConfig) => Promise<OrderHistoryResponse>;
|
|
27
|
+
//# sourceMappingURL=Cart.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cart.service.d.ts","sourceRoot":"","sources":["../../../api/cart/Cart.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAG3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,IAAI,EACJ,QAAQ,EACR,qBAAqB,EAErB,qBAAqB,EACtB,MAAM,qBAAqB,CAAC;AAQ7B,eAAO,MAAM,WAAW,GACtB,KAAK,WAAW,EAChB,SAAQ,kBAAuB,KAC9B,OAAO,CAAC,IAAI,CAkEd,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,KAAK,WAAW,EAChB,aAAa,MAAM,EACnB,SAAQ,kBAAuB,KAC9B,OAAO,CAAC,IAAI,CA0Dd,CAAC;AAEF,eAAO,MAAM,SAAS,GACpB,KAAK,WAAW,EAChB,a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AAC;AAEF,eAAO,MAAM,eAAe,GAC1B,KAAK,WAAW,EAChB,SAAQ,kBAAuB,KAC9B,OAAO,CAAC,oBAAoB,CA8C9B,CAAC"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
|
|
2
|
+
import { mapIncludedResources } from '../../utils/mapIncludedResources';
|
|
3
|
+
const getHeaders = (ctx, customHeaders = {}) => ({
|
|
4
|
+
'Content-Type': 'application/vnd.api+json',
|
|
5
|
+
...(ctx.accessToken && { Authorization: `Bearer ${ctx.accessToken}` }),
|
|
6
|
+
...customHeaders,
|
|
7
|
+
});
|
|
8
|
+
export const getUserCart = async (ctx, config = {}) => {
|
|
9
|
+
if (!ctx.userId)
|
|
10
|
+
throw new Error('Missing userId in context');
|
|
11
|
+
const params = new DrupalJsonApiParams()
|
|
12
|
+
.addFilter('state', 'draft')
|
|
13
|
+
.addFilter('uid.meta', ctx.userId)
|
|
14
|
+
.addInclude([
|
|
15
|
+
'order_items',
|
|
16
|
+
'order_items.purchased_entity',
|
|
17
|
+
'order_items.purchased_entity.product_id',
|
|
18
|
+
'order_items.purchased_entity.product_id.field_image',
|
|
19
|
+
'order_items.purchased_entity.product_id.field_image.field_media_image',
|
|
20
|
+
]);
|
|
21
|
+
const { data } = await ctx.axios.get(`/jsonapi/commerce_order/default?${params.getQueryString()}`, { ...config, headers: getHeaders(ctx, config.headers) });
|
|
22
|
+
if (!data.data || (Array.isArray(data.data) && data.data.length === 0)) {
|
|
23
|
+
return {
|
|
24
|
+
data: {
|
|
25
|
+
id: '',
|
|
26
|
+
drupalOrderId: 0,
|
|
27
|
+
cartItems: [],
|
|
28
|
+
total: { number: '0', currency_code: 'CZK', formatted: '0 Kč' },
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const resolvedOrders = mapIncludedResources(data, 5);
|
|
33
|
+
const orderData = Array.isArray(resolvedOrders) ? resolvedOrders[0] : resolvedOrders;
|
|
34
|
+
const cartItems = (orderData.order_items || []).map((item) => {
|
|
35
|
+
const defaultProduct = item.purchased_entity?.product_id || {};
|
|
36
|
+
const variationProduct = defaultProduct?.default_variation || {};
|
|
37
|
+
const images = defaultProduct?.field_image || [];
|
|
38
|
+
return {
|
|
39
|
+
variation_id: variationProduct.drupal_internal__variation_id,
|
|
40
|
+
variation_uuid: variationProduct.id,
|
|
41
|
+
drupalOrderItemId: item.drupal_internal__order_item_id || 0,
|
|
42
|
+
type: variationProduct.type,
|
|
43
|
+
variation_name: variationProduct.title || '',
|
|
44
|
+
images: images.length
|
|
45
|
+
? images.map((img) => ({
|
|
46
|
+
href: ctx.makeAbsoluteUrl(img.field_media_image?.uri?.url),
|
|
47
|
+
alt: img.name,
|
|
48
|
+
}))
|
|
49
|
+
: [{ href: '/q2_logo.png', alt: 'Q2' }],
|
|
50
|
+
price: parseFloat(item.unit_price?.number || '0'),
|
|
51
|
+
quantity: parseFloat(item.quantity || '0'),
|
|
52
|
+
product_name: defaultProduct.title || '',
|
|
53
|
+
product_id: defaultProduct.drupal_internal__product_id || '',
|
|
54
|
+
order_item_id: item.id || '',
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
data: {
|
|
59
|
+
id: orderData.id || '',
|
|
60
|
+
drupalOrderId: orderData.drupal_internal__order_id || 0,
|
|
61
|
+
cartItems,
|
|
62
|
+
total: orderData.total_price || { number: '0', currency_code: 'CZK', formatted: '0 Kč' },
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
export const getCurrentCart = async (ctx, activeToken, config = {}) => {
|
|
67
|
+
if (!activeToken)
|
|
68
|
+
throw new Error('Missing activeToken in context');
|
|
69
|
+
const { data } = await ctx.axios.get(`/jsonapi/carts?cartToken=${activeToken}&include=order_items,order_items.purchased_entity,order_items.purchased_entity.product_id,order_items.purchased_entity.product_id.field_image,order_items.purchased_entity.product_id.field_image.field_media_image`, { ...config, headers: getHeaders(ctx, config.headers) });
|
|
70
|
+
console.log('getCurrentCart data:', data);
|
|
71
|
+
console.log('getCurrentCart config:', activeToken);
|
|
72
|
+
if (!data.data || data.data.length === 0) {
|
|
73
|
+
return {
|
|
74
|
+
data: {
|
|
75
|
+
id: '',
|
|
76
|
+
drupalOrderId: 0,
|
|
77
|
+
cartItems: [],
|
|
78
|
+
total: { number: '0', currency_code: 'CZK', formatted: '0 Kč' },
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const resolvedOrders = mapIncludedResources(data, 5);
|
|
83
|
+
const orderData = resolvedOrders[0];
|
|
84
|
+
const cartItems = (orderData.order_items || []).map((item) => {
|
|
85
|
+
const defaultProduct = item.purchased_entity?.product_id || {};
|
|
86
|
+
const variationProduct = defaultProduct?.default_variation || {};
|
|
87
|
+
const images = defaultProduct?.field_image || [];
|
|
88
|
+
return {
|
|
89
|
+
variation_id: variationProduct.drupal_internal__variation_id,
|
|
90
|
+
variation_uuid: variationProduct.id,
|
|
91
|
+
drupalOrderItemId: item.drupal_internal__order_item_id || 0,
|
|
92
|
+
type: variationProduct.type,
|
|
93
|
+
variation_name: variationProduct.title || '',
|
|
94
|
+
images: images.length
|
|
95
|
+
? images.map((img) => ({
|
|
96
|
+
href: ctx.makeAbsoluteUrl(img.field_media_image?.uri?.url),
|
|
97
|
+
alt: img.name,
|
|
98
|
+
}))
|
|
99
|
+
: [{ href: '/q2_logo.png', alt: 'Q2' }],
|
|
100
|
+
price: parseFloat(item.unit_price?.number || '0'),
|
|
101
|
+
quantity: parseFloat(item.quantity || '0'),
|
|
102
|
+
product_name: defaultProduct.title || '',
|
|
103
|
+
product_id: defaultProduct.drupal_internal__product_id || '',
|
|
104
|
+
order_item_id: item.id || '',
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
data: {
|
|
109
|
+
id: orderData.id || '',
|
|
110
|
+
drupalOrderId: orderData.drupal_internal__order_id || 0,
|
|
111
|
+
cartItems,
|
|
112
|
+
total: orderData.total_price || { number: '0', currency_code: 'CZK', formatted: '0 Kč' },
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
export const addToCart = async (ctx, activeToken, request, config = {}) => {
|
|
117
|
+
const customHeaders = {};
|
|
118
|
+
if (ctx.accessToken) {
|
|
119
|
+
customHeaders['Authorization'] = `Bearer ${ctx.accessToken}`;
|
|
120
|
+
}
|
|
121
|
+
else if (activeToken) {
|
|
122
|
+
customHeaders['Commerce-Cart-Token'] = activeToken;
|
|
123
|
+
}
|
|
124
|
+
const { data } = await ctx.axios.post('/jsonapi/cart/add', request, {
|
|
125
|
+
...config,
|
|
126
|
+
headers: getHeaders(ctx, { ...config.headers, ...customHeaders }),
|
|
127
|
+
});
|
|
128
|
+
return data;
|
|
129
|
+
};
|
|
130
|
+
export const updateCartItem = async (ctx, orderId, itemId, request, config = {}) => {
|
|
131
|
+
const { data } = await ctx.axios.patch(`/jsonapi/carts/${orderId}/items/${itemId}`, request, { ...config, headers: getHeaders(ctx, config.headers) });
|
|
132
|
+
return data;
|
|
133
|
+
};
|
|
134
|
+
export const deleteCartItem = async (ctx, orderId, request, config = {}) => {
|
|
135
|
+
await ctx.axios.delete(`/jsonapi/carts/${orderId}/items`, {
|
|
136
|
+
...config,
|
|
137
|
+
data: request,
|
|
138
|
+
headers: getHeaders(ctx, { Accept: 'application/vnd.api+json' }),
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
export const clearCart = async (ctx, cartId, config = {}) => {
|
|
142
|
+
await ctx.axios.delete(`/jsonapi/carts/${cartId}`, {
|
|
143
|
+
...config,
|
|
144
|
+
headers: getHeaders(ctx, config.headers),
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
export const applyCoupon = async (ctx, cartId, couponCode, config = {}) => {
|
|
148
|
+
const { data } = await ctx.axios.post(`/jsonapi/commerce_cart/${cartId}/coupons`, {
|
|
149
|
+
data: {
|
|
150
|
+
type: 'commerce_promotion_coupon--default',
|
|
151
|
+
attributes: { code: couponCode },
|
|
152
|
+
},
|
|
153
|
+
}, { ...config, headers: getHeaders(ctx, config.headers) });
|
|
154
|
+
return data;
|
|
155
|
+
};
|
|
156
|
+
export const removeCoupon = async (ctx, cartId, couponId, config = {}) => {
|
|
157
|
+
await ctx.axios.delete(`/jsonapi/commerce_cart/${cartId}/coupons/${couponId}`, {
|
|
158
|
+
...config,
|
|
159
|
+
headers: getHeaders(ctx, config.headers),
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
export const getCartToken = async (ctx, config = {}) => {
|
|
163
|
+
if (!ctx.cartToken)
|
|
164
|
+
throw new Error('Missing cartToken in context');
|
|
165
|
+
const { data } = await ctx.axios.get(`/cart?_format=json&cartToken=${ctx.cartToken}`, { ...config, headers: getHeaders(ctx, config.headers) });
|
|
166
|
+
return data;
|
|
167
|
+
};
|
|
168
|
+
export const getOrderHistory = async (ctx, config = {}) => {
|
|
169
|
+
if (!ctx.userId)
|
|
170
|
+
throw new Error('Missing userId in context');
|
|
171
|
+
const params = new DrupalJsonApiParams()
|
|
172
|
+
.addFilter('state', 'completed')
|
|
173
|
+
.addFilter('uid.meta', ctx.userId)
|
|
174
|
+
.addInclude(['order_items', 'order_items.purchased_entity', 'order_items.purchased_entity.product_id']);
|
|
175
|
+
const { data } = await ctx.axios.get(`/jsonapi/commerce_order/default?${params.getQueryString()}`, { ...config, headers: getHeaders(ctx, config.headers) });
|
|
176
|
+
if (!data.data || (Array.isArray(data.data) && data.data.length === 0)) {
|
|
177
|
+
return { data: [] };
|
|
178
|
+
}
|
|
179
|
+
const resolvedOrders = mapIncludedResources(data);
|
|
180
|
+
const orders = Array.isArray(resolvedOrders) ? resolvedOrders : [resolvedOrders];
|
|
181
|
+
const processedOrders = orders.map(orderData => {
|
|
182
|
+
const cartItems = (orderData.order_items || []).map((item) => ({
|
|
183
|
+
id: item.purchased_entity.product_id.drupal_internal__product_id,
|
|
184
|
+
uuid: item.id,
|
|
185
|
+
drupalOrderItemId: item.drupal_internal__order_item_id || 0,
|
|
186
|
+
type: item.type,
|
|
187
|
+
name: item.title || '',
|
|
188
|
+
price: parseFloat(item.unit_price?.number || '0'),
|
|
189
|
+
quantity: parseFloat(item.quantity || '0'),
|
|
190
|
+
variationId: item.purchased_entity?.id || '',
|
|
191
|
+
}));
|
|
192
|
+
return {
|
|
193
|
+
id: orderData.id || '',
|
|
194
|
+
drupalOrderId: orderData.drupal_internal__order_id || 0,
|
|
195
|
+
cartItems,
|
|
196
|
+
total: orderData.total_price || {
|
|
197
|
+
number: '0',
|
|
198
|
+
currency_code: 'CZK',
|
|
199
|
+
formatted: '0 Kč',
|
|
200
|
+
},
|
|
201
|
+
completed: orderData.completed || '',
|
|
202
|
+
};
|
|
203
|
+
});
|
|
204
|
+
return { data: processedOrders };
|
|
205
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { Product } from '../../types/products/Product';
|
|
2
|
+
export type AddToCartRequest = {
|
|
3
|
+
data: Array<{
|
|
4
|
+
type: string;
|
|
5
|
+
id: string;
|
|
6
|
+
meta: {
|
|
7
|
+
quantity: number;
|
|
8
|
+
combine: boolean;
|
|
9
|
+
};
|
|
10
|
+
}>;
|
|
11
|
+
};
|
|
12
|
+
export type UpdateCartItemRequest = {
|
|
13
|
+
data: {
|
|
14
|
+
type: 'order-items--default';
|
|
15
|
+
id: string;
|
|
16
|
+
attributes: {
|
|
17
|
+
quantity: number;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export type DeleteCartItemRequest = {
|
|
22
|
+
data: Array<{
|
|
23
|
+
type: string;
|
|
24
|
+
id: string;
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
27
|
+
export type JsonApiCartResponse = {
|
|
28
|
+
jsonapi: {
|
|
29
|
+
version: string;
|
|
30
|
+
meta: any;
|
|
31
|
+
};
|
|
32
|
+
data: Array<{
|
|
33
|
+
type: string;
|
|
34
|
+
id: string;
|
|
35
|
+
attributes: {
|
|
36
|
+
drupal_internal__order_id: number;
|
|
37
|
+
order_number: string | null;
|
|
38
|
+
total_price: {
|
|
39
|
+
number: string;
|
|
40
|
+
currency_code: string;
|
|
41
|
+
formatted: string;
|
|
42
|
+
};
|
|
43
|
+
state: string;
|
|
44
|
+
order_total: {
|
|
45
|
+
subtotal: {
|
|
46
|
+
number: string;
|
|
47
|
+
currency_code: string;
|
|
48
|
+
formatted: string;
|
|
49
|
+
};
|
|
50
|
+
total: {
|
|
51
|
+
number: string;
|
|
52
|
+
currency_code: string;
|
|
53
|
+
formatted: string;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
relationships: {
|
|
58
|
+
order_items: {
|
|
59
|
+
data: Array<{
|
|
60
|
+
type: string;
|
|
61
|
+
id: string;
|
|
62
|
+
meta: {
|
|
63
|
+
drupal_internal__target_id: number;
|
|
64
|
+
};
|
|
65
|
+
}>;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
}>;
|
|
69
|
+
included: Array<{
|
|
70
|
+
type: string;
|
|
71
|
+
id: string;
|
|
72
|
+
attributes: any;
|
|
73
|
+
relationships: any;
|
|
74
|
+
}>;
|
|
75
|
+
links: {
|
|
76
|
+
self: {
|
|
77
|
+
href: string;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
export type Cart = {
|
|
82
|
+
data: {
|
|
83
|
+
id: string;
|
|
84
|
+
drupalOrderId: number;
|
|
85
|
+
cartItems: CartItem[];
|
|
86
|
+
total: {
|
|
87
|
+
number: string;
|
|
88
|
+
currency_code: string;
|
|
89
|
+
formatted: string;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
export type CartItem = {
|
|
94
|
+
variation_id: string;
|
|
95
|
+
variation_uuid: string;
|
|
96
|
+
drupalOrderItemId: number;
|
|
97
|
+
images: Array<{
|
|
98
|
+
href: string;
|
|
99
|
+
alt: string;
|
|
100
|
+
}>;
|
|
101
|
+
type: string;
|
|
102
|
+
variation_name: string;
|
|
103
|
+
price: number;
|
|
104
|
+
field_news?: boolean;
|
|
105
|
+
field_aftersale?: boolean;
|
|
106
|
+
quantity: number;
|
|
107
|
+
product_id: string;
|
|
108
|
+
product_name: string;
|
|
109
|
+
order_item_id: string;
|
|
110
|
+
};
|
|
111
|
+
export type AddToCartResponse = Array<{
|
|
112
|
+
order_id: number;
|
|
113
|
+
uuid: string;
|
|
114
|
+
order_number: string | null;
|
|
115
|
+
store_id: number;
|
|
116
|
+
total_price: {
|
|
117
|
+
number: string;
|
|
118
|
+
currency_code: string;
|
|
119
|
+
};
|
|
120
|
+
order_items: Array<{
|
|
121
|
+
order_item_id: number;
|
|
122
|
+
drupal_internal__order_item_id: number;
|
|
123
|
+
uuid: string;
|
|
124
|
+
type: string;
|
|
125
|
+
purchased_entity: number;
|
|
126
|
+
title: string;
|
|
127
|
+
quantity: string;
|
|
128
|
+
unit_price: {
|
|
129
|
+
number: string;
|
|
130
|
+
currency_code: string;
|
|
131
|
+
};
|
|
132
|
+
total_price: {
|
|
133
|
+
number: string;
|
|
134
|
+
currency_code: string;
|
|
135
|
+
};
|
|
136
|
+
}>;
|
|
137
|
+
}>;
|
|
138
|
+
export type OrderHistoryResponse = {
|
|
139
|
+
data: Array<{
|
|
140
|
+
id: string;
|
|
141
|
+
drupalOrderId: number;
|
|
142
|
+
cartItems: CartItem[];
|
|
143
|
+
total: {
|
|
144
|
+
number: string;
|
|
145
|
+
currency_code: string;
|
|
146
|
+
formatted: string;
|
|
147
|
+
};
|
|
148
|
+
}>;
|
|
149
|
+
};
|
|
150
|
+
export type BasketProduct = Omit<Product, 'price'> & {
|
|
151
|
+
quantity: number;
|
|
152
|
+
price: number;
|
|
153
|
+
formattedPrice?: string;
|
|
154
|
+
order_item_id: string;
|
|
155
|
+
};
|
|
156
|
+
//# sourceMappingURL=CartService.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CartService.types.d.ts","sourceRoot":"","sources":["../../../api/cart/CartService.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAEvD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,KAAK,CAAC;QACV,IAAI,EAAE,MAAM,CAAC;QACb,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE;YACJ,QAAQ,EAAE,MAAM,CAAC;YACjB,OAAO,EAAE,OAAO,CAAC;SAClB,CAAA;KACF,CAAC,CAAA;CACH,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE;QACJ,IAAI,EAAE,sBAAsB,CAAC;QAC7B,EAAE,EAAE,MAAM,CAAC;QACX,UAAU,EAAE;YACV,QAAQ,EAAE,MAAM,CAAC;SAClB,CAAA;KACF,CAAA;CACF,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,KAAK,CAAC;QACV,IAAI,EAAE,MAAM,CAAC;QACb,EAAE,EAAE,MAAM,CAAC;KACZ,CAAC,CAAA;CACH,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE;QACP,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,GAAG,CAAC;KACX,CAAC;IACF,IAAI,EAAE,KAAK,CAAC;QACV,IAAI,EAAE,MAAM,CAAC;QACb,EAAE,EAAE,MAAM,CAAC;QACX,UAAU,EAAE;YACV,yBAAyB,EAAE,MAAM,CAAC;YAClC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;YAC5B,WAAW,EAAE;gBACX,MAAM,EAAE,MAAM,CAAC;gBACf,aAAa,EAAE,MAAM,CAAC;gBACtB,SAAS,EAAE,MAAM,CAAC;aACnB,CAAC;YACF,KAAK,EAAE,MAAM,CAAC;YACd,WAAW,EAAE;gBACX,QAAQ,EAAE;oBACR,MAAM,EAAE,MAAM,CAAC;oBACf,aAAa,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M,CAAC;YACtB,SAAS,EAAE,MAAM,CAAC;SACnB,CAAC;KACH,CAAC,CAAC;CACJ,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG;IACjD,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;CACxB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { CoreContext } from '../../context';
|
|
3
|
+
import { Cart } from '../cart/CartService.types';
|
|
4
|
+
import { CheckoutRequest, CreatePaymentRequest, ShippingMethod, UserCheckoutRequest } from './CheckoutService.types';
|
|
5
|
+
export declare const checkout: (ctx: CoreContext, order: string, config?: AxiosRequestConfig) => Promise<Cart>;
|
|
6
|
+
export declare const updateOrderForCheckout: (ctx: CoreContext, order: string, request: CheckoutRequest | UserCheckoutRequest, config?: AxiosRequestConfig) => Promise<Cart>;
|
|
7
|
+
export declare const approvePayment: (ctx: CoreContext, order: string, config?: AxiosRequestConfig) => Promise<any>;
|
|
8
|
+
export declare const createPayment: (ctx: CoreContext, order: string, request: CreatePaymentRequest, config?: AxiosRequestConfig) => Promise<any>;
|
|
9
|
+
export declare const getShippingMethods: (ctx: CoreContext, config?: AxiosRequestConfig) => Promise<ShippingMethod>;
|
|
10
|
+
//# sourceMappingURL=Checkout.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Checkout.service.d.ts","sourceRoot":"","sources":["../../../api/checkout/Checkout.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACL,IAAI,EACL,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,cAAc,EACd,mBAAmB,EACpB,MAAM,yBAAyB,CAAC;AAQjC,eAAO,MAAM,QAAQ,GACnB,KAAK,WAAW,EAChB,OAAO,MAAM,EACb,SAAQ,kBAAuB,KAC9B,OAAO,CAAC,IAAI,CAOd,CAAC;AAEF,eAAO,MAAM,sBAAsB,GACjC,KAAK,WAAW,EAChB,OAAO,MAAM,EACb,SAAS,eAAe,GAAG,mBAAmB,EAC9C,SAAQ,kBAAuB,KAC9B,OAAO,CAAC,IAAI,CAQd,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,KAAK,WAAW,EAChB,OAAO,MAAM,EACb,SAAQ,kBAAuB,KAC9B,OAAO,CAAC,GAAG,CAOb,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,KAAK,WAAW,EAChB,OAAO,MAAM,EACb,SAAS,oBAAoB,EAC7B,SAAQ,kBAAuB,KAC9B,OAAO,CAAC,GAAG,CAQb,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,KAAK,WAAW,EAChB,SAAQ,kBAAuB,KAC9B,OAAO,CAAC,cAAc,CAQxB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const getHeaders = (ctx, customHeaders = {}) => ({
|
|
2
|
+
'Content-Type': 'application/vnd.api+json',
|
|
3
|
+
...(ctx.accessToken && { Authorization: `Bearer ${ctx.accessToken}` }),
|
|
4
|
+
...customHeaders,
|
|
5
|
+
});
|
|
6
|
+
export const checkout = async (ctx, order, config = {}) => {
|
|
7
|
+
const url = `/jsonapi/checkout/${order}`;
|
|
8
|
+
const { data } = await ctx.axios.get(url, { ...config, headers: getHeaders(ctx, config.headers) });
|
|
9
|
+
return data;
|
|
10
|
+
};
|
|
11
|
+
export const updateOrderForCheckout = async (ctx, order, request, config = {}) => {
|
|
12
|
+
const url = `/jsonapi/checkout/${order}`;
|
|
13
|
+
const { data } = await ctx.axios.patch(url, request, { ...config, headers: getHeaders(ctx, config.headers) });
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
export const approvePayment = async (ctx, order, config = {}) => {
|
|
17
|
+
const url = `/jsonapi/checkout/${order}/payment/approve`;
|
|
18
|
+
const { data } = await ctx.axios.get(url, { ...config, headers: getHeaders(ctx, config.headers) });
|
|
19
|
+
return data;
|
|
20
|
+
};
|
|
21
|
+
export const createPayment = async (ctx, order, request, config = {}) => {
|
|
22
|
+
const url = `/jsonapi/checkout/${order}/payment`;
|
|
23
|
+
const { data } = await ctx.axios.post(url, request, { ...config, headers: getHeaders(ctx, config.headers) });
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
export const getShippingMethods = async (ctx, config = {}) => {
|
|
27
|
+
const prefix = ctx.locale !== ctx.defaultLocale ? `/${ctx.locale}` : '';
|
|
28
|
+
const url = `${prefix}/jsonapi/commerce_shipping_method/commerce_shipping_method`;
|
|
29
|
+
const { data } = await ctx.axios.get(url, { ...config, headers: getHeaders(ctx, config.headers) });
|
|
30
|
+
return data;
|
|
31
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export type CheckoutRequest = {
|
|
2
|
+
data: {
|
|
3
|
+
type: 'commerce_order--default';
|
|
4
|
+
attributes: {
|
|
5
|
+
state: 'completed';
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
shipping_address: {
|
|
9
|
+
country_code: string;
|
|
10
|
+
locality: string;
|
|
11
|
+
postal_code: string;
|
|
12
|
+
address_line1: string;
|
|
13
|
+
given_name: string;
|
|
14
|
+
family_name: string;
|
|
15
|
+
};
|
|
16
|
+
email: string;
|
|
17
|
+
phone: string;
|
|
18
|
+
shipping_method: string;
|
|
19
|
+
};
|
|
20
|
+
type CheckoutRequestWithoutShippingAndContact = Omit<CheckoutRequest, 'shipping_address' | 'email' | 'phone'>;
|
|
21
|
+
export type UserCheckoutRequest = CheckoutRequestWithoutShippingAndContact & {
|
|
22
|
+
user_id: string;
|
|
23
|
+
};
|
|
24
|
+
export type CreatePaymentRequest = {
|
|
25
|
+
data: {
|
|
26
|
+
type: string;
|
|
27
|
+
attributes: {
|
|
28
|
+
capture: boolean;
|
|
29
|
+
[key: string]: any;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export type ShippingMethod = {
|
|
34
|
+
id: string;
|
|
35
|
+
type: string;
|
|
36
|
+
attributes: {
|
|
37
|
+
name: string;
|
|
38
|
+
drupal_internal__shipping_method_id: number;
|
|
39
|
+
plugin: {
|
|
40
|
+
target_plugin_id: string;
|
|
41
|
+
target_plugin_configuration: {
|
|
42
|
+
rate_label: string;
|
|
43
|
+
rate_description: string;
|
|
44
|
+
rate_amount: {
|
|
45
|
+
number: string;
|
|
46
|
+
currency_code: string;
|
|
47
|
+
};
|
|
48
|
+
services: string[];
|
|
49
|
+
default_package_type: string;
|
|
50
|
+
workflow: string;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
status: boolean;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=CheckoutService.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CheckoutService.types.d.ts","sourceRoot":"","sources":["../../../api/checkout/CheckoutService.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG;IAC1B,IAAI,EAAE;QACF,IAAI,EAAE,yBAAyB,CAAA;QAC/B,UAAU,EAAE;YACR,KAAK,EAAE,WAAW,CAAA;SACrB,CAAA;KACJ,CAAC;IACF,gBAAgB,EAAE;QACd,YAAY,EAAE,MAAM,CAAA;QACpB,QAAQ,EAAE,MAAM,CAAA;QAChB,WAAW,EAAE,MAAM,CAAA;QACnB,aAAa,EAAE,MAAM,CAAA;QACrB,UAAU,EAAE,MAAM,CAAA;QAClB,WAAW,EAAE,MAAM,CAAA;KACtB,CAAC;IACF,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,eAAe,EAAE,MAAM,CAAA;CAC1B,CAAA;AAED,KAAK,wCAAwC,GAAG,IAAI,CAAC,eAAe,EAAE,kBAAkB,GAAG,OAAO,GAAG,OAAO,CAAC,CAAA;AAE7G,MAAM,MAAM,mBAAmB,GAAG,wCAAwC,GAAG;IAC3E,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IAC/B,IAAI,EAAE;QACF,IAAI,EAAE,MAAM,CAAA;QACZ,UAAU,EAAE;YACR,OAAO,EAAE,OAAO,CAAA;YAChB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;SACrB,CAAA;KACJ,CAAA;CACJ,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IACzB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE;QACR,IAAI,EAAE,MAAM,CAAA;QACZ,mCAAmC,EAAE,MAAM,CAAA;QAC3C,MAAM,EAAE;YACJ,gBAAgB,EAAE,MAAM,CAAA;YACxB,2BAA2B,EAAE;gBACzB,UAAU,EAAE,MAAM,CAAA;gBAClB,gBAAgB,EAAE,MAAM,CAAA;gBACxB,WAAW,EAAE;oBACT,MAAM,EAAE,MAAM,CAAA;oBACd,aAAa,EAAE,MAAM,CAAA;iBACxB,CAAA;gBACD,QAAQ,EAAE,MAAM,EAAE,CAAA;gBAClB,oBAAoB,EAAE,MAAM,CAAA;gBAC5B,QAAQ,EAAE,MAAM,CAAA;aACnB,CAAA;SACJ,CAAA;QACD,MAAM,EAAE,OAAO,CAAA;KAClB,CAAA;CACJ,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CoreContext } from '../../context';
|
|
2
|
+
import { BannerItem } from '../../types/content/Banners';
|
|
3
|
+
type GetBannersInput = {
|
|
4
|
+
location: string;
|
|
5
|
+
mapFn?: (base: BannerItem, raw: any) => BannerItem;
|
|
6
|
+
};
|
|
7
|
+
export declare const getBanners: (ctx: CoreContext, { location, mapFn }: GetBannersInput) => Promise<BannerItem[]>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=getBanners.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getBanners.d.ts","sourceRoot":"","sources":["../../../api/content/getBanners.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAGzD,KAAK,eAAe,GAAG;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,KAAK,UAAU,CAAC;CACpD,CAAC;AAEF,eAAO,MAAM,UAAU,GACrB,KAAK,WAAW,EAChB,qBAAqB,eAAe,KACnC,OAAO,CAAC,UAAU,EAAE,CAoCtB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
|
|
2
|
+
import mapIncludedResources from '../../utils/mapIncludedResources';
|
|
3
|
+
export const getBanners = async (ctx, { location, mapFn }) => {
|
|
4
|
+
const cacheKey = ['banner', ctx.locale, location].join(':');
|
|
5
|
+
const url = ctx.locale === ctx.defaultLocale
|
|
6
|
+
? `/jsonapi/media/banners`
|
|
7
|
+
: `/${ctx.locale}/jsonapi/media/banners`;
|
|
8
|
+
const params = new DrupalJsonApiParams()
|
|
9
|
+
.addInclude(['field_media_image_1', 'field_location'])
|
|
10
|
+
.addFilter('langcode', ctx.locale)
|
|
11
|
+
.addFilter('field_location.name', location)
|
|
12
|
+
.addSort('created', 'DESC');
|
|
13
|
+
const { data } = await ctx.axios.get(`${url}?${params.getQueryString()}`);
|
|
14
|
+
const resources = mapIncludedResources(data);
|
|
15
|
+
const mapped = resources.map((item) => {
|
|
16
|
+
const base = {
|
|
17
|
+
id: item.drupal_internal__mid,
|
|
18
|
+
uuid: item.id,
|
|
19
|
+
type: item.type,
|
|
20
|
+
name: item.name,
|
|
21
|
+
field_description: item.field_description,
|
|
22
|
+
field_link: {
|
|
23
|
+
uri: item.field_link?.uri?.replace('internal:', ''),
|
|
24
|
+
title: item.field_link?.title,
|
|
25
|
+
},
|
|
26
|
+
field_image: ctx.makeAbsoluteUrl(item.field_media_image_1?.uri?.url),
|
|
27
|
+
created: item.created,
|
|
28
|
+
};
|
|
29
|
+
return mapFn ? mapFn(base, item) : base;
|
|
30
|
+
});
|
|
31
|
+
return mapped;
|
|
32
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CoreContext } from '../../context';
|
|
2
|
+
import { BlogItem } from '../../types/content/Blog';
|
|
3
|
+
type GetBlogParams = {
|
|
4
|
+
blogId?: string;
|
|
5
|
+
limit?: number;
|
|
6
|
+
include?: string[];
|
|
7
|
+
mapFn?: any;
|
|
8
|
+
};
|
|
9
|
+
export declare const getBlog: (ctx: CoreContext, { blogId, limit, include, mapFn }: GetBlogParams) => Promise<BlogItem[]>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=getBlog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getBlog.d.ts","sourceRoot":"","sources":["../../../api/content/getBlog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAGpD,KAAK,aAAa,GAAG;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,GAAG,CAAC;CACb,CAAC;AAEF,eAAO,MAAM,OAAO,GAClB,KAAK,WAAW,EAChB,mCAAqD,aAAa,KACjE,OAAO,CAAC,QAAQ,EAAE,CA+CpB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
|
|
2
|
+
import mapIncludedResources from '../../utils/mapIncludedResources';
|
|
3
|
+
export const getBlog = async (ctx, { blogId, limit, include = ['field_image'], mapFn }) => {
|
|
4
|
+
const cacheKey = ['blog', ctx.locale, blogId && `id:${blogId}`, limit && `limit:${limit}`]
|
|
5
|
+
.filter(Boolean)
|
|
6
|
+
.join(':');
|
|
7
|
+
if (ctx.getCache) {
|
|
8
|
+
const cached = await ctx.getCache(cacheKey);
|
|
9
|
+
if (cached)
|
|
10
|
+
return cached;
|
|
11
|
+
}
|
|
12
|
+
const params = new DrupalJsonApiParams()
|
|
13
|
+
.addFilter('langcode', ctx.locale)
|
|
14
|
+
.addInclude(include)
|
|
15
|
+
.addSort('drupal_internal__nid', 'DESC');
|
|
16
|
+
if (blogId)
|
|
17
|
+
params.addFilter('drupal_internal__nid', blogId);
|
|
18
|
+
if (limit)
|
|
19
|
+
params.addPageLimit(limit);
|
|
20
|
+
const url = ctx.locale === ctx.defaultLocale
|
|
21
|
+
? `/jsonapi/node/article`
|
|
22
|
+
: `/${ctx.locale}/jsonapi/node/article`;
|
|
23
|
+
const { data } = await ctx.axios.get(`${url}?${params.getQueryString()}`);
|
|
24
|
+
const resources = mapIncludedResources(data);
|
|
25
|
+
const mapped = resources.map((item) => {
|
|
26
|
+
const base = {
|
|
27
|
+
id: item.drupal_internal__nid,
|
|
28
|
+
uuid: item.id,
|
|
29
|
+
type: item.type,
|
|
30
|
+
title: item.title,
|
|
31
|
+
body: item.body?.processed || '',
|
|
32
|
+
field_image_alt: item.field_image?.filename || '',
|
|
33
|
+
field_image_url: ctx.makeAbsoluteUrl(item.field_image?.uri?.url || ''),
|
|
34
|
+
created: item.created,
|
|
35
|
+
changed: item.changed,
|
|
36
|
+
};
|
|
37
|
+
return mapFn ? mapFn(base, item) : base;
|
|
38
|
+
});
|
|
39
|
+
// if (ctx.setCache) {
|
|
40
|
+
// await ctx.setCache(cacheKey, mapped);
|
|
41
|
+
// }
|
|
42
|
+
return mapped;
|
|
43
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CoreContext } from '../context';
|
|
2
|
+
import { Term } from '../types/Term';
|
|
3
|
+
type GetTermsInput = {
|
|
4
|
+
categoryId?: string[];
|
|
5
|
+
include?: string[];
|
|
6
|
+
mapFn?: (base: Term, raw: any) => Term | Promise<Term>;
|
|
7
|
+
};
|
|
8
|
+
export declare const getTerms: (ctx: CoreContext, { categoryId, include, mapFn }: GetTermsInput) => Promise<Term[]>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=getTerms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTerms.d.ts","sourceRoot":"","sources":["../../api/getTerms.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAIrC,KAAK,aAAa,GAAG;IACnB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD,CAAC;AAEF,eAAO,MAAM,QAAQ,GACnB,KAAK,WAAW,EAChB,gCAA6C,aAAa,KACzD,OAAO,CAAC,IAAI,EAAE,CA0ChB,CAAC"}
|