@simpleapps-com/augur-utils 2.4.0 → 2026.11.2
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/EXPORTS.md +28 -31
- package/README.md +19 -180
- package/dist/address-comparison.d.ts +18 -0
- package/dist/address-comparison.d.ts.map +1 -0
- package/dist/address-schemas.d.ts +45 -0
- package/dist/address-schemas.d.ts.map +1 -0
- package/dist/analytics.d.ts +66 -0
- package/dist/analytics.d.ts.map +1 -0
- package/dist/build-checkout-payload.d.ts +37 -0
- package/dist/build-checkout-payload.d.ts.map +1 -0
- package/dist/cache-config.d.ts +42 -0
- package/dist/cache-config.d.ts.map +1 -0
- package/dist/chunk-5UMFBGVA.cjs.map +1 -1
- package/dist/date-helpers.d.ts +16 -0
- package/dist/date-helpers.d.ts.map +1 -0
- package/dist/derive-price.d.ts +49 -0
- package/dist/derive-price.d.ts.map +1 -0
- package/dist/format-price.d.ts +6 -0
- package/dist/format-price.d.ts.map +1 -0
- package/dist/get-payment-status.d.ts +10 -0
- package/dist/get-payment-status.d.ts.map +1 -0
- package/dist/image-rules.d.ts +70 -0
- package/dist/image-rules.d.ts.map +1 -0
- package/dist/image.d.ts +80 -0
- package/dist/image.d.ts.map +1 -0
- package/dist/index.cjs +545 -166
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +63 -1448
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +544 -165
- package/dist/index.js.map +1 -1
- package/dist/json-ld-rules.d.ts +50 -0
- package/dist/json-ld-rules.d.ts.map +1 -0
- package/dist/json-ld.d.ts +47 -0
- package/dist/json-ld.d.ts.map +1 -0
- package/dist/money.d.ts +37 -0
- package/dist/money.d.ts.map +1 -0
- package/dist/price-breaks.d.ts +16 -0
- package/dist/price-breaks.d.ts.map +1 -0
- package/dist/price-outcome.d.ts +19 -0
- package/dist/price-outcome.d.ts.map +1 -0
- package/dist/resolve-stock.d.ts +22 -0
- package/dist/resolve-stock.d.ts.map +1 -0
- package/dist/result.d.ts +33 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/rules.d.ts +45 -0
- package/dist/rules.d.ts.map +1 -0
- package/dist/schema-availability.d.ts +11 -0
- package/dist/schema-availability.d.ts.map +1 -0
- package/dist/transform-ship-to-address.d.ts +15 -0
- package/dist/transform-ship-to-address.d.ts.map +1 -0
- package/dist/transforms.d.ts +70 -0
- package/dist/transforms.d.ts.map +1 -0
- package/dist/types/api.d.ts +8 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/attribute.d.ts +12 -0
- package/dist/types/attribute.d.ts.map +1 -0
- package/dist/types/cart.d.ts +25 -0
- package/dist/types/cart.d.ts.map +1 -0
- package/dist/types/category-items.d.ts +4 -0
- package/dist/types/category-items.d.ts.map +1 -0
- package/dist/types/category.d.ts +19 -0
- package/dist/types/category.d.ts.map +1 -0
- package/dist/types/checkout.d.ts +4 -0
- package/dist/types/checkout.d.ts.map +1 -0
- package/dist/types/customer.d.ts +4 -0
- package/dist/types/customer.d.ts.map +1 -0
- package/dist/types/filter.d.ts +9 -0
- package/dist/types/filter.d.ts.map +1 -0
- package/dist/types/inventory.d.ts +10 -0
- package/dist/types/inventory.d.ts.map +1 -0
- package/dist/types/joomla.d.ts +11 -0
- package/dist/types/joomla.d.ts.map +1 -0
- package/dist/types/ltl-shipping.d.ts +45 -0
- package/dist/types/ltl-shipping.d.ts.map +1 -0
- package/dist/types/menu.d.ts +14 -0
- package/dist/types/menu.d.ts.map +1 -0
- package/dist/types/meta.d.ts +11 -0
- package/dist/types/meta.d.ts.map +1 -0
- package/dist/types/order.d.ts +72 -0
- package/dist/types/order.d.ts.map +1 -0
- package/dist/types/password.d.ts +7 -0
- package/dist/types/password.d.ts.map +1 -0
- package/dist/types/payment.d.ts +69 -0
- package/dist/types/payment.d.ts.map +1 -0
- package/dist/types/pricing.d.ts +25 -0
- package/dist/types/pricing.d.ts.map +1 -0
- package/dist/types/product.d.ts +58 -0
- package/dist/types/product.d.ts.map +1 -0
- package/dist/types/search.d.ts +16 -0
- package/dist/types/search.d.ts.map +1 -0
- package/dist/types/shipping.d.ts +4 -0
- package/dist/types/shipping.d.ts.map +1 -0
- package/dist/types/smarty-streets.d.ts +4 -0
- package/dist/types/smarty-streets.d.ts.map +1 -0
- package/dist/types/supplier.d.ts +4 -0
- package/dist/types/supplier.d.ts.map +1 -0
- package/dist/types/tax.d.ts +6 -0
- package/dist/types/tax.d.ts.map +1 -0
- package/dist/types/uom.d.ts +4 -0
- package/dist/types/uom.d.ts.map +1 -0
- package/dist/types/user-profile.d.ts +5 -0
- package/dist/types/user-profile.d.ts.map +1 -0
- package/dist/us-states.d.ts +15 -0
- package/dist/us-states.d.ts.map +1 -0
- package/dist/validation-patterns.d.ts +22 -0
- package/dist/validation-patterns.d.ts.map +1 -0
- package/dist/web.cjs.map +1 -1
- package/dist/web.d.ts +3 -5
- package/dist/web.d.ts.map +1 -0
- package/llms.txt +49 -38
- package/package.json +25 -13
- package/dist/index.d.cts +0 -1448
- package/dist/web.d.cts +0 -6
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
var _chunk5UMFBGVAcjs = require('./chunk-5UMFBGVA.cjs');
|
|
4
4
|
|
|
5
|
+
// src/price-breaks.ts
|
|
6
|
+
function hasPriceBreaks(libraryPriceData) {
|
|
7
|
+
return libraryPriceData !== null && Array.isArray(libraryPriceData.breaks);
|
|
8
|
+
}
|
|
9
|
+
|
|
5
10
|
// src/cache-config.ts
|
|
6
11
|
var CACHE_CONFIG = {
|
|
7
12
|
STATIC: {
|
|
@@ -44,29 +49,99 @@ function formatPrice(price, locale = "en-US", currency = "USD") {
|
|
|
44
49
|
}).format(price);
|
|
45
50
|
}
|
|
46
51
|
|
|
52
|
+
// src/rules.ts
|
|
53
|
+
function paymentStatusOf(paidInFull, hasAmounts, amountPaid) {
|
|
54
|
+
if (paidInFull) return "Paid";
|
|
55
|
+
if (hasAmounts && amountPaid > 0) return "Partially Paid";
|
|
56
|
+
return "Unpaid";
|
|
57
|
+
}
|
|
58
|
+
function isLowStockOf(quantity, threshold) {
|
|
59
|
+
return quantity > 0 && threshold > 0 && quantity <= threshold;
|
|
60
|
+
}
|
|
61
|
+
function allYesFrom(flags, i) {
|
|
62
|
+
if (i >= flags.length) return true;
|
|
63
|
+
return flags[i] === "Y" && allYesFrom(flags, i + 1);
|
|
64
|
+
}
|
|
65
|
+
function isDiscontinuedOf(flags) {
|
|
66
|
+
return flags.length > 0 && allYesFrom(flags, 0);
|
|
67
|
+
}
|
|
68
|
+
function categorySortBy(prefix, sortBy) {
|
|
69
|
+
return prefix !== "" && sortBy !== "" ? prefix + sortBy : sortBy;
|
|
70
|
+
}
|
|
71
|
+
function searchSortBy(sortBy) {
|
|
72
|
+
return sortBy !== "" ? sortBy : void 0;
|
|
73
|
+
}
|
|
74
|
+
function pageOffset(page, limit) {
|
|
75
|
+
return page * limit;
|
|
76
|
+
}
|
|
77
|
+
function unwrapMessage(error) {
|
|
78
|
+
return error !== "" ? error : "Action failed";
|
|
79
|
+
}
|
|
80
|
+
function shippingLeadOf(days) {
|
|
81
|
+
if (days === "1-2") return { from: 1, to: 4 };
|
|
82
|
+
if (days === "2") return { from: 4, to: 0 };
|
|
83
|
+
if (days === "2-3") return { from: 2, to: 5 };
|
|
84
|
+
if (days === "3") return { from: 5, to: 0 };
|
|
85
|
+
if (days === "3-4") return { from: 3, to: 6 };
|
|
86
|
+
if (days === "4") return { from: 6, to: 0 };
|
|
87
|
+
if (days === "5") return { from: 7, to: 0 };
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
function isBusinessDayName(dayName) {
|
|
91
|
+
return dayName !== "Sunday" && dayName !== "Saturday";
|
|
92
|
+
}
|
|
93
|
+
function availabilityOf(isInStock, isDiscontinued) {
|
|
94
|
+
if (isInStock) return "InStock";
|
|
95
|
+
if (isDiscontinued) return "OutOfStock";
|
|
96
|
+
return "BackOrder";
|
|
97
|
+
}
|
|
98
|
+
function takerOf(taker) {
|
|
99
|
+
return _nullishCoalesce(taker, () => ( "ESTORE"));
|
|
100
|
+
}
|
|
101
|
+
function addressDifferentOf(line1Same, citySame, stateSame, zipSame) {
|
|
102
|
+
return !line1Same || !citySame || !stateSame || !zipSame;
|
|
103
|
+
}
|
|
104
|
+
|
|
47
105
|
// src/address-comparison.ts
|
|
48
106
|
function isAddressDifferent(userAddress, smartyAddress) {
|
|
49
|
-
return
|
|
107
|
+
return addressDifferentOf(
|
|
108
|
+
(_nullishCoalesce(smartyAddress.deliveryLine1, () => ( ""))).toLowerCase() === userAddress.address1.toLowerCase(),
|
|
109
|
+
(_nullishCoalesce(smartyAddress.cityName, () => ( ""))).toLowerCase() === userAddress.city.toLowerCase(),
|
|
110
|
+
smartyAddress.stateAbbreviation === userAddress.state,
|
|
111
|
+
smartyAddress.zipCode === userAddress.postalCode
|
|
112
|
+
);
|
|
50
113
|
}
|
|
51
114
|
|
|
52
115
|
// src/get-payment-status.ts
|
|
53
116
|
function getPaymentStatus(invoice) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
117
|
+
return paymentStatusOf(
|
|
118
|
+
invoice.paidInFullFlag === "Y",
|
|
119
|
+
invoice.amountPaid != null && invoice.totalAmount != null,
|
|
120
|
+
_nullishCoalesce(invoice.amountPaid, () => ( 0))
|
|
121
|
+
);
|
|
58
122
|
}
|
|
59
123
|
|
|
60
124
|
// src/transform-ship-to-address.ts
|
|
61
125
|
function str(value) {
|
|
62
126
|
return String(value).trim();
|
|
63
127
|
}
|
|
64
|
-
function
|
|
128
|
+
function firstPresent(raw, keys) {
|
|
65
129
|
for (const k of keys) {
|
|
66
|
-
if (raw[k] != null) return
|
|
130
|
+
if (raw[k] != null) return raw[k];
|
|
67
131
|
}
|
|
68
132
|
return "";
|
|
69
133
|
}
|
|
134
|
+
function pick(raw, keys) {
|
|
135
|
+
return str(firstPresent(raw, keys));
|
|
136
|
+
}
|
|
137
|
+
var PHYS_MARKERS = [
|
|
138
|
+
"physAddress1",
|
|
139
|
+
"phys_address1",
|
|
140
|
+
"physCity",
|
|
141
|
+
"phys_city",
|
|
142
|
+
"physState",
|
|
143
|
+
"phys_state"
|
|
144
|
+
];
|
|
70
145
|
var PHYS_FIELDS = {
|
|
71
146
|
address1: ["physAddress1", "phys_address1"],
|
|
72
147
|
address2: ["physAddress2", "phys_address2"],
|
|
@@ -84,19 +159,19 @@ var MAIL_FIELDS = {
|
|
|
84
159
|
country: ["mailCountry", "mail_country", "country"]
|
|
85
160
|
};
|
|
86
161
|
function transformShipToAddress(raw) {
|
|
87
|
-
const isPhys =
|
|
162
|
+
const isPhys = PHYS_MARKERS.some((k) => raw[k] != null);
|
|
88
163
|
const f = isPhys ? PHYS_FIELDS : MAIL_FIELDS;
|
|
89
164
|
const address = {
|
|
90
|
-
shipToId:
|
|
91
|
-
name:
|
|
92
|
-
address1: pick(raw,
|
|
93
|
-
city: pick(raw,
|
|
94
|
-
state: pick(raw,
|
|
95
|
-
zip: pick(raw,
|
|
165
|
+
shipToId: firstPresent(raw, ["shipToId", "ship_to_id", "id"]),
|
|
166
|
+
name: pick(raw, ["shipToName", "ship_to_name", "name"]),
|
|
167
|
+
address1: pick(raw, f.address1),
|
|
168
|
+
city: pick(raw, f.city),
|
|
169
|
+
state: pick(raw, f.state),
|
|
170
|
+
zip: pick(raw, f.zip)
|
|
96
171
|
};
|
|
97
|
-
const address2 = pick(raw,
|
|
172
|
+
const address2 = pick(raw, f.address2);
|
|
98
173
|
if (address2) address.address2 = address2;
|
|
99
|
-
const country = pick(raw,
|
|
174
|
+
const country = pick(raw, f.country);
|
|
100
175
|
if (country) address.country = country;
|
|
101
176
|
return address;
|
|
102
177
|
}
|
|
@@ -109,7 +184,7 @@ function buildCheckoutPayload(input) {
|
|
|
109
184
|
sales_location_id: input.salesLocationId,
|
|
110
185
|
user_id: input.userId,
|
|
111
186
|
user_email: input.userEmail,
|
|
112
|
-
taker:
|
|
187
|
+
taker: takerOf(input.taker)
|
|
113
188
|
};
|
|
114
189
|
if (input.poNumber != null) oe_hdr.customer_po_no = input.poNumber;
|
|
115
190
|
if (input.shipToId != null) oe_hdr.ship_to_id = input.shipToId;
|
|
@@ -127,47 +202,95 @@ function buildCheckoutPayload(input) {
|
|
|
127
202
|
return { oe_hdr, oe_line };
|
|
128
203
|
}
|
|
129
204
|
|
|
130
|
-
// src/
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
205
|
+
// src/money.ts
|
|
206
|
+
var MONEY_DECIMALS = 8;
|
|
207
|
+
var MAX_SHIFTED = 2 ** 51;
|
|
208
|
+
function shiftDecimal(value, places) {
|
|
209
|
+
const [mantissa, exponent = "0"] = String(value).split("e");
|
|
210
|
+
return Number(`${mantissa}e${Number(exponent) + places}`);
|
|
211
|
+
}
|
|
212
|
+
function roundHalfAway(value, decimals) {
|
|
213
|
+
if (!Number.isInteger(decimals) || decimals < 0) {
|
|
134
214
|
throw new RangeError(
|
|
135
|
-
`
|
|
215
|
+
`roundHalfAway: decimals must be a non-negative integer, got ${String(decimals)}`
|
|
136
216
|
);
|
|
137
217
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
218
|
+
if (!Number.isFinite(value)) return value;
|
|
219
|
+
const shifted = shiftDecimal(Math.abs(value), decimals);
|
|
220
|
+
if (!(shifted < MAX_SHIFTED)) return value;
|
|
221
|
+
const rounded = Math.round(shifted);
|
|
222
|
+
if (rounded === 0) return 0;
|
|
223
|
+
return Math.sign(value) * shiftDecimal(rounded, -decimals);
|
|
224
|
+
}
|
|
225
|
+
function cleanMoney(value) {
|
|
226
|
+
return roundHalfAway(value, MONEY_DECIMALS);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// src/price-outcome.ts
|
|
230
|
+
function priceOutcome(quantityOk, hasPrice, priceFinite, unitPrice) {
|
|
231
|
+
if (!quantityOk) return "badQuantity";
|
|
232
|
+
if (!hasPrice) return "loading";
|
|
233
|
+
if (!priceFinite || unitPrice < 0) return "badPrice";
|
|
234
|
+
if (unitPrice === 0) return "callForPrice";
|
|
235
|
+
return "priced";
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// src/derive-price.ts
|
|
239
|
+
function outcomeError(outcome, quantity, unitPrice) {
|
|
240
|
+
if (outcome === "badQuantity") {
|
|
241
|
+
return new RangeError(
|
|
242
|
+
`derivePrice: quantity must be a non-negative finite number, got ${String(quantity)}`
|
|
243
|
+
);
|
|
141
244
|
}
|
|
142
|
-
if (
|
|
143
|
-
|
|
245
|
+
if (outcome === "badPrice") {
|
|
246
|
+
return new RangeError(
|
|
144
247
|
`derivePrice: unitPrice must be a non-negative finite number, got ${String(unitPrice)}`
|
|
145
248
|
);
|
|
146
249
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
function outcomeFor(priceData, unitPrice, quantity) {
|
|
253
|
+
const hasPrice = priceData != null && unitPrice != null;
|
|
254
|
+
return priceOutcome(
|
|
255
|
+
Number.isFinite(quantity) && quantity >= 0,
|
|
256
|
+
hasPrice,
|
|
257
|
+
Number.isFinite(unitPrice),
|
|
258
|
+
// Read only when hasPrice is true; the 0 is never compared then.
|
|
259
|
+
_nullishCoalesce(unitPrice, () => ( 0))
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
function derivePrice(input) {
|
|
263
|
+
const { priceData, quantity = 1 } = input;
|
|
264
|
+
const unitPrice = _optionalChain([priceData, 'optionalAccess', _ => _.unitPrice]);
|
|
265
|
+
const outcome = outcomeFor(priceData, unitPrice, quantity);
|
|
266
|
+
const error = outcomeError(outcome, quantity, unitPrice);
|
|
267
|
+
if (error) throw error;
|
|
268
|
+
if (outcome === "loading") return { state: "loading" };
|
|
269
|
+
const record = priceData;
|
|
270
|
+
const price = unitPrice;
|
|
271
|
+
const unitOfMeasure = _nullishCoalesce(_optionalChain([record, 'access', _2 => _2.item, 'optionalAccess', _3 => _3.unitOfMeasure]), () => ( ""));
|
|
272
|
+
if (outcome === "callForPrice") return { state: "callForPrice", unitOfMeasure };
|
|
273
|
+
return { state: "priced", unitPrice: price, total: cleanMoney(price * quantity), unitOfMeasure };
|
|
152
274
|
}
|
|
153
275
|
|
|
154
276
|
// src/resolve-stock.ts
|
|
277
|
+
function summaryQuantity(companySummary, companyKey) {
|
|
278
|
+
if (companyKey && companyKey in companySummary) {
|
|
279
|
+
return _nullishCoalesce(companySummary[companyKey], () => ( 0));
|
|
280
|
+
}
|
|
281
|
+
return Object.values(companySummary).reduce((sum, val) => sum + val, 0);
|
|
282
|
+
}
|
|
283
|
+
function allDiscontinued(stockData) {
|
|
284
|
+
return isDiscontinuedOf(stockData.map((d) => d.discontinued));
|
|
285
|
+
}
|
|
155
286
|
function resolveStock(input) {
|
|
156
287
|
const { stock, companyKey, round = false, lowStockThreshold = 0, showQuantity = false } = input;
|
|
157
288
|
if (!stock) return null;
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
if (companyKey && companyKey in companySummary) {
|
|
161
|
-
qty = _nullishCoalesce(companySummary[companyKey], () => ( 0));
|
|
162
|
-
} else {
|
|
163
|
-
qty = Object.values(companySummary).reduce((sum, val) => sum + val, 0);
|
|
164
|
-
}
|
|
165
|
-
if (round) {
|
|
166
|
-
qty = Math.round(qty);
|
|
167
|
-
}
|
|
289
|
+
const summed = summaryQuantity(stock.companySummary, companyKey);
|
|
290
|
+
const qty = round ? Math.round(summed) : summed;
|
|
168
291
|
const isInStock = qty > 0;
|
|
169
|
-
const isLowStock =
|
|
170
|
-
const isDiscontinued = stock.stockData
|
|
292
|
+
const isLowStock = isLowStockOf(qty, lowStockThreshold);
|
|
293
|
+
const isDiscontinued = allDiscontinued(stock.stockData);
|
|
171
294
|
return {
|
|
172
295
|
quantity: qty,
|
|
173
296
|
isInStock,
|
|
@@ -179,13 +302,238 @@ function resolveStock(input) {
|
|
|
179
302
|
|
|
180
303
|
// src/schema-availability.ts
|
|
181
304
|
function getSchemaAvailability(resolved) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
305
|
+
return SCHEMA_URLS[availabilityOf(!!_optionalChain([resolved, 'optionalAccess', _4 => _4.isInStock]), !!_optionalChain([resolved, 'optionalAccess', _5 => _5.isDiscontinued]))];
|
|
306
|
+
}
|
|
307
|
+
var SCHEMA_URLS = {
|
|
308
|
+
InStock: "https://schema.org/InStock",
|
|
309
|
+
OutOfStock: "https://schema.org/OutOfStock",
|
|
310
|
+
BackOrder: "https://schema.org/BackOrder"
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
// ../utils/src/strings.ts
|
|
314
|
+
function codeAt(s, i) {
|
|
315
|
+
return i >= 0 && i < s.length ? s.charCodeAt(i) : -1;
|
|
316
|
+
}
|
|
317
|
+
function indexOfCode(s, code, from) {
|
|
318
|
+
const c = codeAt(s, from);
|
|
319
|
+
if (c === code) return from;
|
|
320
|
+
if (c === -1) return -1;
|
|
321
|
+
return indexOfCode(s, code, from + 1);
|
|
322
|
+
}
|
|
323
|
+
function startsWithAt(s, x, pos) {
|
|
324
|
+
const at = Math.min(pos, s.length);
|
|
325
|
+
return s.slice(at, Math.min(at + x.length, s.length)) === x;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// ../utils/src/lists.ts
|
|
329
|
+
function joinFrom(xs, sep, i) {
|
|
330
|
+
if (i >= xs.length) return "";
|
|
331
|
+
return joinRange(xs, sep, i, xs.length);
|
|
332
|
+
}
|
|
333
|
+
function joinRange(xs, sep, lo, hi) {
|
|
334
|
+
if (hi - lo === 1) return xs[lo];
|
|
335
|
+
const mid = lo + Math.floor((hi - lo) / 2);
|
|
336
|
+
return joinRange(xs, sep, lo, mid) + sep + joinRange(xs, sep, mid, hi);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// ../utils/src/replace.ts
|
|
340
|
+
function codeIndex(codes, c, i) {
|
|
341
|
+
if (i === codes.length) return -1;
|
|
342
|
+
return codes[i] === c ? i : codeIndex(codes, c, i + 1);
|
|
343
|
+
}
|
|
344
|
+
function substitute(s, codes, texts) {
|
|
345
|
+
let out = "";
|
|
346
|
+
for (let i = 0; i !== s.length; i++) {
|
|
347
|
+
const k = codeIndex(codes, s.charCodeAt(i), 0);
|
|
348
|
+
out = k >= 0 && k < texts.length ? out + texts[k] : out + s.slice(i, i + 1);
|
|
187
349
|
}
|
|
188
|
-
return
|
|
350
|
+
return out;
|
|
351
|
+
}
|
|
352
|
+
function jsonCodes() {
|
|
353
|
+
return [
|
|
354
|
+
34,
|
|
355
|
+
92,
|
|
356
|
+
8,
|
|
357
|
+
9,
|
|
358
|
+
10,
|
|
359
|
+
12,
|
|
360
|
+
13,
|
|
361
|
+
0,
|
|
362
|
+
1,
|
|
363
|
+
2,
|
|
364
|
+
3,
|
|
365
|
+
4,
|
|
366
|
+
5,
|
|
367
|
+
6,
|
|
368
|
+
7,
|
|
369
|
+
11,
|
|
370
|
+
14,
|
|
371
|
+
15,
|
|
372
|
+
16,
|
|
373
|
+
17,
|
|
374
|
+
18,
|
|
375
|
+
19,
|
|
376
|
+
20,
|
|
377
|
+
21,
|
|
378
|
+
22,
|
|
379
|
+
23,
|
|
380
|
+
24,
|
|
381
|
+
25,
|
|
382
|
+
26,
|
|
383
|
+
27,
|
|
384
|
+
28,
|
|
385
|
+
29,
|
|
386
|
+
30,
|
|
387
|
+
31
|
|
388
|
+
];
|
|
389
|
+
}
|
|
390
|
+
function jsonTexts() {
|
|
391
|
+
return [
|
|
392
|
+
'\\"',
|
|
393
|
+
"\\\\",
|
|
394
|
+
"\\b",
|
|
395
|
+
"\\t",
|
|
396
|
+
"\\n",
|
|
397
|
+
"\\f",
|
|
398
|
+
"\\r",
|
|
399
|
+
"\\u0000",
|
|
400
|
+
"\\u0001",
|
|
401
|
+
"\\u0002",
|
|
402
|
+
"\\u0003",
|
|
403
|
+
"\\u0004",
|
|
404
|
+
"\\u0005",
|
|
405
|
+
"\\u0006",
|
|
406
|
+
"\\u0007",
|
|
407
|
+
"\\u000b",
|
|
408
|
+
"\\u000e",
|
|
409
|
+
"\\u000f",
|
|
410
|
+
"\\u0010",
|
|
411
|
+
"\\u0011",
|
|
412
|
+
"\\u0012",
|
|
413
|
+
"\\u0013",
|
|
414
|
+
"\\u0014",
|
|
415
|
+
"\\u0015",
|
|
416
|
+
"\\u0016",
|
|
417
|
+
"\\u0017",
|
|
418
|
+
"\\u0018",
|
|
419
|
+
"\\u0019",
|
|
420
|
+
"\\u001a",
|
|
421
|
+
"\\u001b",
|
|
422
|
+
"\\u001c",
|
|
423
|
+
"\\u001d",
|
|
424
|
+
"\\u001e",
|
|
425
|
+
"\\u001f"
|
|
426
|
+
];
|
|
427
|
+
}
|
|
428
|
+
function jsonString(s) {
|
|
429
|
+
return '"' + substitute(s, jsonCodes(), jsonTexts()) + '"';
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// ../utils/src/json.ts
|
|
433
|
+
function jsonPair(key, value) {
|
|
434
|
+
return jsonString(key) + ":" + value;
|
|
435
|
+
}
|
|
436
|
+
function jsonTextPair(key, value) {
|
|
437
|
+
return jsonString(key) + ":" + jsonString(value);
|
|
438
|
+
}
|
|
439
|
+
function jsonObject(pairs) {
|
|
440
|
+
return "{" + joinFrom(pairs, ",", 0) + "}";
|
|
441
|
+
}
|
|
442
|
+
function jsonArray(items) {
|
|
443
|
+
return "[" + joinFrom(items, ",", 0) + "]";
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// ../utils/src/decimal.ts
|
|
447
|
+
function decimal(n) {
|
|
448
|
+
const last = "0123456789".slice(n % 10, n % 10 + 1);
|
|
449
|
+
return n < 10 ? last : decimal(Math.floor(n / 10)) + last;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// ../utils/src/json-ld-items.ts
|
|
453
|
+
function nodeHead(type) {
|
|
454
|
+
return [jsonTextPair("@context", "https://schema.org"), jsonTextPair("@type", type)];
|
|
455
|
+
}
|
|
456
|
+
function crumbItemsFrom(crumbs, i) {
|
|
457
|
+
if (i >= crumbs.length) return [];
|
|
458
|
+
const crumb = crumbs[i];
|
|
459
|
+
return [
|
|
460
|
+
jsonObject([
|
|
461
|
+
jsonTextPair("@type", "ListItem"),
|
|
462
|
+
jsonPair("position", decimal(i + 1)),
|
|
463
|
+
jsonTextPair("name", crumb.name),
|
|
464
|
+
jsonTextPair("item", crumb.url)
|
|
465
|
+
]),
|
|
466
|
+
...crumbItemsFrom(crumbs, i + 1)
|
|
467
|
+
];
|
|
468
|
+
}
|
|
469
|
+
function faqItemsFrom(faqs, i) {
|
|
470
|
+
if (i >= faqs.length) return [];
|
|
471
|
+
const faq = faqs[i];
|
|
472
|
+
return [
|
|
473
|
+
jsonObject([
|
|
474
|
+
jsonTextPair("@type", "Question"),
|
|
475
|
+
jsonTextPair("name", faq.question),
|
|
476
|
+
jsonPair(
|
|
477
|
+
"acceptedAnswer",
|
|
478
|
+
jsonObject([jsonTextPair("@type", "Answer"), jsonTextPair("text", faq.answer)])
|
|
479
|
+
)
|
|
480
|
+
]),
|
|
481
|
+
...faqItemsFrom(faqs, i + 1)
|
|
482
|
+
];
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// ../utils/src/json-ld.ts
|
|
486
|
+
function idRef(id) {
|
|
487
|
+
return jsonObject([jsonTextPair("@id", id)]);
|
|
488
|
+
}
|
|
489
|
+
function breadcrumbLd(crumbs) {
|
|
490
|
+
return jsonObject([
|
|
491
|
+
...nodeHead("BreadcrumbList"),
|
|
492
|
+
jsonPair("itemListElement", jsonArray(crumbItemsFrom(crumbs, 0)))
|
|
493
|
+
]);
|
|
494
|
+
}
|
|
495
|
+
function faqLd(faqs) {
|
|
496
|
+
return jsonObject([
|
|
497
|
+
...nodeHead("FAQPage"),
|
|
498
|
+
jsonPair("mainEntity", jsonArray(faqItemsFrom(faqs, 0)))
|
|
499
|
+
]);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// src/json-ld-rules.ts
|
|
503
|
+
function breadcrumbPosition(i) {
|
|
504
|
+
return i + 1;
|
|
505
|
+
}
|
|
506
|
+
function gtinFieldOf(upper) {
|
|
507
|
+
if (upper === "UPC") return "gtin12";
|
|
508
|
+
if (upper === "EAN") return "gtin13";
|
|
509
|
+
return "gtin";
|
|
510
|
+
}
|
|
511
|
+
function isSuppressedOf(deleteFlag, onlineCd, statusCd) {
|
|
512
|
+
return deleteFlag === "Y" || onlineCd === 0 || statusCd === 0;
|
|
513
|
+
}
|
|
514
|
+
function productNameOf(suppressed, name, unitPrice) {
|
|
515
|
+
if (suppressed) return null;
|
|
516
|
+
if (name === "" || unitPrice <= 0) return null;
|
|
517
|
+
return name;
|
|
518
|
+
}
|
|
519
|
+
function firstNonBlankOf(a, b) {
|
|
520
|
+
if (a !== "") return a;
|
|
521
|
+
if (b !== "") return b;
|
|
522
|
+
return void 0;
|
|
523
|
+
}
|
|
524
|
+
function primarySupplierFrom(flags, i) {
|
|
525
|
+
if (i >= flags.length) return -1;
|
|
526
|
+
if (flags[i] === "Y") return i;
|
|
527
|
+
return primarySupplierFrom(flags, i + 1);
|
|
528
|
+
}
|
|
529
|
+
function supplierIndexOf(flags) {
|
|
530
|
+
const primary = primarySupplierFrom(flags, 0);
|
|
531
|
+
if (primary >= 0) return primary;
|
|
532
|
+
return flags.length > 0 ? 0 : -1;
|
|
533
|
+
}
|
|
534
|
+
function offerUrlOf(siteUrl, itemPath, itemId) {
|
|
535
|
+
if (siteUrl === "") return void 0;
|
|
536
|
+
return siteUrl + itemPath + "/" + itemId;
|
|
189
537
|
}
|
|
190
538
|
|
|
191
539
|
// src/json-ld.ts
|
|
@@ -195,21 +543,21 @@ function generateBreadcrumbJsonLd(items) {
|
|
|
195
543
|
"@type": "BreadcrumbList",
|
|
196
544
|
itemListElement: items.map((item, index) => ({
|
|
197
545
|
"@type": "ListItem",
|
|
198
|
-
position: index
|
|
546
|
+
position: breadcrumbPosition(index),
|
|
199
547
|
name: item.name,
|
|
200
548
|
item: item.url
|
|
201
549
|
}))
|
|
202
550
|
};
|
|
203
551
|
}
|
|
552
|
+
var breadcrumbLd2 = breadcrumbLd;
|
|
553
|
+
var faqLd2 = faqLd;
|
|
554
|
+
var nodeHead2 = nodeHead;
|
|
555
|
+
var idRef2 = idRef;
|
|
204
556
|
function getGtinField(upcOrEan) {
|
|
205
|
-
|
|
206
|
-
if (val === "UPC") return "gtin12";
|
|
207
|
-
if (val === "EAN") return "gtin13";
|
|
208
|
-
return "gtin";
|
|
557
|
+
return gtinFieldOf(_nullishCoalesce(_optionalChain([upcOrEan, 'optionalAccess', _6 => _6.toUpperCase, 'call', _7 => _7()]), () => ( "")));
|
|
209
558
|
}
|
|
210
559
|
function getPrimarySupplierPartNo(suppliers) {
|
|
211
|
-
const
|
|
212
|
-
const supplier = _nullishCoalesce(primary, () => ( suppliers[0]));
|
|
560
|
+
const supplier = suppliers[supplierIndexOf(suppliers.map((s) => _nullishCoalesce(s.primarySupplierFlag, () => ( ""))))];
|
|
213
561
|
const partNo = _optionalChain([supplier, 'optionalAccess', _8 => _8.supplierPartNo, 'optionalAccess', _9 => _9.trim, 'call', _10 => _10()]);
|
|
214
562
|
return partNo || void 0;
|
|
215
563
|
}
|
|
@@ -234,14 +582,12 @@ function omitEmpty(obj) {
|
|
|
234
582
|
return result;
|
|
235
583
|
}
|
|
236
584
|
function resolveBrand(doc) {
|
|
237
|
-
const name = _optionalChain([doc, 'access', _11 => _11.brandName, 'optionalAccess', _12 => _12.trim, 'call', _13 => _13()])
|
|
238
|
-
if (
|
|
585
|
+
const name = firstNonBlankOf(_nullishCoalesce(_optionalChain([doc, 'access', _11 => _11.brandName, 'optionalAccess', _12 => _12.trim, 'call', _13 => _13()]), () => ( "")), _nullishCoalesce(_optionalChain([doc, 'access', _14 => _14.parkerProductCd, 'optionalAccess', _15 => _15.trim, 'call', _16 => _16()]), () => ( "")));
|
|
586
|
+
if (name === void 0) return void 0;
|
|
239
587
|
return { "@type": "Brand", name };
|
|
240
588
|
}
|
|
241
589
|
function resolveDescription(doc) {
|
|
242
|
-
|
|
243
|
-
if (_optionalChain([doc, 'access', _20 => _20.extendedDesc, 'optionalAccess', _21 => _21.trim, 'call', _22 => _22()])) return doc.extendedDesc.trim();
|
|
244
|
-
return void 0;
|
|
590
|
+
return firstNonBlankOf(_nullishCoalesce(_optionalChain([doc, 'access', _17 => _17.displayDesc, 'optionalAccess', _18 => _18.trim, 'call', _19 => _19()]), () => ( "")), _nullishCoalesce(_optionalChain([doc, 'access', _20 => _20.extendedDesc, 'optionalAccess', _21 => _21.trim, 'call', _22 => _22()]), () => ( "")));
|
|
245
591
|
}
|
|
246
592
|
function resolveImages(doc, transform2) {
|
|
247
593
|
if (doc.images.length === 0) return void 0;
|
|
@@ -255,7 +601,7 @@ function buildOffers(doc, options) {
|
|
|
255
601
|
const availability = getSchemaAvailability(resolved);
|
|
256
602
|
const validUntil = /* @__PURE__ */ new Date();
|
|
257
603
|
validUntil.setDate(validUntil.getDate() + priceValidDays);
|
|
258
|
-
const url = options.siteUrl
|
|
604
|
+
const url = offerUrlOf(_nullishCoalesce(options.siteUrl, () => ( "")), itemPath, doc.itemId);
|
|
259
605
|
const eligibleQuantity = _optionalChain([doc, 'access', _23 => _23.defaultSellingUnit, 'optionalAccess', _24 => _24.trim, 'call', _25 => _25()]) ? { "@type": "QuantitativeValue", unitCode: doc.defaultSellingUnit.trim() } : void 0;
|
|
260
606
|
const seller = options.seller ? { "@type": "Organization", name: options.seller.name, url: options.seller.url } : void 0;
|
|
261
607
|
return {
|
|
@@ -272,22 +618,25 @@ function buildOffers(doc, options) {
|
|
|
272
618
|
shippingDetails: options.shippingDetails
|
|
273
619
|
};
|
|
274
620
|
}
|
|
275
|
-
function
|
|
276
|
-
|
|
621
|
+
function productName(doc, unitPrice) {
|
|
622
|
+
const suppressed = isSuppressedOf(doc.deleteFlag, doc.onlineCd, doc.statusCd);
|
|
623
|
+
return productNameOf(suppressed, (doc.itemDesc || "").trim(), unitPrice);
|
|
624
|
+
}
|
|
625
|
+
function buildAggregateRating(rating) {
|
|
626
|
+
if (!rating) return void 0;
|
|
627
|
+
return {
|
|
628
|
+
"@type": "AggregateRating",
|
|
629
|
+
ratingValue: rating.ratingValue,
|
|
630
|
+
reviewCount: rating.reviewCount
|
|
631
|
+
};
|
|
277
632
|
}
|
|
278
633
|
function generateProductJsonLd(doc, options) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
if (!name) return null;
|
|
282
|
-
if (options.unitPrice <= 0) return null;
|
|
634
|
+
const name = productName(doc, options.unitPrice);
|
|
635
|
+
if (name === null) return null;
|
|
283
636
|
const weightUnit = _nullishCoalesce(options.weightUnit, () => ( "LBR"));
|
|
284
637
|
const dimensionUnit = _nullishCoalesce(options.dimensionUnit, () => ( "INH"));
|
|
285
638
|
const gtinId = _optionalChain([doc, 'access', _26 => _26.upcOrEanId, 'optionalAccess', _27 => _27.trim, 'call', _28 => _28()]) || void 0;
|
|
286
|
-
const aggregateRating = options.aggregateRating
|
|
287
|
-
"@type": "AggregateRating",
|
|
288
|
-
ratingValue: options.aggregateRating.ratingValue,
|
|
289
|
-
reviewCount: options.aggregateRating.reviewCount
|
|
290
|
-
} : void 0;
|
|
639
|
+
const aggregateRating = buildAggregateRating(options.aggregateRating);
|
|
291
640
|
const product = {
|
|
292
641
|
"@context": "https://schema.org",
|
|
293
642
|
"@type": "Product",
|
|
@@ -311,23 +660,77 @@ function generateProductJsonLd(doc, options) {
|
|
|
311
660
|
|
|
312
661
|
// src/result.ts
|
|
313
662
|
function unwrap(result) {
|
|
314
|
-
if (!result.ok) throw new Error(result.error
|
|
663
|
+
if (!result.ok) throw new Error(unwrapMessage(result.error));
|
|
315
664
|
return result.data;
|
|
316
665
|
}
|
|
317
666
|
function unwrapOr(result) {
|
|
318
667
|
return result.ok ? _nullishCoalesce(result.data, () => ( null)) : null;
|
|
319
668
|
}
|
|
320
669
|
|
|
670
|
+
// src/image-rules.ts
|
|
671
|
+
function transformKeyOf(field) {
|
|
672
|
+
if (field === "width") return "w";
|
|
673
|
+
if (field === "height") return "h";
|
|
674
|
+
if (field === "format") return "f";
|
|
675
|
+
if (field === "quality") return "q";
|
|
676
|
+
if (field === "fit") return "fit";
|
|
677
|
+
return "";
|
|
678
|
+
}
|
|
679
|
+
function transformValueOf(field, value) {
|
|
680
|
+
if (field === "format" && value === "jpg") return "jpeg";
|
|
681
|
+
return value;
|
|
682
|
+
}
|
|
683
|
+
function transformPartsFrom(fields, present, texts, i) {
|
|
684
|
+
if (i >= fields.length) return [];
|
|
685
|
+
const field = fields[i];
|
|
686
|
+
const key = transformKeyOf(field);
|
|
687
|
+
const rest = transformPartsFrom(fields, present, texts, i + 1);
|
|
688
|
+
if (present[i] && key !== "") {
|
|
689
|
+
return [key + "_" + transformValueOf(field, texts[i]), ...rest];
|
|
690
|
+
}
|
|
691
|
+
return rest;
|
|
692
|
+
}
|
|
693
|
+
function serializedTransforms(fields, present, texts) {
|
|
694
|
+
return joinFrom(transformPartsFrom(fields, present, texts, 0), ",", 0);
|
|
695
|
+
}
|
|
696
|
+
function isExternal(path) {
|
|
697
|
+
return startsWithAt(path, "http", 0);
|
|
698
|
+
}
|
|
699
|
+
function stripFirstPrefixFrom(path, prefixes, i) {
|
|
700
|
+
if (i >= prefixes.length) return path;
|
|
701
|
+
const prefix = prefixes[i];
|
|
702
|
+
if (startsWithAt(path, prefix, 0)) return path.slice(prefix.length);
|
|
703
|
+
return stripFirstPrefixFrom(path, prefixes, i + 1);
|
|
704
|
+
}
|
|
705
|
+
function stripLeadingSlashes(s) {
|
|
706
|
+
if (codeAt(s, 0) !== 47) return s;
|
|
707
|
+
return stripLeadingSlashes(s.slice(1));
|
|
708
|
+
}
|
|
709
|
+
function normalizedPath(raw, prefixes, defaultPath) {
|
|
710
|
+
if (isExternal(raw)) return raw;
|
|
711
|
+
const cleaned = stripLeadingSlashes(stripFirstPrefixFrom(raw, prefixes, 0));
|
|
712
|
+
if (defaultPath !== "" && indexOfCode(cleaned, 47, 0) < 0) return defaultPath + "/" + cleaned;
|
|
713
|
+
return cleaned;
|
|
714
|
+
}
|
|
715
|
+
function cdnUrlOf(clientDomain, serialized, normalized) {
|
|
716
|
+
const segment = serialized !== "" ? "/" + serialized : "";
|
|
717
|
+
return "https://agr.media/" + clientDomain + "/images" + segment + "/" + normalized;
|
|
718
|
+
}
|
|
719
|
+
function defaultImageUrlOf(clientDomain, fallback, prefixes, defaultPath) {
|
|
720
|
+
if (fallback === "") return "";
|
|
721
|
+
const normalized = normalizedPath(fallback, prefixes, defaultPath);
|
|
722
|
+
if (isExternal(normalized)) return normalized;
|
|
723
|
+
return "https://agr.media/" + clientDomain + "/images/" + normalized;
|
|
724
|
+
}
|
|
725
|
+
function imageUrlOf(clientDomain, path, serialized, fallback, prefixes, defaultPath) {
|
|
726
|
+
if (path === "") return defaultImageUrlOf(clientDomain, fallback, prefixes, defaultPath);
|
|
727
|
+
const normalized = normalizedPath(path, prefixes, defaultPath);
|
|
728
|
+
if (isExternal(normalized)) return normalized;
|
|
729
|
+
return cdnUrlOf(clientDomain, serialized, normalized);
|
|
730
|
+
}
|
|
731
|
+
|
|
321
732
|
// src/image.ts
|
|
322
733
|
var BLUR_DATA_URL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mN88P/BfwYABQoBfqVKzQAAAABJRU5ErkJggg==";
|
|
323
|
-
var CDN_BASE = "https://agr.media";
|
|
324
|
-
var TRANSFORM_KEY_MAP = {
|
|
325
|
-
width: "w",
|
|
326
|
-
height: "h",
|
|
327
|
-
format: "f",
|
|
328
|
-
quality: "q",
|
|
329
|
-
fit: "fit"
|
|
330
|
-
};
|
|
331
734
|
var DEFAULT_STRIP_PREFIXES = ["/images", "images"];
|
|
332
735
|
function createImageConfig(clientDomain, opts) {
|
|
333
736
|
return Object.freeze({
|
|
@@ -339,54 +742,43 @@ function createImageConfig(clientDomain, opts) {
|
|
|
339
742
|
});
|
|
340
743
|
}
|
|
341
744
|
function serializeTransforms(transforms) {
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
parts.push(`${prefix}_${v2}`);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
return parts.join(",");
|
|
745
|
+
const entries = Object.entries(transforms);
|
|
746
|
+
return serializedTransforms(
|
|
747
|
+
entries.map(([key]) => key),
|
|
748
|
+
entries.map(([, value]) => value !== void 0),
|
|
749
|
+
entries.map(([, value]) => String(value))
|
|
750
|
+
);
|
|
352
751
|
}
|
|
353
752
|
function normalizePath(config, raw) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
if (cleaned.startsWith(prefix)) {
|
|
359
|
-
cleaned = cleaned.slice(prefix.length);
|
|
360
|
-
break;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
cleaned = cleaned.replace(/^\/+/, "");
|
|
364
|
-
if (config.defaultPath && !cleaned.includes("/")) {
|
|
365
|
-
cleaned = `${config.defaultPath}/${cleaned}`;
|
|
366
|
-
}
|
|
367
|
-
return cleaned;
|
|
753
|
+
return normalizedPath(raw, prefixesOf(config), _nullishCoalesce(config.defaultPath, () => ( "")));
|
|
754
|
+
}
|
|
755
|
+
function prefixesOf(config) {
|
|
756
|
+
return _nullishCoalesce(config.stripPrefixes, () => ( DEFAULT_STRIP_PREFIXES));
|
|
368
757
|
}
|
|
369
758
|
function getImageUrl(config, imagePath, transforms, options) {
|
|
370
|
-
const resolvedPath = _optionalChain([imagePath, 'optionalAccess', _33 => _33.trim, 'call', _34 => _34()]);
|
|
371
|
-
if (!resolvedPath) {
|
|
372
|
-
return getDefaultImageUrl(config, options);
|
|
373
|
-
}
|
|
374
|
-
const normalized = normalizePath(config, resolvedPath);
|
|
375
|
-
if (normalized.startsWith("http")) return normalized;
|
|
376
759
|
const merged = {
|
|
377
760
|
...config.defaultTransforms,
|
|
378
761
|
...transforms
|
|
379
762
|
};
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
763
|
+
return imageUrlOf(
|
|
764
|
+
config.clientDomain,
|
|
765
|
+
_nullishCoalesce(_optionalChain([imagePath, 'optionalAccess', _33 => _33.trim, 'call', _34 => _34()]), () => ( "")),
|
|
766
|
+
serializeTransforms(merged),
|
|
767
|
+
fallbackOf(config, options),
|
|
768
|
+
prefixesOf(config),
|
|
769
|
+
_nullishCoalesce(config.defaultPath, () => ( ""))
|
|
770
|
+
);
|
|
383
771
|
}
|
|
384
772
|
function getDefaultImageUrl(config, options) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
773
|
+
return defaultImageUrlOf(
|
|
774
|
+
config.clientDomain,
|
|
775
|
+
fallbackOf(config, options),
|
|
776
|
+
prefixesOf(config),
|
|
777
|
+
_nullishCoalesce(config.defaultPath, () => ( ""))
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
function fallbackOf(config, options) {
|
|
781
|
+
return _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _35 => _35.defaultImage]), () => ( config.defaultImage)), () => ( ""));
|
|
390
782
|
}
|
|
391
783
|
function getImageSrcSet(config, imagePath, widths, transforms) {
|
|
392
784
|
return widths.map((w) => {
|
|
@@ -448,20 +840,20 @@ var US_TERRITORIES = _statesus.states.filter((s) => s.territory);
|
|
|
448
840
|
|
|
449
841
|
// src/address-schemas.ts
|
|
450
842
|
var validStateCodes = US_STATES.map((state) => state.code);
|
|
843
|
+
function personName(requiredMessage, invalidMessage) {
|
|
844
|
+
return v.pipe(
|
|
845
|
+
v.string(),
|
|
846
|
+
v.minLength(1, requiredMessage),
|
|
847
|
+
v.regex(VALIDATION_PATTERNS.nameFormat, invalidMessage),
|
|
848
|
+
v.regex(VALIDATION_PATTERNS.nameNoNumbers, invalidMessage)
|
|
849
|
+
);
|
|
850
|
+
}
|
|
851
|
+
var firstName = personName("First name is required", "Invalid first name");
|
|
852
|
+
var lastName = personName("Last name is required", "Invalid last name");
|
|
451
853
|
var ShippingAddressSchema = v.object({
|
|
452
854
|
companyName: v.optional(v.string()),
|
|
453
|
-
firstName
|
|
454
|
-
|
|
455
|
-
v.minLength(1, "First name is required"),
|
|
456
|
-
v.regex(VALIDATION_PATTERNS.nameFormat, "Invalid first name"),
|
|
457
|
-
v.regex(VALIDATION_PATTERNS.nameNoNumbers, "Invalid first name")
|
|
458
|
-
),
|
|
459
|
-
lastName: v.pipe(
|
|
460
|
-
v.string(),
|
|
461
|
-
v.minLength(1, "Last name is required"),
|
|
462
|
-
v.regex(VALIDATION_PATTERNS.nameFormat, "Invalid last name"),
|
|
463
|
-
v.regex(VALIDATION_PATTERNS.nameNoNumbers, "Invalid last name")
|
|
464
|
-
),
|
|
855
|
+
firstName,
|
|
856
|
+
lastName,
|
|
465
857
|
address1: v.pipe(
|
|
466
858
|
v.string(),
|
|
467
859
|
v.minLength(1, "Address 1 is required"),
|
|
@@ -516,18 +908,8 @@ var ShippingAddressSchema = v.object({
|
|
|
516
908
|
});
|
|
517
909
|
var BillingAddressSchema = v.object({
|
|
518
910
|
poNumber: v.optional(v.string()),
|
|
519
|
-
firstName
|
|
520
|
-
|
|
521
|
-
v.minLength(1, "First name is required"),
|
|
522
|
-
v.regex(VALIDATION_PATTERNS.nameFormat, "Invalid first name"),
|
|
523
|
-
v.regex(VALIDATION_PATTERNS.nameNoNumbers, "Invalid first name")
|
|
524
|
-
),
|
|
525
|
-
lastName: v.pipe(
|
|
526
|
-
v.string(),
|
|
527
|
-
v.minLength(1, "Last name is required"),
|
|
528
|
-
v.regex(VALIDATION_PATTERNS.nameFormat, "Invalid last name"),
|
|
529
|
-
v.regex(VALIDATION_PATTERNS.nameNoNumbers, "Invalid last name")
|
|
530
|
-
),
|
|
911
|
+
firstName,
|
|
912
|
+
lastName,
|
|
531
913
|
address1: v.pipe(
|
|
532
914
|
v.string(),
|
|
533
915
|
v.minLength(1, "Address 1 is required"),
|
|
@@ -557,24 +939,15 @@ function getBusinessDay(businessDaysFromNow) {
|
|
|
557
939
|
const date = /* @__PURE__ */ new Date();
|
|
558
940
|
date.setDate(date.getDate() + i);
|
|
559
941
|
const dayName = date.toLocaleDateString("en-US", { weekday: "long" });
|
|
560
|
-
if (dayName
|
|
942
|
+
if (isBusinessDayName(dayName)) {
|
|
561
943
|
businessDays.push(date.toLocaleDateString("en-US", DATE_FORMAT_OPTIONS));
|
|
562
944
|
}
|
|
563
945
|
i++;
|
|
564
946
|
}
|
|
565
947
|
return businessDays[businessDays.length - 1] || "";
|
|
566
948
|
}
|
|
567
|
-
var SHIPPING_LEAD_CONFIG = {
|
|
568
|
-
"1-2": { from: 1, to: 4 },
|
|
569
|
-
"2": { from: 4 },
|
|
570
|
-
"2-3": { from: 2, to: 5 },
|
|
571
|
-
"3": { from: 5 },
|
|
572
|
-
"3-4": { from: 3, to: 6 },
|
|
573
|
-
"4": { from: 6 },
|
|
574
|
-
"5": { from: 7 }
|
|
575
|
-
};
|
|
576
949
|
function getShippingLeadDate(days) {
|
|
577
|
-
const config =
|
|
950
|
+
const config = shippingLeadOf(days);
|
|
578
951
|
if (!config) return "";
|
|
579
952
|
const fromDate = getBusinessDay(config.from);
|
|
580
953
|
if (config.to) {
|
|
@@ -587,10 +960,7 @@ function getShippingLeadDate(days) {
|
|
|
587
960
|
// src/transforms.ts
|
|
588
961
|
function serializeCategoryFilters(filters, options) {
|
|
589
962
|
const { sortByPrefix, includeStock = true } = _nullishCoalesce(options, () => ( {}));
|
|
590
|
-
|
|
591
|
-
if (sortByPrefix && sortBy) {
|
|
592
|
-
sortBy = `${sortByPrefix}${sortBy}`;
|
|
593
|
-
}
|
|
963
|
+
const sortBy = filters.sortBy ? categorySortBy(_nullishCoalesce(sortByPrefix, () => ( "")), filters.sortBy) : filters.sortBy;
|
|
594
964
|
const params = {
|
|
595
965
|
filters: JSON.stringify(filters.filters),
|
|
596
966
|
limit: filters.limit,
|
|
@@ -610,7 +980,7 @@ function serializeSearchParams(filters, options) {
|
|
|
610
980
|
searchType: "query",
|
|
611
981
|
size: filters.limit,
|
|
612
982
|
from: filters.offset,
|
|
613
|
-
sortBy: filters.sortBy
|
|
983
|
+
sortBy: searchSortBy(filters.sortBy),
|
|
614
984
|
classId5List: categoryUid ? String(categoryUid) : void 0,
|
|
615
985
|
filters: _optionalChain([filters, 'access', _36 => _36.filters, 'optionalAccess', _37 => _37.length]) ? JSON.stringify(filters.filters) : void 0,
|
|
616
986
|
sourceFieldsList: sourceFields
|
|
@@ -619,7 +989,7 @@ function serializeSearchParams(filters, options) {
|
|
|
619
989
|
function paginateOffset(filters, pageParam) {
|
|
620
990
|
return {
|
|
621
991
|
...filters,
|
|
622
|
-
offset: pageParam
|
|
992
|
+
offset: pageOffset(pageParam, filters.limit)
|
|
623
993
|
};
|
|
624
994
|
}
|
|
625
995
|
|
|
@@ -637,7 +1007,7 @@ function trackAddToCart({
|
|
|
637
1007
|
event: "add_to_cart",
|
|
638
1008
|
ecommerce: {
|
|
639
1009
|
currency: "USD",
|
|
640
|
-
value:
|
|
1010
|
+
value: roundHalfAway(estimatedCost, 2),
|
|
641
1011
|
items: [
|
|
642
1012
|
{
|
|
643
1013
|
item_id: itemId,
|
|
@@ -685,7 +1055,7 @@ function buildTrackingData({
|
|
|
685
1055
|
const items = cartLines.map((line, index) => {
|
|
686
1056
|
const details = itemDetails[line.itemId];
|
|
687
1057
|
const price = getUnitPrice(line.itemId);
|
|
688
|
-
total
|
|
1058
|
+
total = cleanMoney(total + cleanMoney(price * line.quantity));
|
|
689
1059
|
return {
|
|
690
1060
|
item_id: line.itemId,
|
|
691
1061
|
item_name: _nullishCoalesce(_optionalChain([details, 'optionalAccess', _38 => _38.itemDesc]), () => ( "")),
|
|
@@ -699,7 +1069,8 @@ function buildTrackingData({
|
|
|
699
1069
|
return {
|
|
700
1070
|
event: "begin_checkout",
|
|
701
1071
|
currency,
|
|
702
|
-
|
|
1072
|
+
// toFixed(2) rounds ties wrong (1.005 → "1.00"); roundHalfAway gives 1.01.
|
|
1073
|
+
value: roundHalfAway(total, 2),
|
|
703
1074
|
items
|
|
704
1075
|
};
|
|
705
1076
|
}
|
|
@@ -756,5 +1127,13 @@ function pushTrackingData(data) {
|
|
|
756
1127
|
|
|
757
1128
|
|
|
758
1129
|
|
|
759
|
-
|
|
1130
|
+
|
|
1131
|
+
|
|
1132
|
+
|
|
1133
|
+
|
|
1134
|
+
|
|
1135
|
+
|
|
1136
|
+
|
|
1137
|
+
|
|
1138
|
+
exports.BLUR_DATA_URL = BLUR_DATA_URL; exports.BillingAddressInvoiceSchema = BillingAddressInvoiceSchema; exports.BillingAddressSchema = BillingAddressSchema; exports.CACHE_CONFIG = CACHE_CONFIG; exports.CONTIGUOUS_STATES = CONTIGUOUS_STATES; exports.ShippingAddressSchema = ShippingAddressSchema; exports.US_STATES = US_STATES; exports.US_STATES_FULL = US_STATES_FULL; exports.US_TERRITORIES = US_TERRITORIES; exports.VALIDATION_PATTERNS = VALIDATION_PATTERNS; exports.breadcrumbLd = breadcrumbLd2; exports.buildCheckoutPayload = buildCheckoutPayload; exports.buildImageLoader = buildImageLoader; exports.buildTrackingData = buildTrackingData; exports.categorySortBy = categorySortBy; exports.cleanMoney = cleanMoney; exports.cn = _chunk5UMFBGVAcjs.cn; exports.createImageConfig = createImageConfig; exports.derivePrice = derivePrice; exports.faqLd = faqLd2; exports.formatPrice = formatPrice; exports.generateBreadcrumbJsonLd = generateBreadcrumbJsonLd; exports.generateProductJsonLd = generateProductJsonLd; exports.getBusinessDay = getBusinessDay; exports.getDefaultImageUrl = getDefaultImageUrl; exports.getImageSrcSet = getImageSrcSet; exports.getImageUrl = getImageUrl; exports.getPaymentStatus = getPaymentStatus; exports.getSchemaAvailability = getSchemaAvailability; exports.getShippingLeadDate = getShippingLeadDate; exports.hasPriceBreaks = hasPriceBreaks; exports.idRef = idRef2; exports.isAddressDifferent = isAddressDifferent; exports.nodeHead = nodeHead2; exports.normalizePath = normalizePath; exports.paginateOffset = paginateOffset; exports.pushTrackingData = pushTrackingData; exports.resolveStock = resolveStock; exports.roundHalfAway = roundHalfAway; exports.sanitizeHtmlImages = sanitizeHtmlImages; exports.serializeCategoryFilters = serializeCategoryFilters; exports.serializeSearchParams = serializeSearchParams; exports.serializeTransforms = serializeTransforms; exports.trackAddToCart = trackAddToCart; exports.trackViewItem = trackViewItem; exports.transformShipToAddress = transformShipToAddress; exports.unwrap = unwrap; exports.unwrapOr = unwrapOr;
|
|
760
1139
|
//# sourceMappingURL=index.cjs.map
|