@zenky/storefront-api 0.0.19 → 0.0.20

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.
@@ -81,7 +81,7 @@ class h extends Error {
81
81
  this.err = s;
82
82
  }
83
83
  }
84
- class R {
84
+ class m {
85
85
  static async build(e) {
86
86
  const r = await e.json();
87
87
  switch (e.status) {
@@ -131,10 +131,10 @@ class c {
131
131
  const l = await this.fetchFunction.call(null, `${this.baseUrl}${r}`, u);
132
132
  if (l.ok)
133
133
  return l.status === 204 ? !0 : l.json();
134
- throw await R.build(l);
134
+ throw await m.build(l);
135
135
  }
136
136
  }
137
- class m extends o {
137
+ class R extends o {
138
138
  async getStore(e) {
139
139
  const r = this.getUrl(`/store/${e}`);
140
140
  return this.getResponse(await this.client.request("GET", r));
@@ -188,7 +188,7 @@ class f extends o {
188
188
  return this.getResponse(await this.client.request("POST", a, i));
189
189
  }
190
190
  }
191
- class v extends o {
191
+ class S extends o {
192
192
  getOrderUrl(e, r, s, i) {
193
193
  const a = typeof r == "string" ? r : r.id, u = typeof r == "string" ? void 0 : r.token;
194
194
  return this.getStoreUrl(e, `/orders/${a}${s}${u ? "?token=" + u : ""}`, i);
@@ -252,7 +252,7 @@ class v extends o {
252
252
  );
253
253
  }
254
254
  async getOrderBonusesPreview(e, r, s) {
255
- const i = this.getOrderUrl(e, r, "/checkout/bonuses/preview", { amount: s });
255
+ const i = this.getOrderUrl(e, r, "/checkout/payments/bonuses", { amount: s });
256
256
  return this.getResponse(
257
257
  await this.client.request("GET", i, void 0, this.getApiToken(r))
258
258
  );
@@ -302,7 +302,7 @@ class v extends o {
302
302
  );
303
303
  }
304
304
  }
305
- class S extends o {
305
+ class v extends o {
306
306
  async getAddressSuggestions(e, r) {
307
307
  const s = this.getStoreUrl(e, "/suggestions/address");
308
308
  return this.getResponse(await this.client.request("POST", s, r));
@@ -407,7 +407,7 @@ class te {
407
407
  n(this, "articles");
408
408
  n(this, "feedback");
409
409
  const s = c.build(e, r);
410
- this.store = new m(s), this.auth = new P(s), this.customer = new y(s), this.categories = new k(s), this.products = new f(s), this.addresses = new S(s), this.orders = new v(s), this.collections = new U(s), this.offers = new q(s), this.articles = new w(s), this.feedback = new O(s), this.client = s;
410
+ this.store = new R(s), this.auth = new P(s), this.customer = new y(s), this.categories = new k(s), this.products = new f(s), this.addresses = new v(s), this.orders = new S(s), this.collections = new U(s), this.offers = new q(s), this.articles = new w(s), this.feedback = new O(s), this.client = s;
411
411
  }
412
412
  setApiToken(e) {
413
413
  return this.client.setToken(e), this;
@@ -441,17 +441,17 @@ export {
441
441
  D as OrderOptionKind,
442
442
  V as OrderPaymentTransactionStatus,
443
443
  z as OrderPaymentTransactionType,
444
- v as OrdersResource,
444
+ S as OrdersResource,
445
445
  I as PaymentMethod,
446
446
  T as PaymentSystemType,
447
447
  J as ProductContextType,
448
448
  f as ProductsResource,
449
449
  B as RecaptchaAction,
450
- m as StoreResource,
450
+ R as StoreResource,
451
451
  Y as TernaryFilter,
452
452
  M as UnitType,
453
453
  Z as VariantOptionType,
454
454
  h as ZenkyError,
455
- R as ZenkyErrorBuilder,
455
+ m as ZenkyErrorBuilder,
456
456
  te as ZenkyStorefront
457
457
  };
@@ -1 +1 @@
1
- (function(n,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(n=typeof globalThis<"u"?globalThis:n||self,c(n.zenkyStorefrontApi={}))})(this,function(n){"use strict";var ee=Object.defineProperty;var te=(n,c,o)=>c in n?ee(n,c,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[c]=o;var a=(n,c,o)=>(te(n,typeof c!="symbol"?c+"":c,o),o);var c=(e=>(e.DADATA="dadata",e))(c||{});class o{constructor(t){this.client=t}getStoreUrl(t,r,s={}){return this.getUrl(`/store/${t}${r}`,s)}getUrl(t,r={}){if(!Object.keys(r).length)return t;const s=[];Object.keys(r).forEach(u=>{s.push(`${u}=${r[u]}`)});const i=t.includes("?")?"&":"?";return`${t}${i}${s.join("&")}`}getPaginatedResponse(t){if(!t||!Array.isArray(t.data)||!t.meta||!t.meta.pagination)throw new Error("getPaginatedResponse(): Invalid response.");const r=t.data,s=t.meta.pagination;return{items:r,pagination:s}}getResponse(t){if(!t||!t.data)throw new Error("getResponse(): Invalid response.");return t.data}}class w extends o{async getArticleCategories(t){const r=this.getStoreUrl(t,"/articles/categories");return this.getPaginatedResponse(await this.client.request("GET",r))}async getArticleCategory(t,r){const s=this.getStoreUrl(t,`/articles/categories/${r}`);return this.getResponse(await this.client.request("GET",s))}async getArticles(t,r){const s=this.getStoreUrl(t,"/articles",r);return this.getPaginatedResponse(await this.client.request("GET",s))}async getArticle(t,r,s){const i=this.getStoreUrl(t,`/articles/${r}`,s);return this.getResponse(await this.client.request("GET",i))}}class p extends o{async getCategories(t,r){const s=this.getStoreUrl(t,"/categories",r);return this.getPaginatedResponse(await this.client.request("GET",s))}async getCategoriesTree(t,r){const s=this.getStoreUrl(t,"/categories/tree",r);return this.getResponse(await this.client.request("GET",s))}async getCategory(t,r,s){const i=this.getStoreUrl(t,`/categories/${r}`,s);return this.getResponse(await this.client.request("GET",i))}async getFeaturesGroups(t,r){const s=this.getStoreUrl(t,`/categories/${r}/features/groups`);return this.getResponse(await this.client.request("GET",s))}async getFeatures(t,r){const s=this.getStoreUrl(t,`/categories/${r}/features`);return this.getResponse(await this.client.request("GET",s))}}class g extends Error{constructor(r,s){super(r);a(this,"err");this.err=s}}class k{static async build(t){const r=await t.json();switch(t.status){case 401:return new g((r==null?void 0:r.message)??"Unauthenticated.",null);default:return new g(r==null?void 0:r.message,(r==null?void 0:r.error)||null)}}}class d{constructor(t,r,s,i,u,l){a(this,"baseUrl");a(this,"token");a(this,"client");a(this,"timezone");a(this,"fetchFunction");a(this,"fetchOptions");this.baseUrl=t,this.token=r,this.client=s,this.timezone=i,this.fetchFunction=typeof u=="function"?u:fetch,this.fetchOptions=typeof l<"u"?l:{}}static build(t,r){return new d((t==null?void 0:t.baseUrl)||"https://storefront.zenky.io/v1",(t==null?void 0:t.token)||null,(t==null?void 0:t.client)||"web",(t==null?void 0:t.timezone)||"UTC",r,t==null?void 0:t.fetchOptions)}setToken(t){return this.token=t,this}async request(t,r,s,i){const u={Accept:"application/json","X-Zenky-Client":this.client,"X-Timezone":this.timezone};i?u.Authorization=`Bearer ${i}`:this.token&&(u.Authorization=`Bearer ${this.token}`);const l={method:t,mode:"cors",...this.fetchOptions};s&&(u["Content-Type"]="application/json",l.body=JSON.stringify(s)),l.headers=u;const h=await this.fetchFunction.call(null,`${this.baseUrl}${r}`,l);if(h.ok)return h.status===204?!0:h.json();throw await k.build(h)}}class R extends o{async getStore(t){const r=this.getUrl(`/store/${t}`);return this.getResponse(await this.client.request("GET",r))}async getStoreByBundleId(t){const r=this.getUrl(`/store/by-bundle/${t}`);return this.getResponse(await this.client.request("GET",r))}}class y extends o{async getCollections(t,r){const s=this.getStoreUrl(t,"/collections",r);return this.getPaginatedResponse(await this.client.request("GET",s))}async getCollection(t,r){const s=this.getStoreUrl(t,`/collections/${r}`);return this.getResponse(await this.client.request("GET",s))}}class m extends o{async getOffers(t,r){const s=this.getStoreUrl(t,"/offers",r);return this.getPaginatedResponse(await this.client.request("GET",s))}async getOffer(t,r,s){const i=this.getStoreUrl(t,`/offers/${r}`,s);return this.getResponse(await this.client.request("GET",i))}}class f extends o{async createFeedback(t,r){const s=this.getStoreUrl(t,"/feedback",r);return this.getResponse(await this.client.request("POST",s))}async createCallback(t,r){const s=this.getStoreUrl(t,"/callback",r);return await this.client.request("POST",s),!0}}class O extends o{async getProducts(t,r){const s=this.getStoreUrl(t,"/products",r);return this.getPaginatedResponse(await this.client.request("GET",s))}async getProduct(t,r,s){const i=this.getStoreUrl(t,`/products/${r}`,s);return this.getResponse(await this.client.request("GET",i))}async getProductVariantPrice(t,r,s,i){const u=this.getStoreUrl(t,`/products/${r}/variants/${s}/price`);return this.getResponse(await this.client.request("POST",u,i))}}class U extends o{getOrderUrl(t,r,s,i){const u=typeof r=="string"?r:r.id,l=typeof r=="string"?void 0:r.token;return this.getStoreUrl(t,`/orders/${u}${s}${l?"?token="+l:""}`,i)}getApiToken(t){if(!(typeof t=="string"||typeof t.api_token>"u"))return t.api_token}async getOrders(t,r,s){const i=this.getStoreUrl(t,"/orders",r);return this.getPaginatedResponse(await this.client.request("GET",i,void 0,s))}async createOrder(t,r,s){const i=this.getStoreUrl(t,"/orders");return this.getResponse(await this.client.request("POST",i,r,s))}async getOrder(t,r,s){const i=this.getOrderUrl(t,r,"",s);return this.getResponse(await this.client.request("GET",i,void 0,this.getApiToken(r)))}async getOrderSettings(t,r){const s=this.getOrderUrl(t,r,"/settings");return this.getResponse(await this.client.request("GET",s,void 0,this.getApiToken(r)))}async addProductVariantToOrder(t,r,s){const i=this.getOrderUrl(t,r,"/products");return this.getResponse(await this.client.request("POST",i,s,this.getApiToken(r)))}async removeProductVariantFromOrder(t,r,s){const i=this.getOrderUrl(t,r,"/products");return this.getResponse(await this.client.request("POST",i,s,this.getApiToken(r)))}async checkProducts(t,r){const s=this.getOrderUrl(t,r,"/products/check");return this.getResponse(await this.client.request("POST",s,void 0,this.getApiToken(r)))}async setOrderCustomer(t,r,s){const i=this.getOrderUrl(t,r,"/checkout/customer");return await this.client.request("POST",i,s,this.getApiToken(r)),!0}async setOrderDeliveryMethod(t,r,s){const i=this.getOrderUrl(t,r,"/checkout/delivery");return this.getResponse(await this.client.request("POST",i,s,this.getApiToken(r)))}async setOrderPayments(t,r,s){const i=this.getOrderUrl(t,r,"/checkout/payments");return this.getResponse(await this.client.request("POST",i,s,this.getApiToken(r)))}async getOrderBonusesPreview(t,r,s){const i=this.getOrderUrl(t,r,"/checkout/bonuses/preview",{amount:s});return this.getResponse(await this.client.request("GET",i,void 0,this.getApiToken(r)))}async getOrderTotal(t,r){const s=this.getOrderUrl(t,r,"/checkout/total");return this.getResponse(await this.client.request("GET",s,void 0,this.getApiToken(r)))}async checkoutOrder(t,r,s){const i=this.getOrderUrl(t,r,"/checkout");return this.getResponse(await this.client.request("POST",i,s,this.getApiToken(r)))}async confirmOrder(t,r,s){const i=this.getOrderUrl(t,r,"/confirm");return await this.client.request("POST",i,s,this.getApiToken(r)),!0}async resendOrderConfirmationCode(t,r){const s=this.getOrderUrl(t,r,"/confirm/resend");return await this.client.request("POST",s,void 0,this.getApiToken(r)),!0}async getOrderBonusesTransactions(t,r,s){const i=this.getOrderUrl(t,r,"/loyalty/transactions",s);return this.getPaginatedResponse(await this.client.request("GET",i,void 0,this.getApiToken(r)))}async getOrderCashbackTransaction(t,r){const s=this.getOrderUrl(t,r,"/loyalty/transactions/cashback");return this.getResponse(await this.client.request("GET",s,void 0,this.getApiToken(r)))}async dispatchPromotionsChecker(t,r){const s=this.getOrderUrl(t,r,"/loyalty/promotions/check");return this.getResponse(await this.client.request("POST",s,void 0,this.getApiToken(r))).dispatched}async getOrderPromotionRewards(t,r){const s=this.getOrderUrl(t,r,"/loyalty/promotions/rewards");return this.getResponse(await this.client.request("GET",s,void 0,this.getApiToken(r)))}}class K extends o{async getAddressSuggestions(t,r){const s=this.getStoreUrl(t,"/suggestions/address");return this.getResponse(await this.client.request("POST",s,r))}}class Y extends o{async getProfile(t,r,s){const i=this.getStoreUrl(t,"/me",r);return this.getResponse(await this.client.request("GET",i,null,s))}async updateProfile(t,r,s){const i=this.getStoreUrl(t,"/me");return this.getResponse(await this.client.request("PUT",i,r,s))}async removeProfile(t,r,s){const i=this.getStoreUrl(t,"/me");return await this.client.request("DELETE",i,r,s),!0}async getSettings(t,r){const s=this.getStoreUrl(t,"/me/settings");return this.getResponse(await this.client.request("GET",s,null,r))}async updateSettings(t,r,s){const i=this.getStoreUrl(t,"/me/settings");return this.getResponse(await this.client.request("PUT",i,r,s))}async getAddresses(t,r,s){const i=this.getStoreUrl(t,"/me/addresses",r);return this.getPaginatedResponse(await this.client.request("GET",i,null,s))}async createAddress(t,r,s){const i=this.getStoreUrl(t,"/me/addresses");return this.getResponse(await this.client.request("POST",i,r,s))}async updateAddress(t,r,s,i){const u=this.getStoreUrl(t,`/me/addresses/${r}`);return this.getResponse(await this.client.request("PUT",u,s,i))}async deleteAddress(t,r,s){const i=this.getStoreUrl(t,`/me/addresses/${r}`);return await this.client.request("DELETE",i,null,s),!0}async getPaymentMethods(t,r,s){const i=this.getStoreUrl(t,"/me/payment-methods",r);return this.getPaginatedResponse(await this.client.request("GET",i,null,s))}async deletePaymentMethod(t,r,s){const i=this.getStoreUrl(t,`/me/payment-methods/${r}`);return await this.client.request("DELETE",i,null,s),!0}async getBonusesTransactions(t,r,s){const i=this.getStoreUrl(t,"/me/loyalty/transactions",r);return this.getPaginatedResponse(await this.client.request("GET",i,null,s))}async getBonusesBalance(t){const r=this.getStoreUrl(t,"/me/loyalty/balance");return this.getResponse(await this.client.request("GET",r,null,null))}}class Q extends o{async checkPhone(t,r){const s=this.getStoreUrl(t,"/auth/check");return this.getResponse(await this.client.request("POST",s,r))}async register(t,r){const s=this.getStoreUrl(t,"/auth/register");return this.getResponse(await this.client.request("POST",s,r))}async confirmRegistration(t,r){const s=this.getStoreUrl(t,"/auth/register/confirm");return this.getResponse(await this.client.request("POST",s,r))}async resendRegistrationConfirmation(t,r){const s=this.getStoreUrl(t,"/auth/register/resend");return this.getResponse(await this.client.request("POST",s,r))}async login(t,r){const s=this.getStoreUrl(t,"/auth/login");return this.getResponse(await this.client.request("POST",s,r))}async dispatchPasswordReset(t,r){const s=this.getStoreUrl(t,"/auth/password/request");return this.getResponse(await this.client.request("POST",s,r))}async resetPassword(t,r){const s=this.getStoreUrl(t,"/auth/password/reset");return this.getResponse(await this.client.request("POST",s,r))}}class x{constructor(t,r){a(this,"client");a(this,"store");a(this,"auth");a(this,"customer");a(this,"categories");a(this,"products");a(this,"addresses");a(this,"orders");a(this,"collections");a(this,"offers");a(this,"articles");a(this,"feedback");const s=d.build(t,r);this.store=new R(s),this.auth=new Q(s),this.customer=new Y(s),this.categories=new p(s),this.products=new O(s),this.addresses=new K(s),this.orders=new U(s),this.collections=new y(s),this.offers=new m(s),this.articles=new w(s),this.feedback=new f(s),this.client=s}setApiToken(t){return this.client.setToken(t),this}}var S=(e=>(e.Female="female",e.Male="male",e.Other="other",e))(S||{}),q=(e=>(e.CloudPayments="cloudpayments",e))(q||{}),v=(e=>(e.Visa="visa",e.MasterCard="master-card",e.MIR="mir",e.Maestro="maestro",e.AmericanExpress="american-express",e.DinersClub="diners-club",e.Discover="discover",e.JCB="jcb",e.UnionPay="union-pay",e))(v||{}),P=(e=>(e.Select="select",e.MutipleSelect="mutiple_select",e.Checkboxes="checkboxes",e.Radios="radios",e.Range="range",e.Text="text",e))(P||{}),T=(e=>(e.Integer="integer",e.Float="float",e))(T||{}),b=(e=>(e.Increase="increase",e.Decrease="decrease",e))(b||{}),E=(e=>(e.Pending="pending",e.Confirmed="confirmed",e.Cancelled="cancelled",e.Rejected="rejected",e.Refunded="refunded",e.PartiallyRefunded="partially_refunded",e))(E||{}),A=(e=>(e.Manual="manual",e.Cashback="cashback",e.ReferralReward="referral_reward",e.RecruitReward="recruit_reward",e.Payment="payment",e.Cancellation="cancellation",e.Refund="refund",e.Adjustment="adjustment",e.WelcomeBonuses="welcome_bonuses",e.PromotionReward="promotion_reward",e.External="external",e))(A||{}),C=(e=>(e.Delivery="delivery",e.Pickup="pickup",e.OnPremise="on_premise",e))(C||{}),G=(e=>(e.Payment="payment",e.Refund="refund",e))(G||{}),$=(e=>(e.Cash="cash",e.CreditCard="credit-card",e.CloudPayments="cloudpayments",e.CardToken="card_token",e.Bonuses="bonuses",e))($||{}),_=(e=>(e.Pending="pending",e.Confirmed="confirmed",e.Cancelled="cancelled",e.PendingRefund="pending_refund",e.Refunding="refunding",e.Refunded="refunded",e))(_||{}),D=(e=>(e.Auth="auth",e.Charge="charge",e))(D||{}),j=(e=>(e.PersonsCount="persons_count",e.DeliveryTime="delivery_time",e))(j||{}),z=(e=>(e.PriceMismatch="price_mismatch",e.OutOfStock="out_of_stock",e.Unavailable="unavailable",e))(z||{}),V=(e=>(e.None="none",e.Cleanup="cleanup",e))(V||{}),F=(e=>(e.Piece="piece",e.Gram="gram",e.Kilogram="kilogram",e.Meter="meter",e))(F||{}),I=(e=>(e.Weight="weight",e.Width="width",e.Height="height",e.Length="length",e))(I||{}),M=(e=>(e.Netto="netto",e.Brutto="brutto",e))(M||{}),Z=(e=>(e.Color="color",e))(Z||{}),L=(e=>(e.Category="category",e.Group="group",e.VariantOption="variant_option",e.VariantOptionValue="variant_option_value",e))(L||{}),N=(e=>(e.Amount="amount",e.Percentage="percentage",e))(N||{}),W=(e=>(e.Email="email",e.Website="website",e.Vk="vk",e.Facebook="facebook",e.Instagram="instagram",e.Twitter="twitter",e.Ok="ok",e.Tiktok="tiktok",e))(W||{}),B=(e=>(e.Yes="yes",e.No="no",e.Both="both",e))(B||{}),J=(e=>(e.Disabled="disabled",e.Preauth="preauth",e.Confirmation="confirmation",e))(J||{}),X=(e=>(e.Dadata="dadata",e.Manual="manual",e))(X||{}),H=(e=>(e.Registration="registration",e.ResendRegistrationCode="resend_registration_code",e.ResetPassword="reset_password",e.OrderSubmission="order_submission",e.FeedbackRequest="feedback_request",e.CallbackRequest="callback_request",e))(H||{});n.AcquiringType=q,n.AddressSuggestionsProvider=c,n.AddressesProvider=X,n.ArticlesResource=w,n.BonusesTransactionReason=A,n.BonusesTransactionStatus=E,n.BonusesTransactionType=b,n.CategoriesResource=p,n.CloudpaymentsChargeType=D,n.CollectionsResource=y,n.ContactType=W,n.DeliveryMethod=C,n.Dimension=I,n.DimensionType=M,n.DiscountType=N,n.FeatureRange=T,n.FeatureType=P,n.FeedbackResource=f,n.Gender=S,n.OffersResource=m,n.OrderAuthenticationMethod=J,n.OrderCartCheckerResultAction=V,n.OrderCartCheckerResultReason=z,n.OrderOptionKind=j,n.OrderPaymentTransactionStatus=_,n.OrderPaymentTransactionType=G,n.OrdersResource=U,n.PaymentMethod=$,n.PaymentSystemType=v,n.ProductContextType=L,n.ProductsResource=O,n.RecaptchaAction=H,n.StoreResource=R,n.TernaryFilter=B,n.UnitType=F,n.VariantOptionType=Z,n.ZenkyError=g,n.ZenkyErrorBuilder=k,n.ZenkyStorefront=x,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
1
+ (function(n,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(n=typeof globalThis<"u"?globalThis:n||self,c(n.zenkyStorefrontApi={}))})(this,function(n){"use strict";var ee=Object.defineProperty;var te=(n,c,o)=>c in n?ee(n,c,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[c]=o;var a=(n,c,o)=>(te(n,typeof c!="symbol"?c+"":c,o),o);var c=(e=>(e.DADATA="dadata",e))(c||{});class o{constructor(t){this.client=t}getStoreUrl(t,r,s={}){return this.getUrl(`/store/${t}${r}`,s)}getUrl(t,r={}){if(!Object.keys(r).length)return t;const s=[];Object.keys(r).forEach(u=>{s.push(`${u}=${r[u]}`)});const i=t.includes("?")?"&":"?";return`${t}${i}${s.join("&")}`}getPaginatedResponse(t){if(!t||!Array.isArray(t.data)||!t.meta||!t.meta.pagination)throw new Error("getPaginatedResponse(): Invalid response.");const r=t.data,s=t.meta.pagination;return{items:r,pagination:s}}getResponse(t){if(!t||!t.data)throw new Error("getResponse(): Invalid response.");return t.data}}class w extends o{async getArticleCategories(t){const r=this.getStoreUrl(t,"/articles/categories");return this.getPaginatedResponse(await this.client.request("GET",r))}async getArticleCategory(t,r){const s=this.getStoreUrl(t,`/articles/categories/${r}`);return this.getResponse(await this.client.request("GET",s))}async getArticles(t,r){const s=this.getStoreUrl(t,"/articles",r);return this.getPaginatedResponse(await this.client.request("GET",s))}async getArticle(t,r,s){const i=this.getStoreUrl(t,`/articles/${r}`,s);return this.getResponse(await this.client.request("GET",i))}}class p extends o{async getCategories(t,r){const s=this.getStoreUrl(t,"/categories",r);return this.getPaginatedResponse(await this.client.request("GET",s))}async getCategoriesTree(t,r){const s=this.getStoreUrl(t,"/categories/tree",r);return this.getResponse(await this.client.request("GET",s))}async getCategory(t,r,s){const i=this.getStoreUrl(t,`/categories/${r}`,s);return this.getResponse(await this.client.request("GET",i))}async getFeaturesGroups(t,r){const s=this.getStoreUrl(t,`/categories/${r}/features/groups`);return this.getResponse(await this.client.request("GET",s))}async getFeatures(t,r){const s=this.getStoreUrl(t,`/categories/${r}/features`);return this.getResponse(await this.client.request("GET",s))}}class g extends Error{constructor(r,s){super(r);a(this,"err");this.err=s}}class k{static async build(t){const r=await t.json();switch(t.status){case 401:return new g((r==null?void 0:r.message)??"Unauthenticated.",null);default:return new g(r==null?void 0:r.message,(r==null?void 0:r.error)||null)}}}class d{constructor(t,r,s,i,u,l){a(this,"baseUrl");a(this,"token");a(this,"client");a(this,"timezone");a(this,"fetchFunction");a(this,"fetchOptions");this.baseUrl=t,this.token=r,this.client=s,this.timezone=i,this.fetchFunction=typeof u=="function"?u:fetch,this.fetchOptions=typeof l<"u"?l:{}}static build(t,r){return new d((t==null?void 0:t.baseUrl)||"https://storefront.zenky.io/v1",(t==null?void 0:t.token)||null,(t==null?void 0:t.client)||"web",(t==null?void 0:t.timezone)||"UTC",r,t==null?void 0:t.fetchOptions)}setToken(t){return this.token=t,this}async request(t,r,s,i){const u={Accept:"application/json","X-Zenky-Client":this.client,"X-Timezone":this.timezone};i?u.Authorization=`Bearer ${i}`:this.token&&(u.Authorization=`Bearer ${this.token}`);const l={method:t,mode:"cors",...this.fetchOptions};s&&(u["Content-Type"]="application/json",l.body=JSON.stringify(s)),l.headers=u;const h=await this.fetchFunction.call(null,`${this.baseUrl}${r}`,l);if(h.ok)return h.status===204?!0:h.json();throw await k.build(h)}}class R extends o{async getStore(t){const r=this.getUrl(`/store/${t}`);return this.getResponse(await this.client.request("GET",r))}async getStoreByBundleId(t){const r=this.getUrl(`/store/by-bundle/${t}`);return this.getResponse(await this.client.request("GET",r))}}class y extends o{async getCollections(t,r){const s=this.getStoreUrl(t,"/collections",r);return this.getPaginatedResponse(await this.client.request("GET",s))}async getCollection(t,r){const s=this.getStoreUrl(t,`/collections/${r}`);return this.getResponse(await this.client.request("GET",s))}}class m extends o{async getOffers(t,r){const s=this.getStoreUrl(t,"/offers",r);return this.getPaginatedResponse(await this.client.request("GET",s))}async getOffer(t,r,s){const i=this.getStoreUrl(t,`/offers/${r}`,s);return this.getResponse(await this.client.request("GET",i))}}class f extends o{async createFeedback(t,r){const s=this.getStoreUrl(t,"/feedback",r);return this.getResponse(await this.client.request("POST",s))}async createCallback(t,r){const s=this.getStoreUrl(t,"/callback",r);return await this.client.request("POST",s),!0}}class O extends o{async getProducts(t,r){const s=this.getStoreUrl(t,"/products",r);return this.getPaginatedResponse(await this.client.request("GET",s))}async getProduct(t,r,s){const i=this.getStoreUrl(t,`/products/${r}`,s);return this.getResponse(await this.client.request("GET",i))}async getProductVariantPrice(t,r,s,i){const u=this.getStoreUrl(t,`/products/${r}/variants/${s}/price`);return this.getResponse(await this.client.request("POST",u,i))}}class U extends o{getOrderUrl(t,r,s,i){const u=typeof r=="string"?r:r.id,l=typeof r=="string"?void 0:r.token;return this.getStoreUrl(t,`/orders/${u}${s}${l?"?token="+l:""}`,i)}getApiToken(t){if(!(typeof t=="string"||typeof t.api_token>"u"))return t.api_token}async getOrders(t,r,s){const i=this.getStoreUrl(t,"/orders",r);return this.getPaginatedResponse(await this.client.request("GET",i,void 0,s))}async createOrder(t,r,s){const i=this.getStoreUrl(t,"/orders");return this.getResponse(await this.client.request("POST",i,r,s))}async getOrder(t,r,s){const i=this.getOrderUrl(t,r,"",s);return this.getResponse(await this.client.request("GET",i,void 0,this.getApiToken(r)))}async getOrderSettings(t,r){const s=this.getOrderUrl(t,r,"/settings");return this.getResponse(await this.client.request("GET",s,void 0,this.getApiToken(r)))}async addProductVariantToOrder(t,r,s){const i=this.getOrderUrl(t,r,"/products");return this.getResponse(await this.client.request("POST",i,s,this.getApiToken(r)))}async removeProductVariantFromOrder(t,r,s){const i=this.getOrderUrl(t,r,"/products");return this.getResponse(await this.client.request("POST",i,s,this.getApiToken(r)))}async checkProducts(t,r){const s=this.getOrderUrl(t,r,"/products/check");return this.getResponse(await this.client.request("POST",s,void 0,this.getApiToken(r)))}async setOrderCustomer(t,r,s){const i=this.getOrderUrl(t,r,"/checkout/customer");return await this.client.request("POST",i,s,this.getApiToken(r)),!0}async setOrderDeliveryMethod(t,r,s){const i=this.getOrderUrl(t,r,"/checkout/delivery");return this.getResponse(await this.client.request("POST",i,s,this.getApiToken(r)))}async setOrderPayments(t,r,s){const i=this.getOrderUrl(t,r,"/checkout/payments");return this.getResponse(await this.client.request("POST",i,s,this.getApiToken(r)))}async getOrderBonusesPreview(t,r,s){const i=this.getOrderUrl(t,r,"/checkout/payments/bonuses",{amount:s});return this.getResponse(await this.client.request("GET",i,void 0,this.getApiToken(r)))}async getOrderTotal(t,r){const s=this.getOrderUrl(t,r,"/checkout/total");return this.getResponse(await this.client.request("GET",s,void 0,this.getApiToken(r)))}async checkoutOrder(t,r,s){const i=this.getOrderUrl(t,r,"/checkout");return this.getResponse(await this.client.request("POST",i,s,this.getApiToken(r)))}async confirmOrder(t,r,s){const i=this.getOrderUrl(t,r,"/confirm");return await this.client.request("POST",i,s,this.getApiToken(r)),!0}async resendOrderConfirmationCode(t,r){const s=this.getOrderUrl(t,r,"/confirm/resend");return await this.client.request("POST",s,void 0,this.getApiToken(r)),!0}async getOrderBonusesTransactions(t,r,s){const i=this.getOrderUrl(t,r,"/loyalty/transactions",s);return this.getPaginatedResponse(await this.client.request("GET",i,void 0,this.getApiToken(r)))}async getOrderCashbackTransaction(t,r){const s=this.getOrderUrl(t,r,"/loyalty/transactions/cashback");return this.getResponse(await this.client.request("GET",s,void 0,this.getApiToken(r)))}async dispatchPromotionsChecker(t,r){const s=this.getOrderUrl(t,r,"/loyalty/promotions/check");return this.getResponse(await this.client.request("POST",s,void 0,this.getApiToken(r))).dispatched}async getOrderPromotionRewards(t,r){const s=this.getOrderUrl(t,r,"/loyalty/promotions/rewards");return this.getResponse(await this.client.request("GET",s,void 0,this.getApiToken(r)))}}class K extends o{async getAddressSuggestions(t,r){const s=this.getStoreUrl(t,"/suggestions/address");return this.getResponse(await this.client.request("POST",s,r))}}class Y extends o{async getProfile(t,r,s){const i=this.getStoreUrl(t,"/me",r);return this.getResponse(await this.client.request("GET",i,null,s))}async updateProfile(t,r,s){const i=this.getStoreUrl(t,"/me");return this.getResponse(await this.client.request("PUT",i,r,s))}async removeProfile(t,r,s){const i=this.getStoreUrl(t,"/me");return await this.client.request("DELETE",i,r,s),!0}async getSettings(t,r){const s=this.getStoreUrl(t,"/me/settings");return this.getResponse(await this.client.request("GET",s,null,r))}async updateSettings(t,r,s){const i=this.getStoreUrl(t,"/me/settings");return this.getResponse(await this.client.request("PUT",i,r,s))}async getAddresses(t,r,s){const i=this.getStoreUrl(t,"/me/addresses",r);return this.getPaginatedResponse(await this.client.request("GET",i,null,s))}async createAddress(t,r,s){const i=this.getStoreUrl(t,"/me/addresses");return this.getResponse(await this.client.request("POST",i,r,s))}async updateAddress(t,r,s,i){const u=this.getStoreUrl(t,`/me/addresses/${r}`);return this.getResponse(await this.client.request("PUT",u,s,i))}async deleteAddress(t,r,s){const i=this.getStoreUrl(t,`/me/addresses/${r}`);return await this.client.request("DELETE",i,null,s),!0}async getPaymentMethods(t,r,s){const i=this.getStoreUrl(t,"/me/payment-methods",r);return this.getPaginatedResponse(await this.client.request("GET",i,null,s))}async deletePaymentMethod(t,r,s){const i=this.getStoreUrl(t,`/me/payment-methods/${r}`);return await this.client.request("DELETE",i,null,s),!0}async getBonusesTransactions(t,r,s){const i=this.getStoreUrl(t,"/me/loyalty/transactions",r);return this.getPaginatedResponse(await this.client.request("GET",i,null,s))}async getBonusesBalance(t){const r=this.getStoreUrl(t,"/me/loyalty/balance");return this.getResponse(await this.client.request("GET",r,null,null))}}class Q extends o{async checkPhone(t,r){const s=this.getStoreUrl(t,"/auth/check");return this.getResponse(await this.client.request("POST",s,r))}async register(t,r){const s=this.getStoreUrl(t,"/auth/register");return this.getResponse(await this.client.request("POST",s,r))}async confirmRegistration(t,r){const s=this.getStoreUrl(t,"/auth/register/confirm");return this.getResponse(await this.client.request("POST",s,r))}async resendRegistrationConfirmation(t,r){const s=this.getStoreUrl(t,"/auth/register/resend");return this.getResponse(await this.client.request("POST",s,r))}async login(t,r){const s=this.getStoreUrl(t,"/auth/login");return this.getResponse(await this.client.request("POST",s,r))}async dispatchPasswordReset(t,r){const s=this.getStoreUrl(t,"/auth/password/request");return this.getResponse(await this.client.request("POST",s,r))}async resetPassword(t,r){const s=this.getStoreUrl(t,"/auth/password/reset");return this.getResponse(await this.client.request("POST",s,r))}}class x{constructor(t,r){a(this,"client");a(this,"store");a(this,"auth");a(this,"customer");a(this,"categories");a(this,"products");a(this,"addresses");a(this,"orders");a(this,"collections");a(this,"offers");a(this,"articles");a(this,"feedback");const s=d.build(t,r);this.store=new R(s),this.auth=new Q(s),this.customer=new Y(s),this.categories=new p(s),this.products=new O(s),this.addresses=new K(s),this.orders=new U(s),this.collections=new y(s),this.offers=new m(s),this.articles=new w(s),this.feedback=new f(s),this.client=s}setApiToken(t){return this.client.setToken(t),this}}var S=(e=>(e.Female="female",e.Male="male",e.Other="other",e))(S||{}),q=(e=>(e.CloudPayments="cloudpayments",e))(q||{}),v=(e=>(e.Visa="visa",e.MasterCard="master-card",e.MIR="mir",e.Maestro="maestro",e.AmericanExpress="american-express",e.DinersClub="diners-club",e.Discover="discover",e.JCB="jcb",e.UnionPay="union-pay",e))(v||{}),P=(e=>(e.Select="select",e.MutipleSelect="mutiple_select",e.Checkboxes="checkboxes",e.Radios="radios",e.Range="range",e.Text="text",e))(P||{}),T=(e=>(e.Integer="integer",e.Float="float",e))(T||{}),b=(e=>(e.Increase="increase",e.Decrease="decrease",e))(b||{}),E=(e=>(e.Pending="pending",e.Confirmed="confirmed",e.Cancelled="cancelled",e.Rejected="rejected",e.Refunded="refunded",e.PartiallyRefunded="partially_refunded",e))(E||{}),A=(e=>(e.Manual="manual",e.Cashback="cashback",e.ReferralReward="referral_reward",e.RecruitReward="recruit_reward",e.Payment="payment",e.Cancellation="cancellation",e.Refund="refund",e.Adjustment="adjustment",e.WelcomeBonuses="welcome_bonuses",e.PromotionReward="promotion_reward",e.External="external",e))(A||{}),C=(e=>(e.Delivery="delivery",e.Pickup="pickup",e.OnPremise="on_premise",e))(C||{}),G=(e=>(e.Payment="payment",e.Refund="refund",e))(G||{}),$=(e=>(e.Cash="cash",e.CreditCard="credit-card",e.CloudPayments="cloudpayments",e.CardToken="card_token",e.Bonuses="bonuses",e))($||{}),_=(e=>(e.Pending="pending",e.Confirmed="confirmed",e.Cancelled="cancelled",e.PendingRefund="pending_refund",e.Refunding="refunding",e.Refunded="refunded",e))(_||{}),D=(e=>(e.Auth="auth",e.Charge="charge",e))(D||{}),j=(e=>(e.PersonsCount="persons_count",e.DeliveryTime="delivery_time",e))(j||{}),z=(e=>(e.PriceMismatch="price_mismatch",e.OutOfStock="out_of_stock",e.Unavailable="unavailable",e))(z||{}),V=(e=>(e.None="none",e.Cleanup="cleanup",e))(V||{}),F=(e=>(e.Piece="piece",e.Gram="gram",e.Kilogram="kilogram",e.Meter="meter",e))(F||{}),I=(e=>(e.Weight="weight",e.Width="width",e.Height="height",e.Length="length",e))(I||{}),M=(e=>(e.Netto="netto",e.Brutto="brutto",e))(M||{}),Z=(e=>(e.Color="color",e))(Z||{}),L=(e=>(e.Category="category",e.Group="group",e.VariantOption="variant_option",e.VariantOptionValue="variant_option_value",e))(L||{}),N=(e=>(e.Amount="amount",e.Percentage="percentage",e))(N||{}),W=(e=>(e.Email="email",e.Website="website",e.Vk="vk",e.Facebook="facebook",e.Instagram="instagram",e.Twitter="twitter",e.Ok="ok",e.Tiktok="tiktok",e))(W||{}),B=(e=>(e.Yes="yes",e.No="no",e.Both="both",e))(B||{}),J=(e=>(e.Disabled="disabled",e.Preauth="preauth",e.Confirmation="confirmation",e))(J||{}),X=(e=>(e.Dadata="dadata",e.Manual="manual",e))(X||{}),H=(e=>(e.Registration="registration",e.ResendRegistrationCode="resend_registration_code",e.ResetPassword="reset_password",e.OrderSubmission="order_submission",e.FeedbackRequest="feedback_request",e.CallbackRequest="callback_request",e))(H||{});n.AcquiringType=q,n.AddressSuggestionsProvider=c,n.AddressesProvider=X,n.ArticlesResource=w,n.BonusesTransactionReason=A,n.BonusesTransactionStatus=E,n.BonusesTransactionType=b,n.CategoriesResource=p,n.CloudpaymentsChargeType=D,n.CollectionsResource=y,n.ContactType=W,n.DeliveryMethod=C,n.Dimension=I,n.DimensionType=M,n.DiscountType=N,n.FeatureRange=T,n.FeatureType=P,n.FeedbackResource=f,n.Gender=S,n.OffersResource=m,n.OrderAuthenticationMethod=J,n.OrderCartCheckerResultAction=V,n.OrderCartCheckerResultReason=z,n.OrderOptionKind=j,n.OrderPaymentTransactionStatus=_,n.OrderPaymentTransactionType=G,n.OrdersResource=U,n.PaymentMethod=$,n.PaymentSystemType=v,n.ProductContextType=L,n.ProductsResource=O,n.RecaptchaAction=H,n.StoreResource=R,n.TernaryFilter=B,n.UnitType=F,n.VariantOptionType=Z,n.ZenkyError=g,n.ZenkyErrorBuilder=k,n.ZenkyStorefront=x,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenky/storefront-api",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "description": "Zenky Storefront API SDK",
5
5
  "author": "Timur Zurbaev <hello@zurbaev.ru>",
6
6
  "license": "MIT",