@misiki/gocommerce-connector 0.4.4 → 0.4.6

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.
@@ -1 +1 @@
1
- export { a as AddressService, c as Approval, e as AuthService, f as AutocompleteService, B as B2bPlaced, g as B2bRole, h as B2bService, i as BannerService, j as BaseService, k as BlogService, m as CartService, n as CatalogService, p as CategoryService, q as ChatService, t as CheckoutService, w as CollectionService, x as Company, y as CompanyOrder, z as ContactService, D as CountryService, E as CouponService, G as Credit, H as CurrencyService, J as DealService, K as DemoRequestService, L as EngineRequest, M as EnquiryService, P as FaqService, Q as FeedbackService, S as GalleryService, T as HomeService, V as InitService, W as Invitation, X as Lead, Z as MeilisearchService, _ as Member, a1 as MenuService, a4 as NewsletterService, a8 as OrderService, a9 as PageService, ab as PaymentMethodService, ad as PluginService, ad as PluginsService, ae as PopularSearchService, af as PopularityService, ai as ProductService, aj as ProfileService, ak as Quote, al as REDIRECT_GATEWAYS, am as ReelsService, an as RegionService, ao as RejectedLine, ar as ReviewService, au as SearchService, av as SettingService, av as SettingsService, ax as StateService, az as StoreService, aB as StorefrontMenu, aE as UploadService, aF as UserService, aI as VariantService, aJ as VarniCustomDesignService, aK as VarniCustomProductService, aM as VendorService, aN as WarrantyService, aQ as WishlistService, aR as addressService, aS as authService, aT as autocompleteService, aU as b2bService, aV as bannerService, aW as blogService, aX as cartService, aY as categoryService, aZ as chatService, a_ as checkoutService, a$ as collectionService, b0 as contactService, b1 as countryService, b2 as couponService, b4 as currencyService, b5 as dealService, b6 as demoRequestService, b8 as emptyPage, b9 as enquiryService, ba as faqService, bb as feedbackService, bf as galleryService, bg as homeService, bh as initService, bi as mediaUrl, bj as meilisearchService, bk as menuService, bm as newsletterService, bn as orderService, bo as ownDomain, bp as pageService, bq as paymentMethodService, br as pluginService, bs as pluginsService, bt as popularSearchService, bu as popularityService, bx as productService, by as profileService, bz as qs, bA as reelsService, bB as regionService, bC as reviewService, bD as searchService, bE as setRequestHost, bF as settingService, bG as settingsService, bH as stateService, bI as staticStore, bJ as storeForHost, bK as storeService, bV as toPage, b$ as uploadService, c0 as userService, c1 as variantService, c2 as varniCustomDesignService, c3 as varniCustomProductService, c4 as vendorService, c5 as warrantyService, c6 as wishlistService } from '../index-BNYk4TS2.cjs';
1
+ export { a as AddressService, c as Approval, e as AuthService, f as AutocompleteService, B as B2bPlaced, g as B2bRole, h as B2bService, i as BannerService, j as BaseService, k as BlogService, m as CartService, n as CatalogService, p as CategoryService, q as ChatService, t as CheckoutService, w as CollectionService, x as Company, y as CompanyOrder, z as ContactService, D as CountryService, E as CouponService, G as Credit, H as CurrencyService, J as DealService, K as DemoRequestService, L as EngineRequest, M as EnquiryService, P as FaqService, Q as FeedbackService, S as GalleryService, T as HomeService, V as InitService, W as Invitation, X as Lead, Z as MeilisearchService, _ as Member, a1 as MenuService, a4 as NewsletterService, a8 as OrderService, a9 as PageService, ab as PaymentMethodService, ad as PluginService, ad as PluginsService, ae as PopularSearchService, af as PopularityService, ai as ProductService, aj as ProfileService, ak as Quote, al as REDIRECT_GATEWAYS, am as ReelsService, an as RegionService, ao as RejectedLine, ar as ReviewService, au as SearchService, av as SettingService, av as SettingsService, ax as StateService, az as StoreService, aB as StorefrontMenu, aE as UploadService, aF as UserService, aI as VariantService, aJ as VarniCustomDesignService, aK as VarniCustomProductService, aM as VendorService, aN as WarrantyService, aQ as WishlistService, aR as addressService, aS as authService, aT as autocompleteService, aU as b2bService, aV as bannerService, aW as blogService, aX as cartService, aY as categoryService, aZ as chatService, a_ as checkoutService, a$ as collectionService, b0 as contactService, b1 as countryService, b2 as couponService, b4 as currencyService, b5 as dealService, b6 as demoRequestService, b8 as emptyPage, b9 as enquiryService, ba as faqService, bb as feedbackService, bf as galleryService, bg as homeService, bh as initService, bi as mediaUrl, bj as meilisearchService, bk as menuService, bm as newsletterService, bn as orderService, bo as ownDomain, bp as pageService, bq as paymentMethodService, br as pluginService, bs as pluginsService, bt as popularSearchService, bu as popularityService, bx as productService, by as profileService, bz as qs, bA as reelsService, bB as regionService, bC as reviewService, bD as searchService, bE as setRequestHost, bF as settingService, bG as settingsService, bH as stateService, bI as staticStore, bJ as storeForHost, bK as storeService, bV as toPage, b$ as uploadService, c0 as userService, c1 as variantService, c2 as varniCustomDesignService, c3 as varniCustomProductService, c4 as vendorService, c5 as warrantyService, c6 as wishlistService } from '../index-B0Gf_Bvg.cjs';
@@ -1 +1 @@
1
- export { a as AddressService, c as Approval, e as AuthService, f as AutocompleteService, B as B2bPlaced, g as B2bRole, h as B2bService, i as BannerService, j as BaseService, k as BlogService, m as CartService, n as CatalogService, p as CategoryService, q as ChatService, t as CheckoutService, w as CollectionService, x as Company, y as CompanyOrder, z as ContactService, D as CountryService, E as CouponService, G as Credit, H as CurrencyService, J as DealService, K as DemoRequestService, L as EngineRequest, M as EnquiryService, P as FaqService, Q as FeedbackService, S as GalleryService, T as HomeService, V as InitService, W as Invitation, X as Lead, Z as MeilisearchService, _ as Member, a1 as MenuService, a4 as NewsletterService, a8 as OrderService, a9 as PageService, ab as PaymentMethodService, ad as PluginService, ad as PluginsService, ae as PopularSearchService, af as PopularityService, ai as ProductService, aj as ProfileService, ak as Quote, al as REDIRECT_GATEWAYS, am as ReelsService, an as RegionService, ao as RejectedLine, ar as ReviewService, au as SearchService, av as SettingService, av as SettingsService, ax as StateService, az as StoreService, aB as StorefrontMenu, aE as UploadService, aF as UserService, aI as VariantService, aJ as VarniCustomDesignService, aK as VarniCustomProductService, aM as VendorService, aN as WarrantyService, aQ as WishlistService, aR as addressService, aS as authService, aT as autocompleteService, aU as b2bService, aV as bannerService, aW as blogService, aX as cartService, aY as categoryService, aZ as chatService, a_ as checkoutService, a$ as collectionService, b0 as contactService, b1 as countryService, b2 as couponService, b4 as currencyService, b5 as dealService, b6 as demoRequestService, b8 as emptyPage, b9 as enquiryService, ba as faqService, bb as feedbackService, bf as galleryService, bg as homeService, bh as initService, bi as mediaUrl, bj as meilisearchService, bk as menuService, bm as newsletterService, bn as orderService, bo as ownDomain, bp as pageService, bq as paymentMethodService, br as pluginService, bs as pluginsService, bt as popularSearchService, bu as popularityService, bx as productService, by as profileService, bz as qs, bA as reelsService, bB as regionService, bC as reviewService, bD as searchService, bE as setRequestHost, bF as settingService, bG as settingsService, bH as stateService, bI as staticStore, bJ as storeForHost, bK as storeService, bV as toPage, b$ as uploadService, c0 as userService, c1 as variantService, c2 as varniCustomDesignService, c3 as varniCustomProductService, c4 as vendorService, c5 as warrantyService, c6 as wishlistService } from '../index-BNYk4TS2.js';
1
+ export { a as AddressService, c as Approval, e as AuthService, f as AutocompleteService, B as B2bPlaced, g as B2bRole, h as B2bService, i as BannerService, j as BaseService, k as BlogService, m as CartService, n as CatalogService, p as CategoryService, q as ChatService, t as CheckoutService, w as CollectionService, x as Company, y as CompanyOrder, z as ContactService, D as CountryService, E as CouponService, G as Credit, H as CurrencyService, J as DealService, K as DemoRequestService, L as EngineRequest, M as EnquiryService, P as FaqService, Q as FeedbackService, S as GalleryService, T as HomeService, V as InitService, W as Invitation, X as Lead, Z as MeilisearchService, _ as Member, a1 as MenuService, a4 as NewsletterService, a8 as OrderService, a9 as PageService, ab as PaymentMethodService, ad as PluginService, ad as PluginsService, ae as PopularSearchService, af as PopularityService, ai as ProductService, aj as ProfileService, ak as Quote, al as REDIRECT_GATEWAYS, am as ReelsService, an as RegionService, ao as RejectedLine, ar as ReviewService, au as SearchService, av as SettingService, av as SettingsService, ax as StateService, az as StoreService, aB as StorefrontMenu, aE as UploadService, aF as UserService, aI as VariantService, aJ as VarniCustomDesignService, aK as VarniCustomProductService, aM as VendorService, aN as WarrantyService, aQ as WishlistService, aR as addressService, aS as authService, aT as autocompleteService, aU as b2bService, aV as bannerService, aW as blogService, aX as cartService, aY as categoryService, aZ as chatService, a_ as checkoutService, a$ as collectionService, b0 as contactService, b1 as countryService, b2 as couponService, b4 as currencyService, b5 as dealService, b6 as demoRequestService, b8 as emptyPage, b9 as enquiryService, ba as faqService, bb as feedbackService, bf as galleryService, bg as homeService, bh as initService, bi as mediaUrl, bj as meilisearchService, bk as menuService, bm as newsletterService, bn as orderService, bo as ownDomain, bp as pageService, bq as paymentMethodService, br as pluginService, bs as pluginsService, bt as popularSearchService, bu as popularityService, bx as productService, by as profileService, bz as qs, bA as reelsService, bB as regionService, bC as reviewService, bD as searchService, bE as setRequestHost, bF as settingService, bG as settingsService, bH as stateService, bI as staticStore, bJ as storeForHost, bK as storeService, bV as toPage, b$ as uploadService, c0 as userService, c1 as variantService, c2 as varniCustomDesignService, c3 as varniCustomProductService, c4 as vendorService, c5 as warrantyService, c6 as wishlistService } from '../index-B0Gf_Bvg.js';
@@ -1011,6 +1011,13 @@ var StoreFacts = class extends BaseService {
1011
1011
  profile() {
1012
1012
  return remember(this.key("profile"), () => this.data("/api/store"));
1013
1013
  }
1014
+ /** Where the store delivers (D117): its priced zones' countries, or everywhere. */
1015
+ shipsTo() {
1016
+ return remember(this.key("ships-to"), async () => {
1017
+ const r = await this.data("/api/checkout/countries");
1018
+ return { everywhere: r?.everywhere ?? true, countries: r?.countries ?? [] };
1019
+ });
1020
+ }
1014
1021
  checkoutOptions() {
1015
1022
  return remember(this.key("checkout"), () => this.data("/api/checkout"));
1016
1023
  }
@@ -2184,6 +2191,19 @@ var UserService = class extends BaseService {
2184
2191
  }
2185
2192
  };
2186
2193
  var AuthService = class extends UserService {
2194
+ facts = new StoreFacts(this._fetch);
2195
+ /**
2196
+ * How this store signs customers in: `email_password` or `phone_otp`.
2197
+ * A store whose accounts module says nothing signs in by email.
2198
+ */
2199
+ async loginMethod() {
2200
+ try {
2201
+ const method = (await this.facts.plugins()).get("identity")?.settings?.login_method;
2202
+ return method === "phone_otp" ? "phone_otp" : "email_password";
2203
+ } catch {
2204
+ return "email_password";
2205
+ }
2206
+ }
2187
2207
  async forgotPassword({ email }) {
2188
2208
  return this.account("/x/identity/password-reset", {
2189
2209
  method: "POST",
@@ -2210,11 +2230,21 @@ var AuthService = class extends UserService {
2210
2230
  return { errorCode: err.code ?? "invalid_token", message: err.message };
2211
2231
  }
2212
2232
  }
2213
- async getOtp() {
2214
- throw new NotSupportedError("AuthService", "getOtp", "sign in with an email and password");
2233
+ /** Texts a 4-digit sign-in code to `phone`, which needs its country code. */
2234
+ async getOtp({ phone }) {
2235
+ const res = await this.account("/x/identity/otp", {
2236
+ method: "POST",
2237
+ body: { phone: String(phone ?? "").trim() }
2238
+ });
2239
+ return { expiresInMinutes: res?.expires_in_minutes ?? 10 };
2215
2240
  }
2216
- async verifyOtp() {
2217
- throw new NotSupportedError("AuthService", "verifyOtp", "sign in with an email and password");
2241
+ /** Signs in the account on `phone` with the code it was sent, opening one the first time. */
2242
+ async verifyOtp({ phone, otp }) {
2243
+ const auth = await this.account("/x/identity/otp/verify", {
2244
+ method: "POST",
2245
+ body: { phone: String(phone ?? "").trim(), code: String(otp ?? "").trim() }
2246
+ });
2247
+ return this.signedIn(auth);
2218
2248
  }
2219
2249
  async joinAsAdmin() {
2220
2250
  throw new NotSupportedError("AuthService", "joinAsAdmin", "operators are invited from the admin panel");
@@ -2535,12 +2565,14 @@ var StoreService = class extends BaseService {
2535
2565
  return super.post(path, data);
2536
2566
  }
2537
2567
  async live() {
2538
- const [ready, plugins, menus, base, profile] = await Promise.all([
2568
+ const [ready, plugins, menus, base, profile, ships] = await Promise.all([
2539
2569
  this.facts.ready(),
2540
2570
  this.facts.plugins().catch(() => /* @__PURE__ */ new Map()),
2541
2571
  new MenuService(this._fetch).engineMenus(),
2542
2572
  readStaticStore(),
2543
- this.facts.profile().catch(() => null)
2573
+ this.facts.profile().catch(() => null),
2574
+ // An engine without the route rules nothing out.
2575
+ this.facts.shipsTo().catch(() => ({ everywhere: true, countries: [] }))
2544
2576
  ]);
2545
2577
  const code = ready.currency;
2546
2578
  const sameCurrency = (base.currency?.code ?? base.currencyCode) === code;
@@ -2569,11 +2601,30 @@ var StoreService = class extends BaseService {
2569
2601
  ...flag(plugins.has("product-reviews"))
2570
2602
  }
2571
2603
  },
2572
- ...menus?.length ? { menu: menus } : {}
2604
+ ...menus?.length ? { menu: menus } : {},
2605
+ ...deliverable(base, ships),
2606
+ // The one way this store signs customers in (D116), which the sign-in
2607
+ // form reads as PHONE or EMAIL. Without the accounts module the static
2608
+ // record says.
2609
+ ...plugins.has("identity") ? { loginType: plugins.get("identity")?.settings?.login_method === "phone_otp" ? "PHONE" : "EMAIL" } : {}
2573
2610
  };
2574
2611
  }
2575
2612
  };
2576
2613
  var storeService = new StoreService();
2614
+ function deliverable(base, ships) {
2615
+ if (ships.everywhere || !ships.countries.length) return {};
2616
+ const known = new Map((base.countries ?? []).map((c) => [String(c.code).toUpperCase(), c]));
2617
+ const countries = ships.countries.map((code) => known.get(code) ?? { code, name: regionName(code) });
2618
+ const keep = base.country && ships.countries.includes(String(base.country.code).toUpperCase());
2619
+ return { countries, ...keep ? {} : { country: countries[0] } };
2620
+ }
2621
+ function regionName(code) {
2622
+ try {
2623
+ return new Intl.DisplayNames(["en"], { type: "region" }).of(code) ?? code;
2624
+ } catch {
2625
+ return code;
2626
+ }
2627
+ }
2577
2628
 
2578
2629
  // src/services/page-service.ts
2579
2630
  var PageService = class extends BaseService {