@decocms/apps 0.20.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/.github/workflows/release.yml +34 -0
- package/.releaserc.json +25 -0
- package/commerce/components/Image.tsx +209 -0
- package/commerce/components/JsonLd.tsx +285 -0
- package/commerce/sdk/analytics.ts +24 -0
- package/commerce/sdk/formatPrice.ts +23 -0
- package/commerce/sdk/url.ts +9 -0
- package/commerce/sdk/useOffer.ts +75 -0
- package/commerce/sdk/useVariantPossibilities.ts +43 -0
- package/commerce/types/commerce.ts +1105 -0
- package/commerce/utils/canonical.ts +11 -0
- package/commerce/utils/constants.ts +9 -0
- package/commerce/utils/filters.ts +10 -0
- package/commerce/utils/productToAnalyticsItem.ts +67 -0
- package/commerce/utils/stateByZip.ts +50 -0
- package/knip.json +19 -0
- package/package.json +77 -0
- package/shopify/actions/cart/addItems.ts +37 -0
- package/shopify/actions/cart/updateCoupons.ts +32 -0
- package/shopify/actions/cart/updateItems.ts +32 -0
- package/shopify/actions/user/signIn.ts +45 -0
- package/shopify/actions/user/signUp.ts +36 -0
- package/shopify/client.ts +58 -0
- package/shopify/index.ts +32 -0
- package/shopify/init.ts +40 -0
- package/shopify/loaders/ProductDetailsPage.ts +35 -0
- package/shopify/loaders/ProductList.ts +101 -0
- package/shopify/loaders/ProductListingPage.ts +180 -0
- package/shopify/loaders/RelatedProducts.ts +45 -0
- package/shopify/loaders/cart.ts +73 -0
- package/shopify/loaders/shop.ts +40 -0
- package/shopify/loaders/user.ts +44 -0
- package/shopify/utils/admin/admin.ts +57 -0
- package/shopify/utils/admin/queries.ts +29 -0
- package/shopify/utils/cart.ts +28 -0
- package/shopify/utils/cookies.ts +85 -0
- package/shopify/utils/enums.ts +438 -0
- package/shopify/utils/graphql.ts +69 -0
- package/shopify/utils/storefront/queries.ts +530 -0
- package/shopify/utils/storefront/storefront.graphql.gen.ts +113 -0
- package/shopify/utils/transform.ts +436 -0
- package/shopify/utils/types.ts +191 -0
- package/shopify/utils/user.ts +23 -0
- package/shopify/utils/utils.ts +164 -0
- package/tsconfig.json +11 -0
- package/vtex/README.md +6 -0
- package/vtex/actions/address.ts +211 -0
- package/vtex/actions/auth.ts +337 -0
- package/vtex/actions/checkout.ts +497 -0
- package/vtex/actions/index.ts +11 -0
- package/vtex/actions/masterData.ts +170 -0
- package/vtex/actions/misc.ts +196 -0
- package/vtex/actions/newsletter.ts +108 -0
- package/vtex/actions/orders.ts +37 -0
- package/vtex/actions/profile.ts +119 -0
- package/vtex/actions/session.ts +87 -0
- package/vtex/actions/trigger.ts +43 -0
- package/vtex/actions/wishlist.ts +116 -0
- package/vtex/client.ts +423 -0
- package/vtex/hooks/index.ts +4 -0
- package/vtex/hooks/useAutocomplete.ts +89 -0
- package/vtex/hooks/useCart.ts +219 -0
- package/vtex/hooks/useUser.ts +78 -0
- package/vtex/hooks/useWishlist.ts +119 -0
- package/vtex/index.ts +14 -0
- package/vtex/inline-loaders/productDetailsPage.ts +75 -0
- package/vtex/inline-loaders/productList.ts +163 -0
- package/vtex/inline-loaders/productListingPage.ts +447 -0
- package/vtex/inline-loaders/relatedProducts.ts +83 -0
- package/vtex/inline-loaders/suggestions.ts +49 -0
- package/vtex/inline-loaders/workflowProducts.ts +68 -0
- package/vtex/invoke.ts +202 -0
- package/vtex/loaders/address.ts +120 -0
- package/vtex/loaders/brands.ts +51 -0
- package/vtex/loaders/cart.ts +49 -0
- package/vtex/loaders/catalog.ts +165 -0
- package/vtex/loaders/collections.ts +57 -0
- package/vtex/loaders/index.ts +19 -0
- package/vtex/loaders/legacy.ts +671 -0
- package/vtex/loaders/logistics.ts +115 -0
- package/vtex/loaders/navbar.ts +29 -0
- package/vtex/loaders/orders.ts +103 -0
- package/vtex/loaders/pageType.ts +62 -0
- package/vtex/loaders/payment.ts +107 -0
- package/vtex/loaders/profile.ts +138 -0
- package/vtex/loaders/promotion.ts +33 -0
- package/vtex/loaders/search.ts +127 -0
- package/vtex/loaders/session.ts +91 -0
- package/vtex/loaders/user.ts +89 -0
- package/vtex/loaders/wishlist.ts +89 -0
- package/vtex/loaders/wishlistProducts.ts +81 -0
- package/vtex/loaders/workflow.ts +323 -0
- package/vtex/logo.png +0 -0
- package/vtex/middleware.ts +229 -0
- package/vtex/types.ts +248 -0
- package/vtex/utils/batch.ts +21 -0
- package/vtex/utils/cookies.ts +76 -0
- package/vtex/utils/enrichment.ts +540 -0
- package/vtex/utils/fetchCache.ts +150 -0
- package/vtex/utils/index.ts +17 -0
- package/vtex/utils/intelligentSearch.ts +84 -0
- package/vtex/utils/legacy.ts +155 -0
- package/vtex/utils/pickAndOmit.ts +30 -0
- package/vtex/utils/proxy.ts +196 -0
- package/vtex/utils/resourceRange.ts +10 -0
- package/vtex/utils/segment.ts +163 -0
- package/vtex/utils/similars.ts +38 -0
- package/vtex/utils/sitemap.ts +133 -0
- package/vtex/utils/slugCache.ts +32 -0
- package/vtex/utils/slugify.ts +13 -0
- package/vtex/utils/transform.ts +1331 -0
- package/vtex/utils/types.ts +1884 -0
- package/vtex/utils/vtexId.ts +103 -0
package/vtex/types.ts
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VTEX Checkout / OrderForm types.
|
|
3
|
+
* These mirror the VTEX Checkout API response shapes.
|
|
4
|
+
* Aligned with deco-cx/apps vtex/utils/types.ts
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface OrderFormItem {
|
|
8
|
+
id: string;
|
|
9
|
+
productId: string;
|
|
10
|
+
productRefId?: string;
|
|
11
|
+
refId?: string;
|
|
12
|
+
ean?: string | null;
|
|
13
|
+
name: string;
|
|
14
|
+
skuName: string;
|
|
15
|
+
imageUrl: string;
|
|
16
|
+
detailUrl: string;
|
|
17
|
+
price: number;
|
|
18
|
+
listPrice: number;
|
|
19
|
+
manualPrice?: number | null;
|
|
20
|
+
quantity: number;
|
|
21
|
+
sellingPrice: number;
|
|
22
|
+
rewardValue?: number;
|
|
23
|
+
isGift?: boolean;
|
|
24
|
+
tax?: number;
|
|
25
|
+
seller: string;
|
|
26
|
+
sellerChain?: string[];
|
|
27
|
+
uniqueId: string;
|
|
28
|
+
parentItemIndex?: number | null;
|
|
29
|
+
parentAssemblyBinding?: string | null;
|
|
30
|
+
availability?: string;
|
|
31
|
+
measurementUnit?: string;
|
|
32
|
+
unitMultiplier?: number;
|
|
33
|
+
productCategoryIds?: string;
|
|
34
|
+
productCategories?: Record<string, string>;
|
|
35
|
+
additionalInfo?: {
|
|
36
|
+
brandName?: string;
|
|
37
|
+
brandId?: string;
|
|
38
|
+
dimension?: Record<string, string> | null;
|
|
39
|
+
offeringInfo?: unknown | null;
|
|
40
|
+
offeringType?: unknown | null;
|
|
41
|
+
offeringTypeId?: unknown | null;
|
|
42
|
+
};
|
|
43
|
+
attachments?: unknown[];
|
|
44
|
+
attachmentOfferings?: Array<{
|
|
45
|
+
name: string;
|
|
46
|
+
required: boolean;
|
|
47
|
+
schema: Record<string, unknown>;
|
|
48
|
+
}>;
|
|
49
|
+
offerings?: Array<{
|
|
50
|
+
type: string;
|
|
51
|
+
id: string;
|
|
52
|
+
name: string;
|
|
53
|
+
price: number;
|
|
54
|
+
}>;
|
|
55
|
+
priceTags?: Array<{
|
|
56
|
+
name: string;
|
|
57
|
+
value: number;
|
|
58
|
+
rawValue: number;
|
|
59
|
+
isPercentual: boolean;
|
|
60
|
+
identifier: string | null;
|
|
61
|
+
}>;
|
|
62
|
+
components?: unknown[];
|
|
63
|
+
bundleItems?: unknown[];
|
|
64
|
+
priceDefinition?: {
|
|
65
|
+
calculatedSellingPrice: number;
|
|
66
|
+
total: number;
|
|
67
|
+
sellingPrices: Array<{
|
|
68
|
+
value: number;
|
|
69
|
+
quantity: number;
|
|
70
|
+
}>;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface Totalizer {
|
|
75
|
+
id: string;
|
|
76
|
+
name: string;
|
|
77
|
+
value: number;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface Message {
|
|
81
|
+
code: string;
|
|
82
|
+
text: string;
|
|
83
|
+
status: string;
|
|
84
|
+
fields?: Record<string, string>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface MarketingData {
|
|
88
|
+
utmSource?: string;
|
|
89
|
+
utmMedium?: string;
|
|
90
|
+
utmCampaign?: string;
|
|
91
|
+
utmiPage?: string;
|
|
92
|
+
utmiPart?: string;
|
|
93
|
+
utmiCampaign?: string;
|
|
94
|
+
coupon?: string;
|
|
95
|
+
marketingTags?: string[];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface ClientProfileData {
|
|
99
|
+
email: string;
|
|
100
|
+
firstName?: string | null;
|
|
101
|
+
lastName?: string | null;
|
|
102
|
+
document?: string | null;
|
|
103
|
+
phone?: string | null;
|
|
104
|
+
corporateName?: string | null;
|
|
105
|
+
isCorporate?: boolean;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface StorePreferencesData {
|
|
109
|
+
countryCode: string;
|
|
110
|
+
saveUserData?: boolean;
|
|
111
|
+
timeZone?: string;
|
|
112
|
+
currencyCode: string;
|
|
113
|
+
currencyLocale?: number;
|
|
114
|
+
currencySymbol: string;
|
|
115
|
+
currencyFormatInfo?: {
|
|
116
|
+
currencyDecimalDigits: number;
|
|
117
|
+
currencyDecimalSeparator: string;
|
|
118
|
+
currencyGroupSeparator: string;
|
|
119
|
+
currencyGroupSize: number;
|
|
120
|
+
startsWithCurrencySymbol: boolean;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface ClientPreferencesData {
|
|
125
|
+
locale: string;
|
|
126
|
+
optinNewsLetter?: boolean;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface ShippingData {
|
|
130
|
+
address?: {
|
|
131
|
+
postalCode?: string;
|
|
132
|
+
city?: string;
|
|
133
|
+
state?: string;
|
|
134
|
+
country?: string;
|
|
135
|
+
street?: string;
|
|
136
|
+
number?: string;
|
|
137
|
+
neighborhood?: string;
|
|
138
|
+
complement?: string;
|
|
139
|
+
reference?: string;
|
|
140
|
+
} | null;
|
|
141
|
+
selectedAddresses?: Array<{
|
|
142
|
+
postalCode?: string;
|
|
143
|
+
city?: string;
|
|
144
|
+
state?: string;
|
|
145
|
+
country?: string;
|
|
146
|
+
}>;
|
|
147
|
+
logisticsInfo?: Array<{
|
|
148
|
+
itemIndex: number;
|
|
149
|
+
selectedSla?: string;
|
|
150
|
+
selectedDeliveryChannel?: string;
|
|
151
|
+
slas?: Sla[];
|
|
152
|
+
}>;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export interface PaymentData {
|
|
156
|
+
updateStatus?: string;
|
|
157
|
+
installmentOptions?: unknown[];
|
|
158
|
+
paymentSystems?: unknown[];
|
|
159
|
+
payments?: unknown[];
|
|
160
|
+
giftCards?: unknown[];
|
|
161
|
+
availableAccounts?: unknown[];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export interface OrderForm {
|
|
165
|
+
orderFormId: string;
|
|
166
|
+
salesChannel: string;
|
|
167
|
+
loggedIn: boolean;
|
|
168
|
+
isCheckedIn: boolean;
|
|
169
|
+
storeId?: unknown | null;
|
|
170
|
+
checkedInPickupPointId?: unknown | null;
|
|
171
|
+
allowManualPrice: boolean;
|
|
172
|
+
canEditData: boolean;
|
|
173
|
+
userProfileId?: unknown | null;
|
|
174
|
+
userType?: unknown | null;
|
|
175
|
+
ignoreProfileData: boolean;
|
|
176
|
+
value: number;
|
|
177
|
+
messages: Message[];
|
|
178
|
+
items: OrderFormItem[];
|
|
179
|
+
selectableGifts?: unknown[];
|
|
180
|
+
totalizers: Totalizer[];
|
|
181
|
+
shippingData: ShippingData | null;
|
|
182
|
+
clientProfileData: ClientProfileData | null;
|
|
183
|
+
paymentData: PaymentData | null;
|
|
184
|
+
marketingData: MarketingData | null;
|
|
185
|
+
sellers?: Array<{ id: string; name: string; logo?: string }>;
|
|
186
|
+
clientPreferencesData?: ClientPreferencesData | null;
|
|
187
|
+
commercialConditionData?: unknown | null;
|
|
188
|
+
storePreferencesData?: StorePreferencesData | null;
|
|
189
|
+
giftRegistryData?: unknown | null;
|
|
190
|
+
openTextField?: unknown | null;
|
|
191
|
+
invoiceData?: unknown | null;
|
|
192
|
+
customData?: unknown | null;
|
|
193
|
+
itemMetadata?: unknown | null;
|
|
194
|
+
hooksData?: unknown | null;
|
|
195
|
+
ratesAndBenefitsData?: {
|
|
196
|
+
rateAndBenefitsIdentifiers?: unknown[];
|
|
197
|
+
teaser?: unknown[];
|
|
198
|
+
} | null;
|
|
199
|
+
subscriptionData?: unknown | null;
|
|
200
|
+
merchantContextData?: unknown | null;
|
|
201
|
+
itemsOrdination?: unknown | null;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface SimulationOrderForm {
|
|
205
|
+
items: Array<{
|
|
206
|
+
id: string;
|
|
207
|
+
quantity: number;
|
|
208
|
+
seller: string;
|
|
209
|
+
price?: number;
|
|
210
|
+
listPrice?: number;
|
|
211
|
+
offerings?: any[];
|
|
212
|
+
priceTags?: any[];
|
|
213
|
+
availability?: string;
|
|
214
|
+
}>;
|
|
215
|
+
logisticsInfo?: Array<{
|
|
216
|
+
itemIndex: number;
|
|
217
|
+
slas: Sla[];
|
|
218
|
+
selectedSla?: string;
|
|
219
|
+
selectedDeliveryChannel?: string;
|
|
220
|
+
}>;
|
|
221
|
+
paymentData?: {
|
|
222
|
+
installmentOptions?: any[];
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export interface Sla {
|
|
227
|
+
id: string;
|
|
228
|
+
name: string;
|
|
229
|
+
price: number;
|
|
230
|
+
shippingEstimate: string;
|
|
231
|
+
deliveryChannel?: string;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export interface SKU {
|
|
235
|
+
id: string;
|
|
236
|
+
seller: string;
|
|
237
|
+
quantity: number;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export interface VtexProduct {
|
|
241
|
+
productId: string;
|
|
242
|
+
productName: string;
|
|
243
|
+
brand: string;
|
|
244
|
+
categoryId: string;
|
|
245
|
+
categories: string[];
|
|
246
|
+
items: any[];
|
|
247
|
+
[key: string]: any;
|
|
248
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const batch = <T>(
|
|
2
|
+
iterable: IterableIterator<T> | T[],
|
|
3
|
+
size: number,
|
|
4
|
+
): T[][] => {
|
|
5
|
+
const batches: T[][] = [];
|
|
6
|
+
|
|
7
|
+
let current = 0;
|
|
8
|
+
for (const item of iterable) {
|
|
9
|
+
if (batches[current]?.length === size) {
|
|
10
|
+
current++;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (!batches[current]) {
|
|
14
|
+
batches[current] = [];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
batches[current].push(item);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return batches;
|
|
21
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
interface Cookie {
|
|
2
|
+
name: string;
|
|
3
|
+
value: string;
|
|
4
|
+
domain?: string;
|
|
5
|
+
path?: string;
|
|
6
|
+
expires?: Date;
|
|
7
|
+
maxAge?: number;
|
|
8
|
+
secure?: boolean;
|
|
9
|
+
httpOnly?: boolean;
|
|
10
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getSetCookies(headers: Headers): Cookie[] {
|
|
14
|
+
const cookies: Cookie[] = [];
|
|
15
|
+
headers.forEach((value, key) => {
|
|
16
|
+
if (key.toLowerCase() !== "set-cookie") return;
|
|
17
|
+
const parts = value.split(";").map((p) => p.trim());
|
|
18
|
+
const [nameValue, ...attrs] = parts;
|
|
19
|
+
const eqIdx = nameValue.indexOf("=");
|
|
20
|
+
if (eqIdx < 0) return;
|
|
21
|
+
const cookie: Cookie = {
|
|
22
|
+
name: nameValue.slice(0, eqIdx),
|
|
23
|
+
value: nameValue.slice(eqIdx + 1),
|
|
24
|
+
};
|
|
25
|
+
for (const attr of attrs) {
|
|
26
|
+
const [k, v] = attr.split("=").map((s) => s.trim());
|
|
27
|
+
const lower = k.toLowerCase();
|
|
28
|
+
if (lower === "domain") cookie.domain = v;
|
|
29
|
+
else if (lower === "path") cookie.path = v;
|
|
30
|
+
else if (lower === "secure") cookie.secure = true;
|
|
31
|
+
else if (lower === "httponly") cookie.httpOnly = true;
|
|
32
|
+
else if (lower === "samesite") cookie.sameSite = v as Cookie["sameSite"];
|
|
33
|
+
}
|
|
34
|
+
cookies.push(cookie);
|
|
35
|
+
});
|
|
36
|
+
return cookies;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function setCookie(headers: Headers, cookie: Cookie): void {
|
|
40
|
+
let str = `${cookie.name}=${cookie.value}`;
|
|
41
|
+
if (cookie.domain) str += `; Domain=${cookie.domain}`;
|
|
42
|
+
if (cookie.path) str += `; Path=${cookie.path}`;
|
|
43
|
+
if (cookie.secure) str += "; Secure";
|
|
44
|
+
if (cookie.httpOnly) str += "; HttpOnly";
|
|
45
|
+
if (cookie.sameSite) str += `; SameSite=${cookie.sameSite}`;
|
|
46
|
+
if (cookie.maxAge != null) str += `; Max-Age=${cookie.maxAge}`;
|
|
47
|
+
if (cookie.expires) str += `; Expires=${cookie.expires.toUTCString()}`;
|
|
48
|
+
headers.append("Set-Cookie", str);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const stringify = (cookies: Record<string, string>) =>
|
|
52
|
+
Object.entries(cookies)
|
|
53
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
54
|
+
.join("; ");
|
|
55
|
+
|
|
56
|
+
export const proxySetCookie = (
|
|
57
|
+
from: Headers,
|
|
58
|
+
to: Headers,
|
|
59
|
+
toDomain?: URL | string,
|
|
60
|
+
) => {
|
|
61
|
+
const newDomain = toDomain && new URL(toDomain);
|
|
62
|
+
|
|
63
|
+
for (const cookie of getSetCookies(from)) {
|
|
64
|
+
const newCookie = newDomain
|
|
65
|
+
? {
|
|
66
|
+
...cookie,
|
|
67
|
+
domain: newDomain.hostname,
|
|
68
|
+
}
|
|
69
|
+
: cookie;
|
|
70
|
+
|
|
71
|
+
setCookie(to, newCookie);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const CHECKOUT_DATA_ACCESS_COOKIE = "CheckoutDataAccess";
|
|
76
|
+
export const VTEX_CHKO_AUTH = "Vtex_CHKO_Auth";
|