@misiki/gocommerce-connector 0.4.6 → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as Address, a as AddressService, b as AppliedDiscount, c as Approval, d as AuthResponse, e as AuthService, f as AutocompleteService, B as B2bPlaced, g as B2bRole, h as B2bService, i as BannerService, j as BaseService, k as BlogService, C as Cart, l as CartLine, m as CartService, n as CatalogService, o as Category, p as CategoryService, q as ChatService, r as CheckoutOptions, s as CheckoutResult, t as CheckoutService, u as CmsPage, v as Collection, w as CollectionService, x as Company, y as CompanyOrder, z as ContactService, D as CountryService, E as CouponService, F as Credentials, G as Credit, H as CurrencyService, I as Customer, J as DealService, K as DemoRequestService, L as EngineRequest, M as EnquiryService, N as Envelope, O as Faq, P as FaqService, Q as FeedbackService, R as Fulfillment, S as GalleryService, T as HomeService, U as IdentityAddress, V as InitService, W as Invitation, X as Lead, Y as ListMeta, Z as MeilisearchService, _ as Member, $ as Menu, a0 as MenuItem, a1 as MenuService, a2 as MenuSummary, a3 as Money, a4 as NewsletterService, a5 as Offer, a6 as Order, a7 as OrderLine, a8 as OrderService, a9 as PageService, aa as PaymentIntent, ab as PaymentMethodService, ac as Plugin, ad as PluginService, ad as PluginsService, ae as PopularSearchService, af as PopularityService, ag as Product, ah as ProductOption, ai as ProductService, aj as ProfileService, ak as Quote, al as REDIRECT_GATEWAYS, am as ReelsService, an as RegionService, ao as RejectedLine, ap as Review, aq as ReviewPage, ar as ReviewService, as as SearchDoc, at as SearchResult, au as SearchService, av as SettingService, av as SettingsService, aw as ShippingRate, ax as StateService, ay as StoreProfile, az as StoreService, aA as StorefrontCategory, aB as StorefrontMenu, aC as StorefrontOrder, aD as StorefrontProduct, aE as UploadService, aF as UserService, aG as Variant, aH as VariantImage, aI as VariantService, aJ as VarniCustomDesignService, aK as VarniCustomProductService, aL as Vendor, aM as VendorService, aN as WarrantyService, aO as Wishlist, aP as WishlistItem, 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, b3 as currencyExponent, b4 as currencyService, b5 as dealService, b6 as demoRequestService, b7 as emptyCart, b8 as emptyPage, b9 as enquiryService, ba as faqService, bb as feedbackService, bc as fromEngineAddress, bd as fromIdentityAddress, be as fromSearchDoc, bf as galleryService, bg as homeService, bh as initService, bi as mediaUrl, bj as meilisearchService, bk as menuService, bl as minorToMajor, 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, bv as priceOf, bw as productImages, 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, bL as toCart, bM as toCartLine, bN as toCategory, bO as toCmsPage, bP as toCollection, bQ as toEngineAddress, bR as toIdentityAddress, bS as toMajor, bT as toMinor, bU as toOrder, bV as toPage, bW as toProduct, bX as toRating, bY as toUser, bZ as toVariant, b_ as toVendor, 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
+ export { A as Address, a as AddressService, b as AppliedDiscount, c as Approval, d as AuthResponse, e as AuthService, f as AutocompleteService, B as B2bPlaced, g as B2bRole, h as B2bService, i as BannerService, j as BaseService, k as BlogService, C as Cart, l as CartLine, m as CartService, n as CatalogService, o as Category, p as CategoryService, q as ChatService, r as CheckoutOptions, s as CheckoutResult, t as CheckoutService, u as CmsPage, v as Collection, w as CollectionService, x as Company, y as CompanyOrder, z as ContactService, D as CountryService, E as CouponService, F as Credentials, G as Credit, H as CurrencyService, I as Customer, J as DealService, K as DemoRequestService, L as EngineRequest, M as EnquiryService, N as Envelope, O as Faq, P as FaqService, Q as FeedbackService, R as Fulfillment, S as GalleryService, T as HomeService, U as IdentityAddress, V as InitService, W as Invitation, X as Lead, Y as ListMeta, Z as MeilisearchService, _ as Member, $ as Menu, a0 as MenuItem, a1 as MenuService, a2 as MenuSummary, a3 as Money, a4 as NewsletterService, a5 as Offer, a6 as Order, a7 as OrderLine, a8 as OrderService, a9 as PageService, aa as PaymentIntent, ab as PaymentMethodService, ac as Plugin, ad as PluginService, ad as PluginsService, ae as PopularSearchService, af as PopularityService, ag as Product, ah as ProductOption, ai as ProductService, aj as ProfileService, ak as Quote, al as REDIRECT_GATEWAYS, am as ReelsService, an as RegionService, ao as RejectedLine, ap as Review, aq as ReviewPage, ar as ReviewService, as as SearchDoc, at as SearchResult, au as SearchService, av as SettingService, av as SettingsService, aw as ShippingRate, ax as StateService, ay as StoreProfile, az as StoreService, aA as StorefrontCategory, aB as StorefrontMenu, aC as StorefrontOrder, aD as StorefrontProduct, aE as UploadService, aF as UserService, aG as Variant, aH as VariantImage, aI as VariantService, aJ as VarniCustomDesignService, aK as VarniCustomProductService, aL as Vendor, aM as VendorService, aN as WarrantyService, aO as Wishlist, aP as WishlistItem, 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, b3 as currencyExponent, b4 as currencyService, b5 as dealService, b6 as demoRequestService, b7 as emptyCart, b8 as emptyPage, b9 as enquiryService, ba as faqService, bb as feedbackService, bc as fromEngineAddress, bd as fromIdentityAddress, be as fromSearchDoc, bf as galleryService, bg as homeService, bh as initService, bi as mediaUrl, bj as meilisearchService, bk as menuService, bl as minorToMajor, 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, bv as priceOf, bw as productImages, 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, bL as toCart, bM as toCartLine, bN as toCategory, bO as toCmsPage, bP as toCollection, bQ as toEngineAddress, bR as toIdentityAddress, bS as toMajor, bT as toMinor, bU as toOrder, bV as toPage, bW as toProduct, bX as toRating, bY as toUser, bZ as toVariant, b_ as toVendor, 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-Bjx8kR8G.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 Address, a as AddressService, b as AppliedDiscount, c as Approval, d as AuthResponse, e as AuthService, f as AutocompleteService, B as B2bPlaced, g as B2bRole, h as B2bService, i as BannerService, j as BaseService, k as BlogService, C as Cart, l as CartLine, m as CartService, n as CatalogService, o as Category, p as CategoryService, q as ChatService, r as CheckoutOptions, s as CheckoutResult, t as CheckoutService, u as CmsPage, v as Collection, w as CollectionService, x as Company, y as CompanyOrder, z as ContactService, D as CountryService, E as CouponService, F as Credentials, G as Credit, H as CurrencyService, I as Customer, J as DealService, K as DemoRequestService, L as EngineRequest, M as EnquiryService, N as Envelope, O as Faq, P as FaqService, Q as FeedbackService, R as Fulfillment, S as GalleryService, T as HomeService, U as IdentityAddress, V as InitService, W as Invitation, X as Lead, Y as ListMeta, Z as MeilisearchService, _ as Member, $ as Menu, a0 as MenuItem, a1 as MenuService, a2 as MenuSummary, a3 as Money, a4 as NewsletterService, a5 as Offer, a6 as Order, a7 as OrderLine, a8 as OrderService, a9 as PageService, aa as PaymentIntent, ab as PaymentMethodService, ac as Plugin, ad as PluginService, ad as PluginsService, ae as PopularSearchService, af as PopularityService, ag as Product, ah as ProductOption, ai as ProductService, aj as ProfileService, ak as Quote, al as REDIRECT_GATEWAYS, am as ReelsService, an as RegionService, ao as RejectedLine, ap as Review, aq as ReviewPage, ar as ReviewService, as as SearchDoc, at as SearchResult, au as SearchService, av as SettingService, av as SettingsService, aw as ShippingRate, ax as StateService, ay as StoreProfile, az as StoreService, aA as StorefrontCategory, aB as StorefrontMenu, aC as StorefrontOrder, aD as StorefrontProduct, aE as UploadService, aF as UserService, aG as Variant, aH as VariantImage, aI as VariantService, aJ as VarniCustomDesignService, aK as VarniCustomProductService, aL as Vendor, aM as VendorService, aN as WarrantyService, aO as Wishlist, aP as WishlistItem, 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, b3 as currencyExponent, b4 as currencyService, b5 as dealService, b6 as demoRequestService, b7 as emptyCart, b8 as emptyPage, b9 as enquiryService, ba as faqService, bb as feedbackService, bc as fromEngineAddress, bd as fromIdentityAddress, be as fromSearchDoc, bf as galleryService, bg as homeService, bh as initService, bi as mediaUrl, bj as meilisearchService, bk as menuService, bl as minorToMajor, 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, bv as priceOf, bw as productImages, 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, bL as toCart, bM as toCartLine, bN as toCategory, bO as toCmsPage, bP as toCollection, bQ as toEngineAddress, bR as toIdentityAddress, bS as toMajor, bT as toMinor, bU as toOrder, bV as toPage, bW as toProduct, bX as toRating, bY as toUser, bZ as toVariant, b_ as toVendor, 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';
1
+ export { A as Address, a as AddressService, b as AppliedDiscount, c as Approval, d as AuthResponse, e as AuthService, f as AutocompleteService, B as B2bPlaced, g as B2bRole, h as B2bService, i as BannerService, j as BaseService, k as BlogService, C as Cart, l as CartLine, m as CartService, n as CatalogService, o as Category, p as CategoryService, q as ChatService, r as CheckoutOptions, s as CheckoutResult, t as CheckoutService, u as CmsPage, v as Collection, w as CollectionService, x as Company, y as CompanyOrder, z as ContactService, D as CountryService, E as CouponService, F as Credentials, G as Credit, H as CurrencyService, I as Customer, J as DealService, K as DemoRequestService, L as EngineRequest, M as EnquiryService, N as Envelope, O as Faq, P as FaqService, Q as FeedbackService, R as Fulfillment, S as GalleryService, T as HomeService, U as IdentityAddress, V as InitService, W as Invitation, X as Lead, Y as ListMeta, Z as MeilisearchService, _ as Member, $ as Menu, a0 as MenuItem, a1 as MenuService, a2 as MenuSummary, a3 as Money, a4 as NewsletterService, a5 as Offer, a6 as Order, a7 as OrderLine, a8 as OrderService, a9 as PageService, aa as PaymentIntent, ab as PaymentMethodService, ac as Plugin, ad as PluginService, ad as PluginsService, ae as PopularSearchService, af as PopularityService, ag as Product, ah as ProductOption, ai as ProductService, aj as ProfileService, ak as Quote, al as REDIRECT_GATEWAYS, am as ReelsService, an as RegionService, ao as RejectedLine, ap as Review, aq as ReviewPage, ar as ReviewService, as as SearchDoc, at as SearchResult, au as SearchService, av as SettingService, av as SettingsService, aw as ShippingRate, ax as StateService, ay as StoreProfile, az as StoreService, aA as StorefrontCategory, aB as StorefrontMenu, aC as StorefrontOrder, aD as StorefrontProduct, aE as UploadService, aF as UserService, aG as Variant, aH as VariantImage, aI as VariantService, aJ as VarniCustomDesignService, aK as VarniCustomProductService, aL as Vendor, aM as VendorService, aN as WarrantyService, aO as Wishlist, aP as WishlistItem, 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, b3 as currencyExponent, b4 as currencyService, b5 as dealService, b6 as demoRequestService, b7 as emptyCart, b8 as emptyPage, b9 as enquiryService, ba as faqService, bb as feedbackService, bc as fromEngineAddress, bd as fromIdentityAddress, be as fromSearchDoc, bf as galleryService, bg as homeService, bh as initService, bi as mediaUrl, bj as meilisearchService, bk as menuService, bl as minorToMajor, 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, bv as priceOf, bw as productImages, 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, bL as toCart, bM as toCartLine, bN as toCategory, bO as toCmsPage, bP as toCollection, bQ as toEngineAddress, bR as toIdentityAddress, bS as toMajor, bT as toMinor, bU as toOrder, bV as toPage, bW as toProduct, bX as toRating, bY as toUser, bZ as toVariant, b_ as toVendor, 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-Bjx8kR8G.js';
2
2
 
3
3
  /**
4
4
  * The two ways a call through this connector fails.
package/dist/index.js CHANGED
@@ -203,6 +203,7 @@ function toMe(c) {
203
203
  avatar: null,
204
204
  role: "USER",
205
205
  emailVerified: c.email_verified,
206
+ phoneVerified: !!c.phone_verified,
206
207
  storeId: null
207
208
  };
208
209
  }
@@ -984,6 +985,7 @@ function toUser(c) {
984
985
  email: c.email,
985
986
  emailVerified: c.email_verified,
986
987
  phone: c.phone || null,
988
+ phoneVerified: !!c.phone_verified,
987
989
  firstName: firstName || "",
988
990
  lastName: rest.join(" "),
989
991
  name: c.name,
@@ -2081,11 +2083,24 @@ var orderService = new OrderService();
2081
2083
 
2082
2084
  // src/services/user-service.ts
2083
2085
  var UserService = class extends BaseService {
2084
- /** Email and password. The answer is the user object the storefront keeps in its `me` cookie. */
2085
- async login({ email, password }) {
2086
+ /**
2087
+ * Email and password. The answer is the user object the storefront keeps in its `me` cookie.
2088
+ * With `phone` and `phoneToken` from `verifyOtp({ askIfNew: true })`, the phone is added to
2089
+ * the account as it signs in (D123).
2090
+ */
2091
+ async login({
2092
+ email,
2093
+ password,
2094
+ phone,
2095
+ phoneToken
2096
+ }) {
2086
2097
  const auth = await this.account("/x/identity/login", {
2087
2098
  method: "POST",
2088
- body: { email: String(email ?? "").trim(), password: String(password ?? "") }
2099
+ body: {
2100
+ email: String(email ?? "").trim(),
2101
+ password: String(password ?? ""),
2102
+ ...phoneToken ? { phone: String(phone ?? "").trim(), phone_token: phoneToken } : {}
2103
+ }
2089
2104
  });
2090
2105
  return this.signedIn(auth);
2091
2106
  }
@@ -2218,7 +2233,7 @@ var AuthService = class extends UserService {
2218
2233
  async loginMethod() {
2219
2234
  try {
2220
2235
  const method = (await this.facts.plugins()).get("identity")?.settings?.login_method;
2221
- return method === "phone_otp" ? "phone_otp" : "email_password";
2236
+ return method === "phone_otp" || method === "email_or_phone" ? method : "email_password";
2222
2237
  } catch {
2223
2238
  return "email_password";
2224
2239
  }
@@ -2257,11 +2272,29 @@ var AuthService = class extends UserService {
2257
2272
  });
2258
2273
  return { expiresInMinutes: res?.expires_in_minutes ?? 10 };
2259
2274
  }
2260
- /** Signs in the account on `phone` with the code it was sent, opening one the first time. */
2261
- async verifyOtp({ phone, otp }) {
2262
- const auth = await this.account("/x/identity/otp/verify", {
2275
+ /**
2276
+ * Signs in the account on `phone` with the code it was sent, opening one the first time.
2277
+ * With `askIfNew`, on a store that signs in either way, a phone with no account opens none:
2278
+ * the answer is `{ newPhone: true, phoneToken }`, and the storefront asks "Already have an
2279
+ * account?" — `login` with the token adds the phone to it, `openPhoneAccount` opens a new one (D123).
2280
+ */
2281
+ async verifyOtp({ phone, otp, askIfNew }) {
2282
+ const res = await this.account("/x/identity/otp/verify", {
2263
2283
  method: "POST",
2264
- body: { phone: String(phone ?? "").trim(), code: String(otp ?? "").trim() }
2284
+ body: {
2285
+ phone: String(phone ?? "").trim(),
2286
+ code: String(otp ?? "").trim(),
2287
+ ...askIfNew ? { ask_if_new: true } : {}
2288
+ }
2289
+ });
2290
+ if ("new_phone" in res && res.new_phone) return { newPhone: true, phoneToken: res.phone_token };
2291
+ return this.signedIn(res);
2292
+ }
2293
+ /** Opens a new account on a phone `verifyOtp({ askIfNew: true })` proved, and signs it in (D123). */
2294
+ async openPhoneAccount({ phone, phoneToken }) {
2295
+ const auth = await this.account("/x/identity/otp/new-account", {
2296
+ method: "POST",
2297
+ body: { phone: String(phone ?? "").trim(), phone_token: phoneToken }
2265
2298
  });
2266
2299
  return this.signedIn(auth);
2267
2300
  }
@@ -2276,6 +2309,25 @@ var ProfileService = class extends UserService {
2276
2309
  async save(profile) {
2277
2310
  return this.updateProfile(profile);
2278
2311
  }
2312
+ /** Texts a code to a phone the signed-in shopper wants to add (D118). */
2313
+ async requestPhoneLink({ phone }) {
2314
+ const res = await this.account("/x/identity/me/phone", {
2315
+ method: "POST",
2316
+ auth: true,
2317
+ body: { phone: String(phone ?? "").trim() }
2318
+ });
2319
+ return { expiresInMinutes: res?.expires_in_minutes ?? 10 };
2320
+ }
2321
+ /** Adds the phone with its code; from then on it signs in to this account too. */
2322
+ async verifyPhoneLink({ phone, otp }) {
2323
+ const c = await this.account("/x/identity/me/phone/verify", {
2324
+ method: "POST",
2325
+ auth: true,
2326
+ body: { phone: String(phone ?? "").trim(), code: String(otp ?? "").trim() }
2327
+ });
2328
+ updateMe(c);
2329
+ return toUser(c);
2330
+ }
2279
2331
  };
2280
2332
  var userService = new UserService();
2281
2333
  var authService = new AuthService();
@@ -2622,7 +2674,7 @@ var StoreService = class extends BaseService {
2622
2674
  // The one way this store signs customers in (D116), which the sign-in
2623
2675
  // form reads as PHONE or EMAIL. Without the accounts module the static
2624
2676
  // record says.
2625
- ...plugins.has("identity") ? { loginType: plugins.get("identity")?.settings?.login_method === "phone_otp" ? "PHONE" : "EMAIL" } : {}
2677
+ ...plugins.has("identity") ? { loginType: LOGIN_TYPES[String(plugins.get("identity")?.settings?.login_method)] ?? "EMAIL" } : {}
2626
2678
  };
2627
2679
  }
2628
2680
  };
@@ -2641,6 +2693,7 @@ function regionName(code) {
2641
2693
  return code;
2642
2694
  }
2643
2695
  }
2696
+ var LOGIN_TYPES = { phone_otp: "PHONE", email_or_phone: "BOTH", email_password: "EMAIL" };
2644
2697
 
2645
2698
  // src/services/page-service.ts
2646
2699
  var PageService = class extends BaseService {