@misiki/gocommerce-connector 0.29.0 → 0.30.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/README.md +1 -0
- package/dist/{index-DOlNI60Y.d.cts → index-BdXhbm20.d.cts} +134 -3
- package/dist/{index-DOlNI60Y.d.ts → index-BdXhbm20.d.ts} +134 -3
- package/dist/index.cjs +184 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +184 -24
- package/dist/index.js.map +1 -1
- package/dist/services/index.cjs +182 -23
- package/dist/services/index.cjs.map +1 -1
- package/dist/services/index.d.cts +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +182 -23
- package/dist/services/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AddOn, a as Address, b as AddressService, c as AppliedDiscount, d as Approval, e as AuthResponse, f as AuthService, g as AutocompleteService, B as B2bPlaced, h as B2bRole, i as B2bService, j as BannerService, k as BaseService, l as BlogService, C as Cart, m as CartLine, n as CartOffer, o as CartService, p as CatalogService, q as Category, r as CategoryService, s as ChatService, t as CheckoutOptions, u as
|
|
1
|
+
export { A as AddOn, a as Address, b as AddressService, c as AppliedDiscount, d as Approval, e as AuthResponse, f as AuthService, g as AutocompleteService, B as B2bPlaced, h as B2bRole, i as B2bService, j as BannerService, k as BaseService, l as BlogService, C as Cart, m as CartLine, n as CartOffer, o as CartService, p as CatalogService, q as Category, r as CategoryService, s as ChatService, t as CheckoutOptions, u as CheckoutQuote, v as CheckoutResult, w as CheckoutService, x as CmsPage, y as Collection, z as CollectionService, D as Company, E as CompanyOrder, F as ContactService, G as CountryService, H as CouponService, I as Credentials, J as Credit, K as CurrencyService, L as Customer, M as CustomizerDesign, N as CustomizerDocument, O as CustomizerEditor, P as CustomizerFile, Q as CustomizerLayer, R as CustomizerSavedDesign, S as CustomizerService, T as CustomizerSetup, U as CustomizerUpload, V as DealService, W as DemoRequestService, X as EngineRequest, Y as EnquiryService, Z as Envelope, _ as FacetValue, $ as Faq, a0 as FaqService, a1 as FeedbackService, a2 as FooterSettings, a3 as FreeShipping, a4 as Fulfillment, a5 as GalleryService, a6 as GooglePlace, a7 as GoogleReview, a8 as GoogleReviewService, a9 as GoogleReviews, aa as GoogleSurvey, ab as HeaderSettings, ac as HomeLayout, ad as HomeLayoutSection, ae as HomeService, af as IdentityAddress, ag as InitService, ah as Invitation, ai as LayoutCollection, aj as LayoutPage, ak as LayoutService, al as Lead, am as ListMeta, an as MeilisearchService, ao as Member, ap as Menu, aq as MenuItem, ar as MenuService, as as MenuSummary, at as Money, au as NewsletterService, av as Offer, aw as OpeningHours, ax as Order, ay as OrderLine, az as OrderService, aA as PageLayout, aB as PageService, aC as PaymentIntent, aD as PaymentMethodService, aE as Plugin, aF as PluginService, aF as PluginsService, aG as PopularSearchService, aH as PopularityService, aI as Postcode, aJ as Product, aK as ProductFacets, aL as ProductOption, aM as ProductService, aN as ProfileService, aO as Quote, aP as REDIRECT_GATEWAYS, aQ as ReelsService, aR as RegionService, aS as RejectedLine, aT as Review, aU as ReviewPage, aV as ReviewService, aW as SearchDoc, aX as SearchResult, aY as SearchService, aZ as SettingService, aZ as SettingsService, a_ as ShippingRate, a$ as SiteChrome, b0 as SiteFooter, b1 as SiteHeader, b2 as SocialLink, b3 as StateService, b4 as StoreClosed, b5 as StorePass, b6 as StorePassAnswer, b7 as StoreProfile, b8 as StoreService, b9 as StoreUnlock, ba as StorefrontCategory, bb as StorefrontMenu, bc as StorefrontOrder, bd as StorefrontProduct, be as ThemeSettings, bf as ThemeSettingsResult, bg as UploadService, bh as UserService, bi as Variant, bj as VariantImage, bk as VariantService, bl as VarniCustomDesignService, bm as VarniCustomProductService, bn as Vendor, bo as VendorService, bp as WarrantyService, bq as WhatsappConsent, br as WhatsappConsentOffer, bs as WhatsappService, bt as Wishlist, bu as WishlistItem, bv as WishlistService, bw as addressService, bx as authService, by as autocompleteService, bz as b2bService, bA as bannerService, bB as blogService, bC as cartService, bD as categoryService, bE as chatService, bF as checkoutService, bG as collectionService, bH as contactService, bI as countryService, bJ as couponService, bK as currencyExponent, bL as currencyService, bM as customizerService, bN as dealService, bO as demoRequestService, bP as emptyCart, bQ as emptyPage, bR as enquiryService, bS as faqService, bT as feedbackService, bU as fromEngineAddress, bV as fromIdentityAddress, bW as fromSearchDoc, bX as galleryService, bY as googleReviewService, bZ as homeService, b_ as initService, b$ as layoutService, c0 as mediaUrl, c1 as meilisearchService, c2 as menuService, c3 as minorToMajor, c4 as newsletterService, c5 as orderService, c6 as ownDomain, c7 as pageService, c8 as paymentMethodService, c9 as pluginService, ca as pluginsService, cb as popularSearchService, cc as popularityService, cd as priceOf, ce as productImages, cf as productService, cg as productVideos, ch as profileService, ci as qs, cj as reelsService, ck as regionService, cl as reviewService, cm as searchService, cn as setRequestHost, co as settingService, cp as settingsService, cq as stateService, cr as staticStore, cs as storeForHost, ct as storeService, cu as toAddOn, cv as toCart, cw as toCartLine, cx as toCartOffer, cy as toCategory, cz as toCheckoutQuote, cA as toCmsPage, cB as toCollection, cC as toEngineAddress, cD as toFreeShipping, cE as toIdentityAddress, cF as toMajor, cG as toMinor, cH as toOrder, cI as toPage, cJ as toProduct, cK as toRating, cL as toStorefrontFacets, cM as toUser, cN as toVariant, cO as toVendor, cP as uploadService, cQ as userService, cR as variantService, cS as varniCustomDesignService, cT as varniCustomProductService, cU as vendorService, cV as warrantyService, cW as whatsappService, cX as wishlistService } from './index-BdXhbm20.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The two ways a call through this connector fails.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AddOn, a as Address, b as AddressService, c as AppliedDiscount, d as Approval, e as AuthResponse, f as AuthService, g as AutocompleteService, B as B2bPlaced, h as B2bRole, i as B2bService, j as BannerService, k as BaseService, l as BlogService, C as Cart, m as CartLine, n as CartOffer, o as CartService, p as CatalogService, q as Category, r as CategoryService, s as ChatService, t as CheckoutOptions, u as
|
|
1
|
+
export { A as AddOn, a as Address, b as AddressService, c as AppliedDiscount, d as Approval, e as AuthResponse, f as AuthService, g as AutocompleteService, B as B2bPlaced, h as B2bRole, i as B2bService, j as BannerService, k as BaseService, l as BlogService, C as Cart, m as CartLine, n as CartOffer, o as CartService, p as CatalogService, q as Category, r as CategoryService, s as ChatService, t as CheckoutOptions, u as CheckoutQuote, v as CheckoutResult, w as CheckoutService, x as CmsPage, y as Collection, z as CollectionService, D as Company, E as CompanyOrder, F as ContactService, G as CountryService, H as CouponService, I as Credentials, J as Credit, K as CurrencyService, L as Customer, M as CustomizerDesign, N as CustomizerDocument, O as CustomizerEditor, P as CustomizerFile, Q as CustomizerLayer, R as CustomizerSavedDesign, S as CustomizerService, T as CustomizerSetup, U as CustomizerUpload, V as DealService, W as DemoRequestService, X as EngineRequest, Y as EnquiryService, Z as Envelope, _ as FacetValue, $ as Faq, a0 as FaqService, a1 as FeedbackService, a2 as FooterSettings, a3 as FreeShipping, a4 as Fulfillment, a5 as GalleryService, a6 as GooglePlace, a7 as GoogleReview, a8 as GoogleReviewService, a9 as GoogleReviews, aa as GoogleSurvey, ab as HeaderSettings, ac as HomeLayout, ad as HomeLayoutSection, ae as HomeService, af as IdentityAddress, ag as InitService, ah as Invitation, ai as LayoutCollection, aj as LayoutPage, ak as LayoutService, al as Lead, am as ListMeta, an as MeilisearchService, ao as Member, ap as Menu, aq as MenuItem, ar as MenuService, as as MenuSummary, at as Money, au as NewsletterService, av as Offer, aw as OpeningHours, ax as Order, ay as OrderLine, az as OrderService, aA as PageLayout, aB as PageService, aC as PaymentIntent, aD as PaymentMethodService, aE as Plugin, aF as PluginService, aF as PluginsService, aG as PopularSearchService, aH as PopularityService, aI as Postcode, aJ as Product, aK as ProductFacets, aL as ProductOption, aM as ProductService, aN as ProfileService, aO as Quote, aP as REDIRECT_GATEWAYS, aQ as ReelsService, aR as RegionService, aS as RejectedLine, aT as Review, aU as ReviewPage, aV as ReviewService, aW as SearchDoc, aX as SearchResult, aY as SearchService, aZ as SettingService, aZ as SettingsService, a_ as ShippingRate, a$ as SiteChrome, b0 as SiteFooter, b1 as SiteHeader, b2 as SocialLink, b3 as StateService, b4 as StoreClosed, b5 as StorePass, b6 as StorePassAnswer, b7 as StoreProfile, b8 as StoreService, b9 as StoreUnlock, ba as StorefrontCategory, bb as StorefrontMenu, bc as StorefrontOrder, bd as StorefrontProduct, be as ThemeSettings, bf as ThemeSettingsResult, bg as UploadService, bh as UserService, bi as Variant, bj as VariantImage, bk as VariantService, bl as VarniCustomDesignService, bm as VarniCustomProductService, bn as Vendor, bo as VendorService, bp as WarrantyService, bq as WhatsappConsent, br as WhatsappConsentOffer, bs as WhatsappService, bt as Wishlist, bu as WishlistItem, bv as WishlistService, bw as addressService, bx as authService, by as autocompleteService, bz as b2bService, bA as bannerService, bB as blogService, bC as cartService, bD as categoryService, bE as chatService, bF as checkoutService, bG as collectionService, bH as contactService, bI as countryService, bJ as couponService, bK as currencyExponent, bL as currencyService, bM as customizerService, bN as dealService, bO as demoRequestService, bP as emptyCart, bQ as emptyPage, bR as enquiryService, bS as faqService, bT as feedbackService, bU as fromEngineAddress, bV as fromIdentityAddress, bW as fromSearchDoc, bX as galleryService, bY as googleReviewService, bZ as homeService, b_ as initService, b$ as layoutService, c0 as mediaUrl, c1 as meilisearchService, c2 as menuService, c3 as minorToMajor, c4 as newsletterService, c5 as orderService, c6 as ownDomain, c7 as pageService, c8 as paymentMethodService, c9 as pluginService, ca as pluginsService, cb as popularSearchService, cc as popularityService, cd as priceOf, ce as productImages, cf as productService, cg as productVideos, ch as profileService, ci as qs, cj as reelsService, ck as regionService, cl as reviewService, cm as searchService, cn as setRequestHost, co as settingService, cp as settingsService, cq as stateService, cr as staticStore, cs as storeForHost, ct as storeService, cu as toAddOn, cv as toCart, cw as toCartLine, cx as toCartOffer, cy as toCategory, cz as toCheckoutQuote, cA as toCmsPage, cB as toCollection, cC as toEngineAddress, cD as toFreeShipping, cE as toIdentityAddress, cF as toMajor, cG as toMinor, cH as toOrder, cI as toPage, cJ as toProduct, cK as toRating, cL as toStorefrontFacets, cM as toUser, cN as toVariant, cO as toVendor, cP as uploadService, cQ as userService, cR as variantService, cS as varniCustomDesignService, cT as varniCustomProductService, cU as vendorService, cV as warrantyService, cW as whatsappService, cX as wishlistService } from './index-BdXhbm20.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The two ways a call through this connector fails.
|
package/dist/index.js
CHANGED
|
@@ -132,8 +132,17 @@ function remember(key, load, ttl = TTL_MS) {
|
|
|
132
132
|
});
|
|
133
133
|
return value;
|
|
134
134
|
}
|
|
135
|
+
var known = /* @__PURE__ */ new Map();
|
|
136
|
+
function keep(key, value) {
|
|
137
|
+
known.set(key, value);
|
|
138
|
+
return value;
|
|
139
|
+
}
|
|
140
|
+
function recall(key) {
|
|
141
|
+
return known.get(key);
|
|
142
|
+
}
|
|
135
143
|
function forgetAll() {
|
|
136
144
|
entries.clear();
|
|
145
|
+
known.clear();
|
|
137
146
|
}
|
|
138
147
|
|
|
139
148
|
// src/browser.ts
|
|
@@ -1118,7 +1127,22 @@ function toCartOffer(o, currency) {
|
|
|
1118
1127
|
applies: o.applies,
|
|
1119
1128
|
amount: o.amount ? toMajor(o.amount) : null,
|
|
1120
1129
|
remaining: o.remaining ? toMajor(o.remaining) : null,
|
|
1121
|
-
reason: o.reason ?? ""
|
|
1130
|
+
reason: o.reason ?? "",
|
|
1131
|
+
autoApply: !!o.auto_apply
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1134
|
+
function toCheckoutQuote(q) {
|
|
1135
|
+
const d = q.discount;
|
|
1136
|
+
return {
|
|
1137
|
+
subtotal: toMajor(q.subtotal),
|
|
1138
|
+
shippingCharges: toMajor(q.shipping),
|
|
1139
|
+
shippingMethod: q.shipping_method ?? null,
|
|
1140
|
+
discount: toMajor(d?.amount),
|
|
1141
|
+
coupon: d ? { code: d.code, title: d.title, autoApplied: d.auto_applied, freeShipping: !!d.free_shipping } : null,
|
|
1142
|
+
tax: toMajor(q.tax),
|
|
1143
|
+
taxIncluded: q.tax_inclusive,
|
|
1144
|
+
codCharges: toMajor(q.payment_fee),
|
|
1145
|
+
total: toMajor(q.total)
|
|
1122
1146
|
};
|
|
1123
1147
|
}
|
|
1124
1148
|
function toFreeShipping(f) {
|
|
@@ -2126,6 +2150,7 @@ var customizerService = new CustomizerService();
|
|
|
2126
2150
|
|
|
2127
2151
|
// src/services/checkout-service.ts
|
|
2128
2152
|
var CheckoutService = class extends BaseService {
|
|
2153
|
+
expected = /* @__PURE__ */ new Map();
|
|
2129
2154
|
/** Delivery options for the address on the cart: `{ data: [{ id, name, base_rate }] }`. */
|
|
2130
2155
|
async getShippingRates({ cartId } = {}) {
|
|
2131
2156
|
const id2 = cartId || storedCartId();
|
|
@@ -2297,6 +2322,64 @@ var CheckoutService = class extends BaseService {
|
|
|
2297
2322
|
);
|
|
2298
2323
|
return { methods: options.methods ?? [], currency: options.currency };
|
|
2299
2324
|
}
|
|
2325
|
+
/**
|
|
2326
|
+
* What checkout would charge for the cart now, by the storefront's method
|
|
2327
|
+
* code (`COD`, `RAZORPAY`, `PAYPAL`) or none yet (D185). Null until the
|
|
2328
|
+
* address step has stored an address, and null from an engine before D185.
|
|
2329
|
+
*
|
|
2330
|
+
* A refusal is checkout's own: the same GoCommerceError, with the same
|
|
2331
|
+
* message, that placing the order would raise now.
|
|
2332
|
+
*/
|
|
2333
|
+
async getQuote({ cartId, method = "" } = {}) {
|
|
2334
|
+
const id2 = cartId || storedCartId();
|
|
2335
|
+
if (!id2 || !cartExtras(id2).shippingAddress) return null;
|
|
2336
|
+
const { extras, email, address } = await this.storedCheckout(id2);
|
|
2337
|
+
const code = method.toLowerCase() === "paypal" ? await this.redirectGateway() : method.toLowerCase();
|
|
2338
|
+
try {
|
|
2339
|
+
const quote2 = await this.data("/api/checkout/quote", {
|
|
2340
|
+
query: {
|
|
2341
|
+
cart: id2,
|
|
2342
|
+
country: address.country,
|
|
2343
|
+
state: address.state,
|
|
2344
|
+
shipping_rate_id: extras.shippingRateId || void 0,
|
|
2345
|
+
method: code || void 0,
|
|
2346
|
+
email: email || void 0
|
|
2347
|
+
}
|
|
2348
|
+
});
|
|
2349
|
+
return toCheckoutQuote(quote2);
|
|
2350
|
+
} catch (err) {
|
|
2351
|
+
if (err instanceof GoCommerceError && (err.status === 405 || err.status === 404 && err.message.startsWith("no route for "))) {
|
|
2352
|
+
return null;
|
|
2353
|
+
}
|
|
2354
|
+
throw err;
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
/**
|
|
2358
|
+
* The total on screen as the shopper confirms, from getQuote, or null when nothing was quoted
|
|
2359
|
+
* (D185). Every order placed for the cart then carries it, and checkout refuses one whose own
|
|
2360
|
+
* total differs instead of charging it: `onChange` gets checkout's figures now and the sentence
|
|
2361
|
+
* the placing call fails with.
|
|
2362
|
+
*/
|
|
2363
|
+
expectTotal({
|
|
2364
|
+
cartId,
|
|
2365
|
+
total,
|
|
2366
|
+
onChange
|
|
2367
|
+
}) {
|
|
2368
|
+
const id2 = cartId || storedCartId();
|
|
2369
|
+
if (!id2) return;
|
|
2370
|
+
if (typeof total === "number") this.expected.set(id2, { total, onChange });
|
|
2371
|
+
else this.expected.delete(id2);
|
|
2372
|
+
}
|
|
2373
|
+
async storedCheckout(cartId) {
|
|
2374
|
+
const id2 = cartId || storedCartId();
|
|
2375
|
+
if (!id2) throw new GoCommerceError("Your bag is empty.", 400);
|
|
2376
|
+
const extras = cartExtras(id2);
|
|
2377
|
+
const ship = extras.shippingAddress;
|
|
2378
|
+
if (!ship) throw new GoCommerceError("Add a delivery address first.", 400);
|
|
2379
|
+
const cart = await this.data(`/api/carts/${encodeURIComponent(id2)}`);
|
|
2380
|
+
const email = cart.email || (ship.email ? String(ship.email) : "");
|
|
2381
|
+
return { id: id2, extras, email, address: toEngineAddress(ship), currency: cart.currency };
|
|
2382
|
+
}
|
|
2300
2383
|
async redirectGateway() {
|
|
2301
2384
|
const { methods } = await this.listMethods();
|
|
2302
2385
|
return methods.find((m) => REDIRECT_GATEWAYS.has(m.code))?.code;
|
|
@@ -2312,15 +2395,8 @@ var CheckoutService = class extends BaseService {
|
|
|
2312
2395
|
* the engine refuses a key replayed with a different body.
|
|
2313
2396
|
*/
|
|
2314
2397
|
async place(code, cartId, extra = {}) {
|
|
2315
|
-
const id2 =
|
|
2316
|
-
if (!id2) throw new GoCommerceError("Your bag is empty.", 400);
|
|
2317
|
-
const extras = cartExtras(id2);
|
|
2318
|
-
const ship = extras.shippingAddress;
|
|
2319
|
-
if (!ship) throw new GoCommerceError("Add a delivery address first.", 400);
|
|
2320
|
-
const cart = await this.data(`/api/carts/${encodeURIComponent(id2)}`);
|
|
2321
|
-
const email = cart.email || (ship.email ? String(ship.email) : "");
|
|
2398
|
+
const { id: id2, extras, email, address, currency } = await this.storedCheckout(cartId);
|
|
2322
2399
|
if (!email) throw new GoCommerceError("Add an email address so we can send your receipt.", 400);
|
|
2323
|
-
const address = toEngineAddress(ship);
|
|
2324
2400
|
const body = {
|
|
2325
2401
|
cart_id: id2,
|
|
2326
2402
|
email,
|
|
@@ -2343,10 +2419,23 @@ var CheckoutService = class extends BaseService {
|
|
|
2343
2419
|
...meta ? { meta_capi: meta } : {},
|
|
2344
2420
|
...attribution ? { attribution } : {}
|
|
2345
2421
|
};
|
|
2422
|
+
const expected = this.expected.get(id2);
|
|
2346
2423
|
const result = await this.data(`/api/checkout/${encodeURIComponent(code)}`, {
|
|
2347
2424
|
method: "POST",
|
|
2348
|
-
body:
|
|
2425
|
+
body: {
|
|
2426
|
+
...Object.keys(metadata).length ? { ...body, metadata } : body,
|
|
2427
|
+
...expected ? { quoted_total_minor: toMinor(expected.total, currency) } : {}
|
|
2428
|
+
},
|
|
2349
2429
|
headers: { "Idempotency-Key": key }
|
|
2430
|
+
}).catch((err) => {
|
|
2431
|
+
if (keyAlreadyUsed(err)) {
|
|
2432
|
+
throw new GoCommerceError("This order was already placed in another tab. Check that tab for its confirmation.", 400, err.code);
|
|
2433
|
+
}
|
|
2434
|
+
const now = movedTotal(err);
|
|
2435
|
+
if (!expected || !now) throw err;
|
|
2436
|
+
const message = `Your total changed to ${shopperAmount(now.total, currency)}. Check the new total and confirm again.`;
|
|
2437
|
+
expected.onChange?.(now, message);
|
|
2438
|
+
throw new GoCommerceError(message, 409, "total_changed", now);
|
|
2350
2439
|
});
|
|
2351
2440
|
if (result.order.access_token) {
|
|
2352
2441
|
rememberOrder({
|
|
@@ -2369,6 +2458,21 @@ var CheckoutService = class extends BaseService {
|
|
|
2369
2458
|
};
|
|
2370
2459
|
var REDIRECT_GATEWAYS = /* @__PURE__ */ new Set(["adyen", "paddle", "lemonsqueezy", "creem", "hyperswitch", "revenuecat"]);
|
|
2371
2460
|
var unsupported = (method, why) => new NotSupportedError("CheckoutService", method, why);
|
|
2461
|
+
function keyAlreadyUsed(err) {
|
|
2462
|
+
return err instanceof GoCommerceError && err.status === 400 && err.message.includes("Idempotency-Key was already used");
|
|
2463
|
+
}
|
|
2464
|
+
function movedTotal(err) {
|
|
2465
|
+
if (!(err instanceof GoCommerceError) || err.code !== "total_changed") return null;
|
|
2466
|
+
const now = err.details;
|
|
2467
|
+
return now?.total ? toCheckoutQuote(now) : null;
|
|
2468
|
+
}
|
|
2469
|
+
function shopperAmount(amount, currency) {
|
|
2470
|
+
return new Intl.NumberFormat(currency === "INR" ? "en-IN" : "en", {
|
|
2471
|
+
style: "currency",
|
|
2472
|
+
currency,
|
|
2473
|
+
...Number.isInteger(amount) ? { minimumFractionDigits: 0 } : {}
|
|
2474
|
+
}).format(amount);
|
|
2475
|
+
}
|
|
2372
2476
|
function newKey() {
|
|
2373
2477
|
const c = globalThis.crypto;
|
|
2374
2478
|
if (c?.randomUUID) return c.randomUUID();
|
|
@@ -2430,7 +2534,8 @@ var CouponService = class extends BaseService {
|
|
|
2430
2534
|
minAmount: o.minAmount,
|
|
2431
2535
|
description: o.applies ? o.title : o.remaining !== null ? `${o.title}. Add ${o.remaining} more to use this.` : o.reason || o.title,
|
|
2432
2536
|
applies: o.applies,
|
|
2433
|
-
remaining: o.remaining
|
|
2537
|
+
remaining: o.remaining,
|
|
2538
|
+
autoApply: o.autoApply
|
|
2434
2539
|
}));
|
|
2435
2540
|
return { data, count: data.length, pageSize: data.length, noOfPage: 1, page: 1 };
|
|
2436
2541
|
}
|
|
@@ -3183,15 +3288,18 @@ var StoreService = class extends BaseService {
|
|
|
3183
3288
|
async getStoreByIdOrDomain(_args = {}) {
|
|
3184
3289
|
const base = await readStaticStore();
|
|
3185
3290
|
const store = this.store;
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
if (isStoreMissing(err)) {
|
|
3291
|
+
const [plugins, live] = await Promise.all([
|
|
3292
|
+
this.facts.plugins().catch((err) => {
|
|
3293
|
+
if (store && isStoreMissing(err)) {
|
|
3189
3294
|
throw new GoCommerceError(`store not found: no store "${store}" on this engine`, 404, "store_not_found");
|
|
3190
3295
|
}
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3296
|
+
return void 0;
|
|
3297
|
+
}),
|
|
3298
|
+
this.live().catch(() => ({}))
|
|
3299
|
+
]);
|
|
3300
|
+
const known2 = `${this.creds.apiUrl ?? ""}|${store ?? ""}|closed`;
|
|
3301
|
+
const closed = plugins ? keep(known2, closedOf(plugins)) : recall(known2);
|
|
3302
|
+
return { ...base, ...live, closed, id: base.id || "gocommerce" };
|
|
3195
3303
|
}
|
|
3196
3304
|
async getStore(storeId) {
|
|
3197
3305
|
return this.getStoreByIdOrDomain({ storeId });
|
|
@@ -3226,6 +3334,46 @@ var StoreService = class extends BaseService {
|
|
|
3226
3334
|
}
|
|
3227
3335
|
return super.post(path, data);
|
|
3228
3336
|
}
|
|
3337
|
+
/**
|
|
3338
|
+
* A closed store's password (D170), traded for a pass. Never throws. The
|
|
3339
|
+
* engine allows 20 tries an hour per client, and sees this server as the
|
|
3340
|
+
* client unless `clientAddress`, the shopper's, travels as `X-Forwarded-For`.
|
|
3341
|
+
*/
|
|
3342
|
+
async unlockStore(password, { clientAddress } = {}) {
|
|
3343
|
+
const typed = password.trim();
|
|
3344
|
+
if (!typed) return { outcome: "wrong" };
|
|
3345
|
+
try {
|
|
3346
|
+
return { outcome: "unlocked", pass: await this.storePass({ password: typed }, clientAddress) };
|
|
3347
|
+
} catch (err) {
|
|
3348
|
+
return { outcome: err instanceof GoCommerceError && UNLOCK_REFUSED[err.status] || "unavailable" };
|
|
3349
|
+
}
|
|
3350
|
+
}
|
|
3351
|
+
/**
|
|
3352
|
+
* A pass checked without spending a try: the pass, or null when it is wrong,
|
|
3353
|
+
* expired, ended by a new password, or the store takes none now. Throws when
|
|
3354
|
+
* the engine cannot say.
|
|
3355
|
+
*/
|
|
3356
|
+
async checkStorePass(token) {
|
|
3357
|
+
if (!token) return null;
|
|
3358
|
+
try {
|
|
3359
|
+
return await this.storePass({ token });
|
|
3360
|
+
} catch (err) {
|
|
3361
|
+
if (err instanceof GoCommerceError && (err.status === 422 || err.status === 404)) return null;
|
|
3362
|
+
throw err;
|
|
3363
|
+
}
|
|
3364
|
+
}
|
|
3365
|
+
async storePass(body, clientAddress) {
|
|
3366
|
+
const answer = await this.data("/api/store/password", {
|
|
3367
|
+
method: "POST",
|
|
3368
|
+
body,
|
|
3369
|
+
headers: clientAddress && ONE_IP_ADDRESS.test(clientAddress) ? { "X-Forwarded-For": clientAddress } : void 0
|
|
3370
|
+
});
|
|
3371
|
+
const expiresAt = new Date(answer?.expires_at ?? NaN);
|
|
3372
|
+
if (!answer?.token || Number.isNaN(expiresAt.getTime())) {
|
|
3373
|
+
throw new GoCommerceError("The commerce engine answered a store pass without its token or expiry.", 502);
|
|
3374
|
+
}
|
|
3375
|
+
return { token: answer.token, expiresAt };
|
|
3376
|
+
}
|
|
3229
3377
|
async live() {
|
|
3230
3378
|
const [ready, plugins, menus, base, profile, ships] = await Promise.all([
|
|
3231
3379
|
this.facts.ready(),
|
|
@@ -3343,6 +3491,17 @@ var StoreService = class extends BaseService {
|
|
|
3343
3491
|
}
|
|
3344
3492
|
};
|
|
3345
3493
|
var storeService = new StoreService();
|
|
3494
|
+
var ONE_IP_ADDRESS = /^[\da-f.:]{2,45}$/i;
|
|
3495
|
+
var UNLOCK_REFUSED = {
|
|
3496
|
+
422: "wrong",
|
|
3497
|
+
429: "throttled",
|
|
3498
|
+
404: "open"
|
|
3499
|
+
};
|
|
3500
|
+
function closedOf(plugins) {
|
|
3501
|
+
const plugin = plugins?.get("store-close");
|
|
3502
|
+
if (!plugin) return void 0;
|
|
3503
|
+
return { message: String(plugin.settings?.message ?? ""), password: plugin.settings?.password === true };
|
|
3504
|
+
}
|
|
3346
3505
|
var AD_TAGS = [
|
|
3347
3506
|
["meta-pixel", "pixel_id", "facebookPixel"],
|
|
3348
3507
|
["microsoft-clarity", "project_id", "microsoftClarity"],
|
|
@@ -3371,10 +3530,10 @@ function googleTags(plugins) {
|
|
|
3371
3530
|
}
|
|
3372
3531
|
function deliverable(base, ships) {
|
|
3373
3532
|
if (ships.everywhere || !ships.countries.length) return {};
|
|
3374
|
-
const
|
|
3375
|
-
const countries = ships.countries.map((code) =>
|
|
3376
|
-
const
|
|
3377
|
-
return { countries, ...
|
|
3533
|
+
const known2 = new Map((base.countries ?? []).map((c) => [String(c.code).toUpperCase(), c]));
|
|
3534
|
+
const countries = ships.countries.map((code) => known2.get(code) ?? { code, name: regionName(code) });
|
|
3535
|
+
const keep2 = base.country && ships.countries.includes(String(base.country.code).toUpperCase());
|
|
3536
|
+
return { countries, ...keep2 ? {} : { country: countries[0] } };
|
|
3378
3537
|
}
|
|
3379
3538
|
function regionName(code) {
|
|
3380
3539
|
try {
|
|
@@ -3529,7 +3688,8 @@ function toSection(s) {
|
|
|
3529
3688
|
title: c.title,
|
|
3530
3689
|
slug: c.slug,
|
|
3531
3690
|
link: `/collections/${c.slug}`,
|
|
3532
|
-
image: mediaUrl(c.image) ?? null
|
|
3691
|
+
image: mediaUrl(c.image) ?? null,
|
|
3692
|
+
description: c.description || null
|
|
3533
3693
|
}));
|
|
3534
3694
|
}
|
|
3535
3695
|
return out;
|
|
@@ -4115,6 +4275,6 @@ function attemptKey(request) {
|
|
|
4115
4275
|
}
|
|
4116
4276
|
var b2bService = new B2bService();
|
|
4117
4277
|
|
|
4118
|
-
export { AddressService, AuthService, AutocompleteService, B2bService, BannerService, BaseService, BlogService, CartService, CatalogService, CategoryService, ChatService, CheckoutService, CollectionService, ContactService, CountryService, CouponService, CurrencyService, CustomizerService, DealService, DemoRequestService, EnquiryService, FaqService, FeedbackService, GalleryService, GoCommerceError, GoogleReviewService, HomeService, InitService, LayoutService, MeilisearchService, MenuService, NewsletterService, NotSupportedError, OrderService, PageService, PaymentMethodService, PluginService, PluginService as PluginsService, PopularSearchService, PopularityService, ProductService, ProfileService, REDIRECT_GATEWAYS, ReelsService, RegionService, ReviewService, SearchService, SettingService, SettingService as SettingsService, StateService, StoreService, UploadService, UserService, VariantService, VarniCustomDesignService, VarniCustomProductService, VendorService, WarrantyService, WhatsappService, WishlistService, addressService, authService, autocompleteService, b2bService, bannerService, blogService, cartService, categoryService, chatService, checkoutService, forgetAll as clearStoreCache, collectionService, connectorName, contactService, countryService, couponService, currencyExponent, currencyService, customizerService, dealService, demoRequestService, emptyCart, emptyPage, enquiryService, faqService, feedbackService, fromEngineAddress, fromIdentityAddress, fromSearchDoc, galleryService, googleReviewService, hasStaticStore, homeService, initService, layoutService, mediaUrl, meilisearchService, menuService, minorToMajor, newsletterService, orderService, ownDomain, pageService, paymentMethodService, pluginService, pluginsService, popularSearchService, popularityService, priceOf, productImages, productService, productVideos, profileService, qs, readStaticStore, reelsService, regionService, reviewService, searchService, serveRestLocally, setRequestHost, setStaticStore, settingService, settingsService, stateService, staticStore, storeForHost, storeService, toAddOn, toCart, toCartLine, toCartOffer, toCategory, toCmsPage, toCollection, toEngineAddress, toFreeShipping, toIdentityAddress, toMajor, toMinor, toOrder, toPage, toProduct, toRating, toStorefrontFacets, toUser, toVariant, toVendor, uploadService, userService, variantService, varniCustomDesignService, varniCustomProductService, vendorService, warrantyService, whatsappService, wishlistService };
|
|
4278
|
+
export { AddressService, AuthService, AutocompleteService, B2bService, BannerService, BaseService, BlogService, CartService, CatalogService, CategoryService, ChatService, CheckoutService, CollectionService, ContactService, CountryService, CouponService, CurrencyService, CustomizerService, DealService, DemoRequestService, EnquiryService, FaqService, FeedbackService, GalleryService, GoCommerceError, GoogleReviewService, HomeService, InitService, LayoutService, MeilisearchService, MenuService, NewsletterService, NotSupportedError, OrderService, PageService, PaymentMethodService, PluginService, PluginService as PluginsService, PopularSearchService, PopularityService, ProductService, ProfileService, REDIRECT_GATEWAYS, ReelsService, RegionService, ReviewService, SearchService, SettingService, SettingService as SettingsService, StateService, StoreService, UploadService, UserService, VariantService, VarniCustomDesignService, VarniCustomProductService, VendorService, WarrantyService, WhatsappService, WishlistService, addressService, authService, autocompleteService, b2bService, bannerService, blogService, cartService, categoryService, chatService, checkoutService, forgetAll as clearStoreCache, collectionService, connectorName, contactService, countryService, couponService, currencyExponent, currencyService, customizerService, dealService, demoRequestService, emptyCart, emptyPage, enquiryService, faqService, feedbackService, fromEngineAddress, fromIdentityAddress, fromSearchDoc, galleryService, googleReviewService, hasStaticStore, homeService, initService, layoutService, mediaUrl, meilisearchService, menuService, minorToMajor, newsletterService, orderService, ownDomain, pageService, paymentMethodService, pluginService, pluginsService, popularSearchService, popularityService, priceOf, productImages, productService, productVideos, profileService, qs, readStaticStore, reelsService, regionService, reviewService, searchService, serveRestLocally, setRequestHost, setStaticStore, settingService, settingsService, stateService, staticStore, storeForHost, storeService, toAddOn, toCart, toCartLine, toCartOffer, toCategory, toCheckoutQuote, toCmsPage, toCollection, toEngineAddress, toFreeShipping, toIdentityAddress, toMajor, toMinor, toOrder, toPage, toProduct, toRating, toStorefrontFacets, toUser, toVariant, toVendor, uploadService, userService, variantService, varniCustomDesignService, varniCustomProductService, vendorService, warrantyService, whatsappService, wishlistService };
|
|
4119
4279
|
//# sourceMappingURL=index.js.map
|
|
4120
4280
|
//# sourceMappingURL=index.js.map
|