@zenky/storefront-api 0.0.37 → 0.0.39
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.ts
CHANGED
|
@@ -580,6 +580,8 @@ export interface CatalogItem {
|
|
|
580
580
|
}
|
|
581
581
|
export interface RemoteCatalog {
|
|
582
582
|
url: string;
|
|
583
|
+
city_id: string | null;
|
|
584
|
+
stock_id: string | null;
|
|
583
585
|
}
|
|
584
586
|
export declare class CatalogResource extends AbstractResource {
|
|
585
587
|
getCatalog(storeId: string, request?: ShowCatalogRequest): Promise<CatalogItem[]>;
|
|
@@ -683,6 +685,7 @@ export interface Store {
|
|
|
683
685
|
links: Contact[];
|
|
684
686
|
phones: Phone[];
|
|
685
687
|
cities: City[];
|
|
688
|
+
catalogs: RemoteCatalog[];
|
|
686
689
|
settings: StoreSettings;
|
|
687
690
|
}
|
|
688
691
|
export declare class StoreResource extends AbstractResource {
|
|
@@ -78,7 +78,7 @@ class A extends d {
|
|
|
78
78
|
return this.getResponse(await this.client.request("GET", r));
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
class
|
|
81
|
+
class O extends Error {
|
|
82
82
|
constructor(e, r) {
|
|
83
83
|
super(e);
|
|
84
84
|
l(this, "err");
|
|
@@ -90,9 +90,9 @@ class b {
|
|
|
90
90
|
const e = await t.json();
|
|
91
91
|
switch (t.status) {
|
|
92
92
|
case 401:
|
|
93
|
-
return new
|
|
93
|
+
return new O((e == null ? void 0 : e.message) ?? "Unauthenticated.", null);
|
|
94
94
|
default:
|
|
95
|
-
return new
|
|
95
|
+
return new O(e == null ? void 0 : e.message, (e == null ? void 0 : e.error) || null);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
}
|
|
@@ -138,22 +138,22 @@ class k {
|
|
|
138
138
|
return `${t}${n}${r.join("&")}`;
|
|
139
139
|
}
|
|
140
140
|
async request(t, e, r, n) {
|
|
141
|
-
const i = {
|
|
141
|
+
const i = !e.startsWith("/"), a = {
|
|
142
142
|
Accept: "application/json",
|
|
143
143
|
"X-Zenky-Client": this.client,
|
|
144
144
|
"X-Timezone": this.timezone
|
|
145
145
|
};
|
|
146
|
-
n ?
|
|
147
|
-
const
|
|
146
|
+
n ? a.Authorization = `Bearer ${n}` : this.token && (a.Authorization = `Bearer ${this.token}`);
|
|
147
|
+
const o = {
|
|
148
148
|
method: t,
|
|
149
149
|
mode: "cors",
|
|
150
150
|
...this.fetchOptions
|
|
151
151
|
};
|
|
152
|
-
r && (
|
|
153
|
-
const
|
|
154
|
-
if (
|
|
155
|
-
return
|
|
156
|
-
throw await b.build(
|
|
152
|
+
r && (a["Content-Type"] = "application/json", o.body = JSON.stringify(r)), o.headers = i ? { Accept: "application/json" } : a;
|
|
153
|
+
const u = i ? e : `${this.baseUrl}${e}`, c = await this.fetchFunction.call(null, u, o);
|
|
154
|
+
if (c.ok)
|
|
155
|
+
return c.status === 204 ? !0 : c.json();
|
|
156
|
+
throw await b.build(c);
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
class T extends d {
|
|
@@ -425,7 +425,7 @@ class V extends d {
|
|
|
425
425
|
**/
|
|
426
426
|
var p = "application/x-postmate-v1+json", x = 5, I = 0, L = function() {
|
|
427
427
|
return ++I;
|
|
428
|
-
},
|
|
428
|
+
}, h = function() {
|
|
429
429
|
var t;
|
|
430
430
|
return g.debug ? (t = console).log.apply(t, arguments) : null;
|
|
431
431
|
}, M = function(t) {
|
|
@@ -446,7 +446,7 @@ var p = "application/x-postmate-v1+json", x = 5, I = 0, L = function() {
|
|
|
446
446
|
* @param {String|Boolean} allowedOrigin The whitelisted origin or false to skip origin check
|
|
447
447
|
* @return {Boolean}
|
|
448
448
|
*/
|
|
449
|
-
},
|
|
449
|
+
}, E = function(t, e) {
|
|
450
450
|
return !(typeof e == "string" && t.origin !== e || !t.data || typeof t.data == "object" && !("postmate" in t.data) || t.data.type !== p || !z[t.data.postmate]);
|
|
451
451
|
}, j = function(t, e) {
|
|
452
452
|
var r = typeof t[e] == "function" ? t[e]() : t[e];
|
|
@@ -454,19 +454,19 @@ var p = "application/x-postmate-v1+json", x = 5, I = 0, L = function() {
|
|
|
454
454
|
}, H = /* @__PURE__ */ function() {
|
|
455
455
|
function s(e) {
|
|
456
456
|
var r = this;
|
|
457
|
-
this.parent = e.parent, this.frame = e.frame, this.child = e.child, this.childOrigin = e.childOrigin, this.events = {}, process.env.NODE_ENV !== "production" && (
|
|
458
|
-
if (!
|
|
457
|
+
this.parent = e.parent, this.frame = e.frame, this.child = e.child, this.childOrigin = e.childOrigin, this.events = {}, process.env.NODE_ENV !== "production" && (h("Parent: Registering API"), h("Parent: Awaiting messages...")), this.listener = function(n) {
|
|
458
|
+
if (!E(n, r.childOrigin))
|
|
459
459
|
return !1;
|
|
460
460
|
var i = ((n || {}).data || {}).value || {}, a = i.data, o = i.name;
|
|
461
|
-
n.data.postmate === "emit" && (process.env.NODE_ENV !== "production" &&
|
|
462
|
-
}, this.parent.addEventListener("message", this.listener, !1), process.env.NODE_ENV !== "production" &&
|
|
461
|
+
n.data.postmate === "emit" && (process.env.NODE_ENV !== "production" && h("Parent: Received event emission: " + o), o in r.events && r.events[o].call(r, a));
|
|
462
|
+
}, this.parent.addEventListener("message", this.listener, !1), process.env.NODE_ENV !== "production" && h("Parent: Awaiting event emissions from Child");
|
|
463
463
|
}
|
|
464
464
|
var t = s.prototype;
|
|
465
465
|
return t.get = function(r) {
|
|
466
466
|
var n = this;
|
|
467
467
|
return new g.Promise(function(i) {
|
|
468
|
-
var a = L(), o = function u(
|
|
469
|
-
|
|
468
|
+
var a = L(), o = function u(c) {
|
|
469
|
+
c.data.uid === a && c.data.postmate === "reply" && (n.parent.removeEventListener("message", u, !1), i(c.data.value));
|
|
470
470
|
};
|
|
471
471
|
n.parent.addEventListener("message", o, !1), n.child.postMessage({
|
|
472
472
|
postmate: "request",
|
|
@@ -485,26 +485,26 @@ var p = "application/x-postmate-v1+json", x = 5, I = 0, L = function() {
|
|
|
485
485
|
}, t.on = function(r, n) {
|
|
486
486
|
this.events[r] = n;
|
|
487
487
|
}, t.destroy = function() {
|
|
488
|
-
process.env.NODE_ENV !== "production" &&
|
|
488
|
+
process.env.NODE_ENV !== "production" && h("Parent: Destroying Postmate instance"), window.removeEventListener("message", this.listener, !1), this.frame.parentNode.removeChild(this.frame);
|
|
489
489
|
}, s;
|
|
490
490
|
}(), F = /* @__PURE__ */ function() {
|
|
491
491
|
function s(e) {
|
|
492
492
|
var r = this;
|
|
493
|
-
this.model = e.model, this.parent = e.parent, this.parentOrigin = e.parentOrigin, this.child = e.child, process.env.NODE_ENV !== "production" && (
|
|
494
|
-
if (
|
|
495
|
-
process.env.NODE_ENV !== "production" &&
|
|
493
|
+
this.model = e.model, this.parent = e.parent, this.parentOrigin = e.parentOrigin, this.child = e.child, process.env.NODE_ENV !== "production" && (h("Child: Registering API"), h("Child: Awaiting messages...")), this.child.addEventListener("message", function(n) {
|
|
494
|
+
if (E(n, r.parentOrigin)) {
|
|
495
|
+
process.env.NODE_ENV !== "production" && h("Child: Received request", n.data);
|
|
496
496
|
var i = n.data, a = i.property, o = i.uid, u = i.data;
|
|
497
497
|
if (n.data.postmate === "call") {
|
|
498
498
|
a in r.model && typeof r.model[a] == "function" && r.model[a](u);
|
|
499
499
|
return;
|
|
500
500
|
}
|
|
501
|
-
j(r.model, a).then(function(
|
|
501
|
+
j(r.model, a).then(function(c) {
|
|
502
502
|
return n.source.postMessage({
|
|
503
503
|
property: a,
|
|
504
504
|
postmate: "reply",
|
|
505
505
|
type: p,
|
|
506
506
|
uid: o,
|
|
507
|
-
value:
|
|
507
|
+
value: c
|
|
508
508
|
}, n.origin);
|
|
509
509
|
});
|
|
510
510
|
}
|
|
@@ -512,7 +512,7 @@ var p = "application/x-postmate-v1+json", x = 5, I = 0, L = function() {
|
|
|
512
512
|
}
|
|
513
513
|
var t = s.prototype;
|
|
514
514
|
return t.emit = function(r, n) {
|
|
515
|
-
process.env.NODE_ENV !== "production" &&
|
|
515
|
+
process.env.NODE_ENV !== "production" && h('Child: Emitting Event "' + r + '"', n), this.parent.postMessage({
|
|
516
516
|
postmate: "emit",
|
|
517
517
|
type: p,
|
|
518
518
|
value: {
|
|
@@ -523,19 +523,19 @@ var p = "application/x-postmate-v1+json", x = 5, I = 0, L = function() {
|
|
|
523
523
|
}, s;
|
|
524
524
|
}(), g = /* @__PURE__ */ function() {
|
|
525
525
|
function s(e) {
|
|
526
|
-
var r = e.container, n = r === void 0 ? typeof n < "u" ? n : document.body : r, i = e.model, a = e.url, o = e.name, u = e.classListArray,
|
|
527
|
-
return this.parent = window, this.frame = document.createElement("iframe"), this.frame.name = o || "", this.frame.classList.add.apply(this.frame.classList,
|
|
526
|
+
var r = e.container, n = r === void 0 ? typeof n < "u" ? n : document.body : r, i = e.model, a = e.url, o = e.name, u = e.classListArray, c = u === void 0 ? [] : u;
|
|
527
|
+
return this.parent = window, this.frame = document.createElement("iframe"), this.frame.name = o || "", this.frame.classList.add.apply(this.frame.classList, c), n.appendChild(this.frame), this.child = this.frame.contentWindow || this.frame.contentDocument.parentWindow, this.model = i || {}, this.sendHandshake(a);
|
|
528
528
|
}
|
|
529
529
|
var t = s.prototype;
|
|
530
530
|
return t.sendHandshake = function(r) {
|
|
531
531
|
var n = this, i = M(r), a = 0, o;
|
|
532
|
-
return new s.Promise(function(u,
|
|
532
|
+
return new s.Promise(function(u, c) {
|
|
533
533
|
var m = function v(y) {
|
|
534
|
-
return
|
|
534
|
+
return E(y, i) ? y.data.postmate === "handshake-reply" ? (clearInterval(o), process.env.NODE_ENV !== "production" && h("Parent: Received handshake reply from Child"), n.parent.removeEventListener("message", v, !1), n.childOrigin = y.origin, process.env.NODE_ENV !== "production" && h("Parent: Saving Child origin", n.childOrigin), u(new H(n))) : (process.env.NODE_ENV !== "production" && h("Parent: Invalid handshake reply"), c("Failed handshake")) : !1;
|
|
535
535
|
};
|
|
536
536
|
n.parent.addEventListener("message", m, !1);
|
|
537
537
|
var f = function() {
|
|
538
|
-
a++, process.env.NODE_ENV !== "production" &&
|
|
538
|
+
a++, process.env.NODE_ENV !== "production" && h("Parent: Sending handshake attempt " + a, {
|
|
539
539
|
childOrigin: i
|
|
540
540
|
}), n.child.postMessage({
|
|
541
541
|
postmate: "handshake",
|
|
@@ -545,7 +545,7 @@ var p = "application/x-postmate-v1+json", x = 5, I = 0, L = function() {
|
|
|
545
545
|
}, w = function() {
|
|
546
546
|
f(), o = setInterval(f, 500);
|
|
547
547
|
};
|
|
548
|
-
n.frame.attachEvent ? n.frame.attachEvent("onload", w) : n.frame.onload = w, process.env.NODE_ENV !== "production" &&
|
|
548
|
+
n.frame.attachEvent ? n.frame.attachEvent("onload", w) : n.frame.onload = w, process.env.NODE_ENV !== "production" && h("Parent: Loading frame", {
|
|
549
549
|
url: r
|
|
550
550
|
}), n.frame.src = r;
|
|
551
551
|
});
|
|
@@ -570,14 +570,14 @@ g.Model = /* @__PURE__ */ function() {
|
|
|
570
570
|
var a = function o(u) {
|
|
571
571
|
if (u.data.postmate) {
|
|
572
572
|
if (u.data.postmate === "handshake") {
|
|
573
|
-
process.env.NODE_ENV !== "production" &&
|
|
573
|
+
process.env.NODE_ENV !== "production" && h("Child: Received handshake from Parent"), r.child.removeEventListener("message", o, !1), process.env.NODE_ENV !== "production" && h("Child: Sending handshake reply to Parent"), u.source.postMessage({
|
|
574
574
|
postmate: "handshake-reply",
|
|
575
575
|
type: p
|
|
576
576
|
}, u.origin), r.parentOrigin = u.origin;
|
|
577
|
-
var
|
|
578
|
-
return
|
|
579
|
-
r.model[m] =
|
|
580
|
-
}), process.env.NODE_ENV !== "production" &&
|
|
577
|
+
var c = u.data.model;
|
|
578
|
+
return c && (Object.keys(c).forEach(function(m) {
|
|
579
|
+
r.model[m] = c[m];
|
|
580
|
+
}), process.env.NODE_ENV !== "production" && h("Child: Inherited and extended model from Parent")), process.env.NODE_ENV !== "production" && h("Child: Saving Parent origin", r.parentOrigin), n(new F(r));
|
|
581
581
|
}
|
|
582
582
|
return i("Handshake Reply Failed");
|
|
583
583
|
}
|
|
@@ -637,7 +637,7 @@ class W extends d {
|
|
|
637
637
|
};
|
|
638
638
|
}
|
|
639
639
|
}
|
|
640
|
-
class
|
|
640
|
+
class Ee {
|
|
641
641
|
constructor(t, e) {
|
|
642
642
|
l(this, "client");
|
|
643
643
|
l(this, "store");
|
|
@@ -698,7 +698,7 @@ export {
|
|
|
698
698
|
ve as TernaryFilter,
|
|
699
699
|
ce as UnitType,
|
|
700
700
|
de as VariantOptionType,
|
|
701
|
-
|
|
701
|
+
O as ZenkyError,
|
|
702
702
|
b as ZenkyErrorBuilder,
|
|
703
|
-
|
|
703
|
+
Ee as ZenkyStorefront
|
|
704
704
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
(function(i,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(i=typeof globalThis<"u"?globalThis:i||self,g(i.zenkyStorefrontApi={}))})(this,function(i){"use strict";var ke=Object.defineProperty;var Oe=(i,g,u)=>g in i?ke(i,g,{enumerable:!0,configurable:!0,writable:!0,value:u}):i[g]=u;var c=(i,g,u)=>(Oe(i,typeof g!="symbol"?g+"":g,u),u);var g=(s=>(s.DADATA="dadata",s))(g||{});class u{constructor(t){this.client=t}getStoreUrl(t,e,r={}){return this.client.getStoreUrl(t,e,r)}getPaginatedResponse(t){if(!t||!Array.isArray(t.data)||!t.meta||!t.meta.pagination)throw new Error("getPaginatedResponse(): Invalid response.");const e=t.data,r=t.meta.pagination;return{items:e,pagination:r}}getResponse(t){if(!t||!t.data)throw new Error("getResponse(): Invalid response.");return t.data}}class U extends u{async getArticleCategories(t){const e=this.getStoreUrl(t,"/articles/categories");return this.getPaginatedResponse(await this.client.request("GET",e))}async getArticleCategory(t,e){const r=this.getStoreUrl(t,`/articles/categories/${e}`);return this.getResponse(await this.client.request("GET",r))}async getArticles(t,e){const r=this.getStoreUrl(t,"/articles",e);return this.getPaginatedResponse(await this.client.request("GET",r))}async getArticle(t,e,r){const n=this.getStoreUrl(t,`/articles/${e}`,r);return this.getResponse(await this.client.request("GET",n))}}class S extends u{async getCatalog(t,e){const r=this.getStoreUrl(t,"/catalog",e);return this.getResponse(await this.client.request("GET",r))}async getRemoteCatalog(t,e){const r=this.getStoreUrl(t,"/catalog/url",e);return this.getResponse(await this.client.request("GET",r))}async getCatalogFromRemoteUrl(t,e){const r=await this.getRemoteCatalog(t,e);return this.getResponse(await this.client.request("GET",r.url))}}class q extends u{async getCategories(t,e){const r=this.getStoreUrl(t,"/categories",e);return this.getPaginatedResponse(await this.client.request("GET",r))}async getCategoriesTree(t,e){const r=this.getStoreUrl(t,"/categories/tree",e);return this.getResponse(await this.client.request("GET",r))}async getCategory(t,e,r){const n=this.getStoreUrl(t,`/categories/${e}`,r);return this.getResponse(await this.client.request("GET",n))}async getFeaturesGroups(t,e){const r=this.getStoreUrl(t,`/categories/${e}/features/groups`);return this.getResponse(await this.client.request("GET",r))}async getFeatures(t,e){const r=this.getStoreUrl(t,`/categories/${e}/features`);return this.getResponse(await this.client.request("GET",r))}}class O extends Error{constructor(e,r){super(e);c(this,"err");this.err=r}}class T{static async build(t){const e=await t.json();switch(t.status){case 401:return new O((e==null?void 0:e.message)??"Unauthenticated.",null);default:return new O(e==null?void 0:e.message,(e==null?void 0:e.error)||null)}}}class R{constructor(t,e,r,n,a,o,l){c(this,"baseUrl");c(this,"baseAuthUrl");c(this,"token");c(this,"client");c(this,"timezone");c(this,"fetchFunction");c(this,"fetchOptions");this.baseUrl=t,this.baseAuthUrl=e,this.token=r,this.client=n,this.timezone=a,this.fetchFunction=typeof o=="function"?o:fetch,this.fetchOptions=typeof l<"u"?l:{}}static build(t,e){return new R((t==null?void 0:t.baseUrl)||"https://storefront.zenky.io/v1",(t==null?void 0:t.baseAuthUrl)||"https://auth.zenky.io/",(t==null?void 0:t.token)||null,(t==null?void 0:t.client)||"web",(t==null?void 0:t.timezone)||"UTC",e,t==null?void 0:t.fetchOptions)}setToken(t){return this.token=t,this}getBaseAuthUrl(){return this.baseAuthUrl}getStoreUrl(t,e,r={}){return this.getUrl(`/store/${t}${e}`,r)}getUrl(t,e={}){if(!Object.keys(e).length)return t;const r=[];Object.keys(e).forEach(a=>{r.push(`${a}=${e[a]}`)});const n=t.includes("?")?"&":"?";return`${t}${n}${r.join("&")}`}async request(t,e,r,n){const a={Accept:"application/json","X-Zenky-Client":this.client,"X-Timezone":this.timezone};n?a.Authorization=`Bearer ${n}`:this.token&&(a.Authorization=`Bearer ${this.token}`);const o={method:t,mode:"cors",...this.fetchOptions};r&&(a["Content-Type"]="application/json",o.body=JSON.stringify(r)),o.headers=a;const l=await this.fetchFunction.call(null,`${this.baseUrl}${e}`,o);if(l.ok)return l.status===204?!0:l.json();throw await T.build(l)}}class A extends u{async getStore(t){const e=this.client.getUrl(`/store/${t}`);return this.getResponse(await this.client.request("GET",e))}async getStoreByBundleId(t){const e=this.client.getUrl(`/store/by-bundle/${t}`);return this.getResponse(await this.client.request("GET",e))}}class b extends u{async getCollections(t,e){const r=this.getStoreUrl(t,"/collections",e);return this.getPaginatedResponse(await this.client.request("GET",r))}async getCollection(t,e){const r=this.getStoreUrl(t,`/collections/${e}`);return this.getResponse(await this.client.request("GET",r))}}class C extends u{async getOffers(t,e){const r=this.getStoreUrl(t,"/offers",e);return this.getPaginatedResponse(await this.client.request("GET",r))}async getOffer(t,e,r){const n=this.getStoreUrl(t,`/offers/${e}`,r);return this.getResponse(await this.client.request("GET",n))}}class _ extends u{async createFeedback(t,e){const r=this.getStoreUrl(t,"/feedback",e);return this.getResponse(await this.client.request("POST",r))}async createCallback(t,e){const r=this.getStoreUrl(t,"/callback",e);return await this.client.request("POST",r),!0}}class N extends u{async getProducts(t,e){const r=this.getStoreUrl(t,"/products",e);return this.getPaginatedResponse(await this.client.request("GET",r))}async getProduct(t,e,r){const n=this.getStoreUrl(t,`/products/${e}`,r);return this.getResponse(await this.client.request("GET",n))}async getProductVariantPrice(t,e,r,n){const a=this.getStoreUrl(t,`/products/${e}/variants/${r}/price`);return this.getResponse(await this.client.request("POST",a,n))}}class G extends u{getOrderUrl(t,e,r,n){const a=typeof e=="string"?e:e.id,o=typeof e=="string"?void 0:e.token;return this.getStoreUrl(t,`/orders/${a}${r}${o?"?token="+o:""}`,n)}getApiToken(t){if(!(typeof t=="string"||typeof t.api_token>"u"))return t.api_token}async getOrders(t,e,r){const n=this.getStoreUrl(t,"/orders",e);return this.getPaginatedResponse(await this.client.request("GET",n,void 0,r))}async createOrder(t,e,r){const n=this.getStoreUrl(t,"/orders");return this.getResponse(await this.client.request("POST",n,e,r))}async getOrder(t,e,r){const n=this.getOrderUrl(t,e,"",r);return this.getResponse(await this.client.request("GET",n,void 0,this.getApiToken(e)))}async getOrderSettings(t,e){const r=this.getOrderUrl(t,e,"/settings");return this.getResponse(await this.client.request("GET",r,void 0,this.getApiToken(e)))}async addProductVariantToOrder(t,e,r){const n=this.getOrderUrl(t,e,"/products");return this.getResponse(await this.client.request("POST",n,r,this.getApiToken(e)))}async removeProductVariantFromOrder(t,e,r){const n=this.getOrderUrl(t,e,"/products/remove");return this.getResponse(await this.client.request("POST",n,r,this.getApiToken(e)))}async checkProducts(t,e){const r=this.getOrderUrl(t,e,"/products/check");return this.getResponse(await this.client.request("POST",r,void 0,this.getApiToken(e)))}async getOrderCheckoutUrl(t,e,r){const n=this.getOrderUrl(t,e,"/checkout/url");return this.getResponse(await this.client.request("POST",n,{redirect_url:r},this.getApiToken(e))).url}async setOrderCustomer(t,e,r){const n=this.getOrderUrl(t,e,"/checkout/customer");return await this.client.request("POST",n,r,this.getApiToken(e)),!0}async setOrderDeliveryMethod(t,e,r){const n=this.getOrderUrl(t,e,"/checkout/delivery");return this.getResponse(await this.client.request("POST",n,r,this.getApiToken(e)))}async setOrderPayments(t,e,r){const n=this.getOrderUrl(t,e,"/checkout/payments");return this.getResponse(await this.client.request("POST",n,r,this.getApiToken(e)))}async getOrderPromocode(t,e,r){const n=this.getOrderUrl(t,e,"/checkout/promocode");return this.getResponse(await this.client.request("GET",n,r,this.getApiToken(e)))}async setOrderPromocode(t,e,r){const n=this.getOrderUrl(t,e,"/checkout/promocode");return this.getResponse(await this.client.request("POST",n,r,this.getApiToken(e)))}async removeOrderPromocode(t,e){const r=this.getOrderUrl(t,e,"/checkout/promocode");return await this.client.request("DELETE",r,null,this.getApiToken(e)),!0}async getOrderBonusesPreview(t,e,r){const n=this.getOrderUrl(t,e,"/checkout/payments/bonuses",{amount:r});return this.getResponse(await this.client.request("GET",n,void 0,this.getApiToken(e)))}async getOrderTotal(t,e){const r=this.getOrderUrl(t,e,"/checkout/total");return this.getResponse(await this.client.request("GET",r,void 0,this.getApiToken(e)))}async checkoutOrder(t,e,r){const n=this.getOrderUrl(t,e,"/checkout");return this.getResponse(await this.client.request("POST",n,r,this.getApiToken(e)))}async confirmOrder(t,e,r){const n=this.getOrderUrl(t,e,"/confirm");return await this.client.request("POST",n,r,this.getApiToken(e)),!0}async resendOrderConfirmationCode(t,e){const r=this.getOrderUrl(t,e,"/confirm/resend");return await this.client.request("POST",r,void 0,this.getApiToken(e)),!0}async getOrderBonusesTransactions(t,e,r){const n=this.getOrderUrl(t,e,"/loyalty/transactions",r);return this.getPaginatedResponse(await this.client.request("GET",n,void 0,this.getApiToken(e)))}async getOrderCashbackTransaction(t,e){const r=this.getOrderUrl(t,e,"/loyalty/transactions/cashback");return this.getResponse(await this.client.request("GET",r,void 0,this.getApiToken(e)))}async dispatchPromotionsChecker(t,e){const r=this.getOrderUrl(t,e,"/loyalty/promotions/check");return this.getResponse(await this.client.request("POST",r,void 0,this.getApiToken(e))).dispatched}async getOrderPromotionRewards(t,e){const r=this.getOrderUrl(t,e,"/loyalty/promotions/rewards");return this.getResponse(await this.client.request("GET",r,void 0,this.getApiToken(e)))}async getCloudpaymentsReceipt(t,e,r){const n=this.getOrderUrl(t,e,`/payments/${r}/receipt`);return this.getResponse(await this.client.request("GET",n,void 0,this.getApiToken(e)))}}class le extends u{async getAddressSuggestions(t,e){const r=this.getStoreUrl(t,"/suggestions/address");return this.getResponse(await this.client.request("POST",r,e))}}class ce extends u{async getProfile(t,e,r){const n=this.getStoreUrl(t,"/me",e);return this.getResponse(await this.client.request("GET",n,null,r))}async updateProfile(t,e,r){const n=this.getStoreUrl(t,"/me");return this.getResponse(await this.client.request("PUT",n,e,r))}async removeProfile(t,e,r){const n=this.getStoreUrl(t,"/me");return await this.client.request("DELETE",n,e,r),!0}async getSettings(t,e){const r=this.getStoreUrl(t,"/me/settings");return this.getResponse(await this.client.request("GET",r,null,e))}async updateSettings(t,e,r){const n=this.getStoreUrl(t,"/me/settings");return this.getResponse(await this.client.request("PUT",n,e,r))}async getAddresses(t,e,r){const n=this.getStoreUrl(t,"/me/addresses",e);return this.getPaginatedResponse(await this.client.request("GET",n,null,r))}async createAddress(t,e,r){const n=this.getStoreUrl(t,"/me/addresses");return this.getResponse(await this.client.request("POST",n,e,r))}async updateAddress(t,e,r,n){const a=this.getStoreUrl(t,`/me/addresses/${e}`);return this.getResponse(await this.client.request("PUT",a,r,n))}async deleteAddress(t,e,r){const n=this.getStoreUrl(t,`/me/addresses/${e}`);return await this.client.request("DELETE",n,null,r),!0}async getPaymentMethods(t,e,r){const n=this.getStoreUrl(t,"/me/payment-methods",e);return this.getPaginatedResponse(await this.client.request("GET",n,null,r))}async deletePaymentMethod(t,e,r){const n=this.getStoreUrl(t,`/me/payment-methods/${e}`);return await this.client.request("DELETE",n,null,r),!0}async getBonusesTransactions(t,e,r){const n=this.getStoreUrl(t,"/me/loyalty/transactions",e);return this.getPaginatedResponse(await this.client.request("GET",n,null,r))}async getBonusesBalance(t,e){const r=this.getStoreUrl(t,"/me/loyalty/balance");return this.getResponse(await this.client.request("GET",r,null,e))}async revokeToken(t,e){const r=this.getStoreUrl(t,"/me/logout");return await this.client.request("POST",r,null,e),!0}}/**
|
|
1
|
+
(function(i,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(i=typeof globalThis<"u"?globalThis:i||self,p(i.zenkyStorefrontApi={}))})(this,function(i){"use strict";var ke=Object.defineProperty;var Oe=(i,p,h)=>p in i?ke(i,p,{enumerable:!0,configurable:!0,writable:!0,value:h}):i[p]=h;var c=(i,p,h)=>(Oe(i,typeof p!="symbol"?p+"":p,h),h);var p=(s=>(s.DADATA="dadata",s))(p||{});class h{constructor(t){this.client=t}getStoreUrl(t,e,r={}){return this.client.getStoreUrl(t,e,r)}getPaginatedResponse(t){if(!t||!Array.isArray(t.data)||!t.meta||!t.meta.pagination)throw new Error("getPaginatedResponse(): Invalid response.");const e=t.data,r=t.meta.pagination;return{items:e,pagination:r}}getResponse(t){if(!t||!t.data)throw new Error("getResponse(): Invalid response.");return t.data}}class U extends h{async getArticleCategories(t){const e=this.getStoreUrl(t,"/articles/categories");return this.getPaginatedResponse(await this.client.request("GET",e))}async getArticleCategory(t,e){const r=this.getStoreUrl(t,`/articles/categories/${e}`);return this.getResponse(await this.client.request("GET",r))}async getArticles(t,e){const r=this.getStoreUrl(t,"/articles",e);return this.getPaginatedResponse(await this.client.request("GET",r))}async getArticle(t,e,r){const n=this.getStoreUrl(t,`/articles/${e}`,r);return this.getResponse(await this.client.request("GET",n))}}class S extends h{async getCatalog(t,e){const r=this.getStoreUrl(t,"/catalog",e);return this.getResponse(await this.client.request("GET",r))}async getRemoteCatalog(t,e){const r=this.getStoreUrl(t,"/catalog/url",e);return this.getResponse(await this.client.request("GET",r))}async getCatalogFromRemoteUrl(t,e){const r=await this.getRemoteCatalog(t,e);return this.getResponse(await this.client.request("GET",r.url))}}class q extends h{async getCategories(t,e){const r=this.getStoreUrl(t,"/categories",e);return this.getPaginatedResponse(await this.client.request("GET",r))}async getCategoriesTree(t,e){const r=this.getStoreUrl(t,"/categories/tree",e);return this.getResponse(await this.client.request("GET",r))}async getCategory(t,e,r){const n=this.getStoreUrl(t,`/categories/${e}`,r);return this.getResponse(await this.client.request("GET",n))}async getFeaturesGroups(t,e){const r=this.getStoreUrl(t,`/categories/${e}/features/groups`);return this.getResponse(await this.client.request("GET",r))}async getFeatures(t,e){const r=this.getStoreUrl(t,`/categories/${e}/features`);return this.getResponse(await this.client.request("GET",r))}}class O extends Error{constructor(e,r){super(e);c(this,"err");this.err=r}}class T{static async build(t){const e=await t.json();switch(t.status){case 401:return new O((e==null?void 0:e.message)??"Unauthenticated.",null);default:return new O(e==null?void 0:e.message,(e==null?void 0:e.error)||null)}}}class R{constructor(t,e,r,n,a,o,l){c(this,"baseUrl");c(this,"baseAuthUrl");c(this,"token");c(this,"client");c(this,"timezone");c(this,"fetchFunction");c(this,"fetchOptions");this.baseUrl=t,this.baseAuthUrl=e,this.token=r,this.client=n,this.timezone=a,this.fetchFunction=typeof o=="function"?o:fetch,this.fetchOptions=typeof l<"u"?l:{}}static build(t,e){return new R((t==null?void 0:t.baseUrl)||"https://storefront.zenky.io/v1",(t==null?void 0:t.baseAuthUrl)||"https://auth.zenky.io/",(t==null?void 0:t.token)||null,(t==null?void 0:t.client)||"web",(t==null?void 0:t.timezone)||"UTC",e,t==null?void 0:t.fetchOptions)}setToken(t){return this.token=t,this}getBaseAuthUrl(){return this.baseAuthUrl}getStoreUrl(t,e,r={}){return this.getUrl(`/store/${t}${e}`,r)}getUrl(t,e={}){if(!Object.keys(e).length)return t;const r=[];Object.keys(e).forEach(a=>{r.push(`${a}=${e[a]}`)});const n=t.includes("?")?"&":"?";return`${t}${n}${r.join("&")}`}async request(t,e,r,n){const a=!e.startsWith("/"),o={Accept:"application/json","X-Zenky-Client":this.client,"X-Timezone":this.timezone};n?o.Authorization=`Bearer ${n}`:this.token&&(o.Authorization=`Bearer ${this.token}`);const l={method:t,mode:"cors",...this.fetchOptions};r&&(o["Content-Type"]="application/json",l.body=JSON.stringify(r)),l.headers=a?{Accept:"application/json"}:o;const g=a?e:`${this.baseUrl}${e}`,u=await this.fetchFunction.call(null,g,l);if(u.ok)return u.status===204?!0:u.json();throw await T.build(u)}}class A extends h{async getStore(t){const e=this.client.getUrl(`/store/${t}`);return this.getResponse(await this.client.request("GET",e))}async getStoreByBundleId(t){const e=this.client.getUrl(`/store/by-bundle/${t}`);return this.getResponse(await this.client.request("GET",e))}}class b extends h{async getCollections(t,e){const r=this.getStoreUrl(t,"/collections",e);return this.getPaginatedResponse(await this.client.request("GET",r))}async getCollection(t,e){const r=this.getStoreUrl(t,`/collections/${e}`);return this.getResponse(await this.client.request("GET",r))}}class C extends h{async getOffers(t,e){const r=this.getStoreUrl(t,"/offers",e);return this.getPaginatedResponse(await this.client.request("GET",r))}async getOffer(t,e,r){const n=this.getStoreUrl(t,`/offers/${e}`,r);return this.getResponse(await this.client.request("GET",n))}}class _ extends h{async createFeedback(t,e){const r=this.getStoreUrl(t,"/feedback",e);return this.getResponse(await this.client.request("POST",r))}async createCallback(t,e){const r=this.getStoreUrl(t,"/callback",e);return await this.client.request("POST",r),!0}}class N extends h{async getProducts(t,e){const r=this.getStoreUrl(t,"/products",e);return this.getPaginatedResponse(await this.client.request("GET",r))}async getProduct(t,e,r){const n=this.getStoreUrl(t,`/products/${e}`,r);return this.getResponse(await this.client.request("GET",n))}async getProductVariantPrice(t,e,r,n){const a=this.getStoreUrl(t,`/products/${e}/variants/${r}/price`);return this.getResponse(await this.client.request("POST",a,n))}}class G extends h{getOrderUrl(t,e,r,n){const a=typeof e=="string"?e:e.id,o=typeof e=="string"?void 0:e.token;return this.getStoreUrl(t,`/orders/${a}${r}${o?"?token="+o:""}`,n)}getApiToken(t){if(!(typeof t=="string"||typeof t.api_token>"u"))return t.api_token}async getOrders(t,e,r){const n=this.getStoreUrl(t,"/orders",e);return this.getPaginatedResponse(await this.client.request("GET",n,void 0,r))}async createOrder(t,e,r){const n=this.getStoreUrl(t,"/orders");return this.getResponse(await this.client.request("POST",n,e,r))}async getOrder(t,e,r){const n=this.getOrderUrl(t,e,"",r);return this.getResponse(await this.client.request("GET",n,void 0,this.getApiToken(e)))}async getOrderSettings(t,e){const r=this.getOrderUrl(t,e,"/settings");return this.getResponse(await this.client.request("GET",r,void 0,this.getApiToken(e)))}async addProductVariantToOrder(t,e,r){const n=this.getOrderUrl(t,e,"/products");return this.getResponse(await this.client.request("POST",n,r,this.getApiToken(e)))}async removeProductVariantFromOrder(t,e,r){const n=this.getOrderUrl(t,e,"/products/remove");return this.getResponse(await this.client.request("POST",n,r,this.getApiToken(e)))}async checkProducts(t,e){const r=this.getOrderUrl(t,e,"/products/check");return this.getResponse(await this.client.request("POST",r,void 0,this.getApiToken(e)))}async getOrderCheckoutUrl(t,e,r){const n=this.getOrderUrl(t,e,"/checkout/url");return this.getResponse(await this.client.request("POST",n,{redirect_url:r},this.getApiToken(e))).url}async setOrderCustomer(t,e,r){const n=this.getOrderUrl(t,e,"/checkout/customer");return await this.client.request("POST",n,r,this.getApiToken(e)),!0}async setOrderDeliveryMethod(t,e,r){const n=this.getOrderUrl(t,e,"/checkout/delivery");return this.getResponse(await this.client.request("POST",n,r,this.getApiToken(e)))}async setOrderPayments(t,e,r){const n=this.getOrderUrl(t,e,"/checkout/payments");return this.getResponse(await this.client.request("POST",n,r,this.getApiToken(e)))}async getOrderPromocode(t,e,r){const n=this.getOrderUrl(t,e,"/checkout/promocode");return this.getResponse(await this.client.request("GET",n,r,this.getApiToken(e)))}async setOrderPromocode(t,e,r){const n=this.getOrderUrl(t,e,"/checkout/promocode");return this.getResponse(await this.client.request("POST",n,r,this.getApiToken(e)))}async removeOrderPromocode(t,e){const r=this.getOrderUrl(t,e,"/checkout/promocode");return await this.client.request("DELETE",r,null,this.getApiToken(e)),!0}async getOrderBonusesPreview(t,e,r){const n=this.getOrderUrl(t,e,"/checkout/payments/bonuses",{amount:r});return this.getResponse(await this.client.request("GET",n,void 0,this.getApiToken(e)))}async getOrderTotal(t,e){const r=this.getOrderUrl(t,e,"/checkout/total");return this.getResponse(await this.client.request("GET",r,void 0,this.getApiToken(e)))}async checkoutOrder(t,e,r){const n=this.getOrderUrl(t,e,"/checkout");return this.getResponse(await this.client.request("POST",n,r,this.getApiToken(e)))}async confirmOrder(t,e,r){const n=this.getOrderUrl(t,e,"/confirm");return await this.client.request("POST",n,r,this.getApiToken(e)),!0}async resendOrderConfirmationCode(t,e){const r=this.getOrderUrl(t,e,"/confirm/resend");return await this.client.request("POST",r,void 0,this.getApiToken(e)),!0}async getOrderBonusesTransactions(t,e,r){const n=this.getOrderUrl(t,e,"/loyalty/transactions",r);return this.getPaginatedResponse(await this.client.request("GET",n,void 0,this.getApiToken(e)))}async getOrderCashbackTransaction(t,e){const r=this.getOrderUrl(t,e,"/loyalty/transactions/cashback");return this.getResponse(await this.client.request("GET",r,void 0,this.getApiToken(e)))}async dispatchPromotionsChecker(t,e){const r=this.getOrderUrl(t,e,"/loyalty/promotions/check");return this.getResponse(await this.client.request("POST",r,void 0,this.getApiToken(e))).dispatched}async getOrderPromotionRewards(t,e){const r=this.getOrderUrl(t,e,"/loyalty/promotions/rewards");return this.getResponse(await this.client.request("GET",r,void 0,this.getApiToken(e)))}async getCloudpaymentsReceipt(t,e,r){const n=this.getOrderUrl(t,e,`/payments/${r}/receipt`);return this.getResponse(await this.client.request("GET",n,void 0,this.getApiToken(e)))}}class le extends h{async getAddressSuggestions(t,e){const r=this.getStoreUrl(t,"/suggestions/address");return this.getResponse(await this.client.request("POST",r,e))}}class ce extends h{async getProfile(t,e,r){const n=this.getStoreUrl(t,"/me",e);return this.getResponse(await this.client.request("GET",n,null,r))}async updateProfile(t,e,r){const n=this.getStoreUrl(t,"/me");return this.getResponse(await this.client.request("PUT",n,e,r))}async removeProfile(t,e,r){const n=this.getStoreUrl(t,"/me");return await this.client.request("DELETE",n,e,r),!0}async getSettings(t,e){const r=this.getStoreUrl(t,"/me/settings");return this.getResponse(await this.client.request("GET",r,null,e))}async updateSettings(t,e,r){const n=this.getStoreUrl(t,"/me/settings");return this.getResponse(await this.client.request("PUT",n,e,r))}async getAddresses(t,e,r){const n=this.getStoreUrl(t,"/me/addresses",e);return this.getPaginatedResponse(await this.client.request("GET",n,null,r))}async createAddress(t,e,r){const n=this.getStoreUrl(t,"/me/addresses");return this.getResponse(await this.client.request("POST",n,e,r))}async updateAddress(t,e,r,n){const a=this.getStoreUrl(t,`/me/addresses/${e}`);return this.getResponse(await this.client.request("PUT",a,r,n))}async deleteAddress(t,e,r){const n=this.getStoreUrl(t,`/me/addresses/${e}`);return await this.client.request("DELETE",n,null,r),!0}async getPaymentMethods(t,e,r){const n=this.getStoreUrl(t,"/me/payment-methods",e);return this.getPaginatedResponse(await this.client.request("GET",n,null,r))}async deletePaymentMethod(t,e,r){const n=this.getStoreUrl(t,`/me/payment-methods/${e}`);return await this.client.request("DELETE",n,null,r),!0}async getBonusesTransactions(t,e,r){const n=this.getStoreUrl(t,"/me/loyalty/transactions",e);return this.getPaginatedResponse(await this.client.request("GET",n,null,r))}async getBonusesBalance(t,e){const r=this.getStoreUrl(t,"/me/loyalty/balance");return this.getResponse(await this.client.request("GET",r,null,e))}async revokeToken(t,e){const r=this.getStoreUrl(t,"/me/logout");return await this.client.request("POST",r,null,e),!0}}/**
|
|
2
2
|
postmate - A powerful, simple, promise-based postMessage library
|
|
3
3
|
@version v1.5.2
|
|
4
4
|
@link https://github.com/dollarshaveclub/postmate
|
|
5
5
|
@author Jacob Kelley <jakie8@gmail.com>
|
|
6
6
|
@license MIT
|
|
7
|
-
**/var f="application/x-postmate-v1+json",ue=5,he=0,de=function(){return++he},h=function(){var t;return m.debug?(t=console).log.apply(t,arguments):null},ge=function(t){var e=document.createElement("a");e.href=t;var r=e.protocol.length>4?e.protocol:window.location.protocol,n=e.host.length?e.port==="80"||e.port==="443"?e.hostname:e.host:window.location.host;return e.origin||r+"//"+n},pe={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},E=function(t,e){return!(typeof e=="string"&&t.origin!==e||!t.data||typeof t.data=="object"&&!("postmate"in t.data)||t.data.type!==f||!pe[t.data.postmate])},me=function(t,e){var r=typeof t[e]=="function"?t[e]():t[e];return m.Promise.resolve(r)},fe=function(){function s(e){var r=this;this.parent=e.parent,this.frame=e.frame,this.child=e.child,this.childOrigin=e.childOrigin,this.events={},process.env.NODE_ENV!=="production"&&(h("Parent: Registering API"),h("Parent: Awaiting messages...")),this.listener=function(n){if(!E(n,r.childOrigin))return!1;var a=((n||{}).data||{}).value||{},o=a.data,l=a.name;n.data.postmate==="emit"&&(process.env.NODE_ENV!=="production"&&h("Parent: Received event emission: "+l),l in r.events&&r.events[l].call(r,o))},this.parent.addEventListener("message",this.listener,!1),process.env.NODE_ENV!=="production"&&h("Parent: Awaiting event emissions from Child")}var t=s.prototype;return t.get=function(r){var n=this;return new m.Promise(function(a){var o=de(),l=function d(p){p.data.uid===o&&p.data.postmate==="reply"&&(n.parent.removeEventListener("message",d,!1),a(p.data.value))};n.parent.addEventListener("message",l,!1),n.child.postMessage({postmate:"request",type:f,property:r,uid:o},n.childOrigin)})},t.call=function(r,n){this.child.postMessage({postmate:"call",type:f,property:r,data:n},this.childOrigin)},t.on=function(r,n){this.events[r]=n},t.destroy=function(){process.env.NODE_ENV!=="production"&&h("Parent: Destroying Postmate instance"),window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame)},s}(),ve=function(){function s(e){var r=this;this.model=e.model,this.parent=e.parent,this.parentOrigin=e.parentOrigin,this.child=e.child,process.env.NODE_ENV!=="production"&&(h("Child: Registering API"),h("Child: Awaiting messages...")),this.child.addEventListener("message",function(n){if(E(n,r.parentOrigin)){process.env.NODE_ENV!=="production"&&h("Child: Received request",n.data);var a=n.data,o=a.property,l=a.uid,d=a.data;if(n.data.postmate==="call"){o in r.model&&typeof r.model[o]=="function"&&r.model[o](d);return}me(r.model,o).then(function(p){return n.source.postMessage({property:o,postmate:"reply",type:f,uid:l,value:p},n.origin)})}})}var t=s.prototype;return t.emit=function(r,n){process.env.NODE_ENV!=="production"&&h('Child: Emitting Event "'+r+'"',n),this.parent.postMessage({postmate:"emit",type:f,value:{name:r,data:n}},this.parentOrigin)},s}(),m=function(){function s(e){var r=e.container,n=r===void 0?typeof n<"u"?n:document.body:r,a=e.model,o=e.url,l=e.name,d=e.classListArray,p=d===void 0?[]:d;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=l||"",this.frame.classList.add.apply(this.frame.classList,p),n.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=a||{},this.sendHandshake(o)}var t=s.prototype;return t.sendHandshake=function(r){var n=this,a=ge(r),o=0,l;return new s.Promise(function(d,p){var v=function y(P){return E(P,a)?P.data.postmate==="handshake-reply"?(clearInterval(l),process.env.NODE_ENV!=="production"&&h("Parent: Received handshake reply from Child"),n.parent.removeEventListener("message",y,!1),n.childOrigin=P.origin,process.env.NODE_ENV!=="production"&&h("Parent: Saving Child origin",n.childOrigin),d(new fe(n))):(process.env.NODE_ENV!=="production"&&h("Parent: Invalid handshake reply"),p("Failed handshake")):!1};n.parent.addEventListener("message",v,!1);var w=function(){o++,process.env.NODE_ENV!=="production"&&h("Parent: Sending handshake attempt "+o,{childOrigin:a}),n.child.postMessage({postmate:"handshake",type:f,model:n.model},a),o===ue&&clearInterval(l)},k=function(){w(),l=setInterval(w,500)};n.frame.attachEvent?n.frame.attachEvent("onload",k):n.frame.onload=k,process.env.NODE_ENV!=="production"&&h("Parent: Loading frame",{url:r}),n.frame.src=r})},s}();m.debug=!1,m.Promise=function(){try{return window?window.Promise:Promise}catch{return null}}(),m.Model=function(){function s(e){return this.child=window,this.model=e,this.parent=this.child.parent,this.sendHandshakeReply()}var t=s.prototype;return t.sendHandshakeReply=function(){var r=this;return new m.Promise(function(n,a){var o=function l(d){if(d.data.postmate){if(d.data.postmate==="handshake"){process.env.NODE_ENV!=="production"&&h("Child: Received handshake from Parent"),r.child.removeEventListener("message",l,!1),process.env.NODE_ENV!=="production"&&h("Child: Sending handshake reply to Parent"),d.source.postMessage({postmate:"handshake-reply",type:f},d.origin),r.parentOrigin=d.origin;var p=d.data.model;return p&&(Object.keys(p).forEach(function(v){r.model[v]=p[v]}),process.env.NODE_ENV!=="production"&&h("Child: Inherited and extended model from Parent")),process.env.NODE_ENV!=="production"&&h("Child: Saving Parent origin",r.parentOrigin),n(new ve(r))}return a("Handshake Reply Failed")}};r.child.addEventListener("message",o,!1)})},s}();class ye extends u{async checkPhone(t,e){const r=this.getStoreUrl(t,"/auth/check");return this.getResponse(await this.client.request("POST",r,e))}async register(t,e){const r=this.getStoreUrl(t,"/auth/register");return this.getResponse(await this.client.request("POST",r,e))}async confirmRegistration(t,e){const r=this.getStoreUrl(t,"/auth/register/confirm");return this.getResponse(await this.client.request("POST",r,e))}async resendRegistrationConfirmation(t,e){const r=this.getStoreUrl(t,"/auth/register/resend");return this.getResponse(await this.client.request("POST",r,e))}async login(t,e){const r=this.getStoreUrl(t,"/auth/login");return this.getResponse(await this.client.request("POST",r,e))}async dispatchPasswordReset(t,e){const r=this.getStoreUrl(t,"/auth/password/request");return this.getResponse(await this.client.request("POST",r,e))}async resetPassword(t,e){const r=this.getStoreUrl(t,"/auth/password/reset");return this.getResponse(await this.client.request("POST",r,e))}useAuthenticationModal(t,e,r,n={}){const a=`${this.client.getBaseAuthUrl()}/?store_id=${t}&response_type=post_message`;let o=null,l=null;return{initAuthenticationModal:async()=>new Promise(v=>{const w=typeof e=="string"?document.querySelector(e):e;o=new m({...n,container:w,url:a}),o.then(k=>{l=k,l.on("zenky:auth:token",r),l.on("zenky:auth:resize",y=>{l.frame.style.height=`${y}px`}),v(!0)})}),destroyAuthenticationModal:()=>{l&&l.destroy()}}}}class we{constructor(t,e){c(this,"client");c(this,"store");c(this,"auth");c(this,"customer");c(this,"catalog");c(this,"categories");c(this,"products");c(this,"addresses");c(this,"orders");c(this,"collections");c(this,"offers");c(this,"articles");c(this,"feedback");const r=R.build(t,e);this.store=new A(r),this.auth=new ye(r),this.customer=new ce(r),this.catalog=new S(r),this.categories=new q(r),this.products=new N(r),this.addresses=new le(r),this.orders=new G(r),this.collections=new b(r),this.offers=new C(r),this.articles=new U(r),this.feedback=new _(r),this.client=r}setApiToken(t){return this.client.setToken(t),this}}var $=(s=>(s.Female="female",s.Male="male",s.Other="other",s))($||{}),D=(s=>(s.CloudPayments="cloudpayments",s))(D||{}),V=(s=>(s.Visa="visa",s.MasterCard="master-card",s.MIR="mir",s.Maestro="maestro",s.AmericanExpress="american-express",s.DinersClub="diners-club",s.Discover="discover",s.JCB="jcb",s.UnionPay="union-pay",s))(V||{}),I=(s=>(s.Select="select",s.MutipleSelect="mutiple_select",s.Checkboxes="checkboxes",s.Radios="radios",s.Range="range",s.Text="text",s))(I||{}),M=(s=>(s.Integer="integer",s.Float="float",s))(M||{}),L=(s=>(s.Increase="increase",s.Decrease="decrease",s))(L||{}),z=(s=>(s.Pending="pending",s.Confirmed="confirmed",s.Cancelled="cancelled",s.Rejected="rejected",s.Refunded="refunded",s.PartiallyRefunded="partially_refunded",s))(z||{}),j=(s=>(s.Manual="manual",s.Cashback="cashback",s.ReferralReward="referral_reward",s.RecruitReward="recruit_reward",s.Payment="payment",s.Cancellation="cancellation",s.Refund="refund",s.Adjustment="adjustment",s.WelcomeBonuses="welcome_bonuses",s.PromotionReward="promotion_reward",s.External="external",s))(j||{}),F=(s=>(s.Delivery="delivery",s.Pickup="pickup",s.OnPremise="on_premise",s))(F||{}),H=(s=>(s.Payment="payment",s.Refund="refund",s))(H||{}),Z=(s=>(s.Cash="cash",s.CreditCard="credit-card",s.CloudPayments="cloudpayments",s.CardToken="card_token",s.Bonuses="bonuses",s))(Z||{}),W=(s=>(s.Pending="pending",s.Confirmed="confirmed",s.Cancelled="cancelled",s.PendingRefund="pending_refund",s.Refunding="refunding",s.Refunded="refunded",s))(W||{}),B=(s=>(s.Auth="auth",s.Charge="charge",s))(B||{}),J=(s=>(s.PersonsCount="persons_count",s.DeliveryTime="delivery_time",s.DeliveryIntervals="delivery_intervals",s))(J||{}),X=(s=>(s.PriceMismatch="price_mismatch",s.OutOfStock="out_of_stock",s.Unavailable="unavailable",s))(X||{}),Y=(s=>(s.None="none",s.Cleanup="cleanup",s))(Y||{}),K=(s=>(s.Piece="piece",s.Gram="gram",s.Kilogram="kilogram",s.Meter="meter",s))(K||{}),Q=(s=>(s.Weight="weight",s.Width="width",s.Height="height",s.Length="length",s))(Q||{}),x=(s=>(s.Netto="netto",s.Brutto="brutto",s))(x||{}),ee=(s=>(s.Color="color",s))(ee||{}),te=(s=>(s.Category="category",s.Group="group",s.VariantOption="variant_option",s.VariantOptionValue="variant_option_value",s))(te||{}),re=(s=>(s.Amount="amount",s.Percentage="percentage",s))(re||{}),se=(s=>(s.Email="email",s.Website="website",s.Vk="vk",s.Facebook="facebook",s.Instagram="instagram",s.Twitter="twitter",s.Ok="ok",s.Tiktok="tiktok",s))(se||{}),ne=(s=>(s.Yes="yes",s.No="no",s.Both="both",s))(ne||{}),ie=(s=>(s.Disabled="disabled",s.Preauth="preauth",s.Confirmation="confirmation",s))(ie||{}),ae=(s=>(s.Dadata="dadata",s.Manual="manual",s))(ae||{}),oe=(s=>(s.Registration="registration",s.ResendRegistrationCode="resend_registration_code",s.ResetPassword="reset_password",s.OrderSubmission="order_submission",s.FeedbackRequest="feedback_request",s.CallbackRequest="callback_request",s))(oe||{});i.AcquiringType=D,i.AddressSuggestionsProvider=g,i.AddressesProvider=ae,i.ArticlesResource=U,i.BonusesTransactionReason=j,i.BonusesTransactionStatus=z,i.BonusesTransactionType=L,i.CatalogResource=S,i.CategoriesResource=q,i.CloudpaymentsChargeType=B,i.CollectionsResource=b,i.ContactType=se,i.DeliveryMethod=F,i.Dimension=Q,i.DimensionType=x,i.DiscountType=re,i.FeatureRange=M,i.FeatureType=I,i.FeedbackResource=_,i.Gender=$,i.OffersResource=C,i.OrderAuthenticationMethod=ie,i.OrderCartCheckerResultAction=Y,i.OrderCartCheckerResultReason=X,i.OrderOptionKind=J,i.OrderPaymentTransactionStatus=W,i.OrderPaymentTransactionType=H,i.OrdersResource=G,i.PaymentMethod=Z,i.PaymentSystemType=V,i.ProductContextType=te,i.ProductsResource=N,i.RecaptchaAction=oe,i.StoreResource=A,i.TernaryFilter=ne,i.UnitType=K,i.VariantOptionType=ee,i.ZenkyError=O,i.ZenkyErrorBuilder=T,i.ZenkyStorefront=we,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|
|
7
|
+
**/var f="application/x-postmate-v1+json",ue=5,he=0,de=function(){return++he},d=function(){var t;return m.debug?(t=console).log.apply(t,arguments):null},ge=function(t){var e=document.createElement("a");e.href=t;var r=e.protocol.length>4?e.protocol:window.location.protocol,n=e.host.length?e.port==="80"||e.port==="443"?e.hostname:e.host:window.location.host;return e.origin||r+"//"+n},pe={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},E=function(t,e){return!(typeof e=="string"&&t.origin!==e||!t.data||typeof t.data=="object"&&!("postmate"in t.data)||t.data.type!==f||!pe[t.data.postmate])},me=function(t,e){var r=typeof t[e]=="function"?t[e]():t[e];return m.Promise.resolve(r)},fe=function(){function s(e){var r=this;this.parent=e.parent,this.frame=e.frame,this.child=e.child,this.childOrigin=e.childOrigin,this.events={},process.env.NODE_ENV!=="production"&&(d("Parent: Registering API"),d("Parent: Awaiting messages...")),this.listener=function(n){if(!E(n,r.childOrigin))return!1;var a=((n||{}).data||{}).value||{},o=a.data,l=a.name;n.data.postmate==="emit"&&(process.env.NODE_ENV!=="production"&&d("Parent: Received event emission: "+l),l in r.events&&r.events[l].call(r,o))},this.parent.addEventListener("message",this.listener,!1),process.env.NODE_ENV!=="production"&&d("Parent: Awaiting event emissions from Child")}var t=s.prototype;return t.get=function(r){var n=this;return new m.Promise(function(a){var o=de(),l=function g(u){u.data.uid===o&&u.data.postmate==="reply"&&(n.parent.removeEventListener("message",g,!1),a(u.data.value))};n.parent.addEventListener("message",l,!1),n.child.postMessage({postmate:"request",type:f,property:r,uid:o},n.childOrigin)})},t.call=function(r,n){this.child.postMessage({postmate:"call",type:f,property:r,data:n},this.childOrigin)},t.on=function(r,n){this.events[r]=n},t.destroy=function(){process.env.NODE_ENV!=="production"&&d("Parent: Destroying Postmate instance"),window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame)},s}(),ve=function(){function s(e){var r=this;this.model=e.model,this.parent=e.parent,this.parentOrigin=e.parentOrigin,this.child=e.child,process.env.NODE_ENV!=="production"&&(d("Child: Registering API"),d("Child: Awaiting messages...")),this.child.addEventListener("message",function(n){if(E(n,r.parentOrigin)){process.env.NODE_ENV!=="production"&&d("Child: Received request",n.data);var a=n.data,o=a.property,l=a.uid,g=a.data;if(n.data.postmate==="call"){o in r.model&&typeof r.model[o]=="function"&&r.model[o](g);return}me(r.model,o).then(function(u){return n.source.postMessage({property:o,postmate:"reply",type:f,uid:l,value:u},n.origin)})}})}var t=s.prototype;return t.emit=function(r,n){process.env.NODE_ENV!=="production"&&d('Child: Emitting Event "'+r+'"',n),this.parent.postMessage({postmate:"emit",type:f,value:{name:r,data:n}},this.parentOrigin)},s}(),m=function(){function s(e){var r=e.container,n=r===void 0?typeof n<"u"?n:document.body:r,a=e.model,o=e.url,l=e.name,g=e.classListArray,u=g===void 0?[]:g;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=l||"",this.frame.classList.add.apply(this.frame.classList,u),n.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=a||{},this.sendHandshake(o)}var t=s.prototype;return t.sendHandshake=function(r){var n=this,a=ge(r),o=0,l;return new s.Promise(function(g,u){var v=function y(P){return E(P,a)?P.data.postmate==="handshake-reply"?(clearInterval(l),process.env.NODE_ENV!=="production"&&d("Parent: Received handshake reply from Child"),n.parent.removeEventListener("message",y,!1),n.childOrigin=P.origin,process.env.NODE_ENV!=="production"&&d("Parent: Saving Child origin",n.childOrigin),g(new fe(n))):(process.env.NODE_ENV!=="production"&&d("Parent: Invalid handshake reply"),u("Failed handshake")):!1};n.parent.addEventListener("message",v,!1);var w=function(){o++,process.env.NODE_ENV!=="production"&&d("Parent: Sending handshake attempt "+o,{childOrigin:a}),n.child.postMessage({postmate:"handshake",type:f,model:n.model},a),o===ue&&clearInterval(l)},k=function(){w(),l=setInterval(w,500)};n.frame.attachEvent?n.frame.attachEvent("onload",k):n.frame.onload=k,process.env.NODE_ENV!=="production"&&d("Parent: Loading frame",{url:r}),n.frame.src=r})},s}();m.debug=!1,m.Promise=function(){try{return window?window.Promise:Promise}catch{return null}}(),m.Model=function(){function s(e){return this.child=window,this.model=e,this.parent=this.child.parent,this.sendHandshakeReply()}var t=s.prototype;return t.sendHandshakeReply=function(){var r=this;return new m.Promise(function(n,a){var o=function l(g){if(g.data.postmate){if(g.data.postmate==="handshake"){process.env.NODE_ENV!=="production"&&d("Child: Received handshake from Parent"),r.child.removeEventListener("message",l,!1),process.env.NODE_ENV!=="production"&&d("Child: Sending handshake reply to Parent"),g.source.postMessage({postmate:"handshake-reply",type:f},g.origin),r.parentOrigin=g.origin;var u=g.data.model;return u&&(Object.keys(u).forEach(function(v){r.model[v]=u[v]}),process.env.NODE_ENV!=="production"&&d("Child: Inherited and extended model from Parent")),process.env.NODE_ENV!=="production"&&d("Child: Saving Parent origin",r.parentOrigin),n(new ve(r))}return a("Handshake Reply Failed")}};r.child.addEventListener("message",o,!1)})},s}();class ye extends h{async checkPhone(t,e){const r=this.getStoreUrl(t,"/auth/check");return this.getResponse(await this.client.request("POST",r,e))}async register(t,e){const r=this.getStoreUrl(t,"/auth/register");return this.getResponse(await this.client.request("POST",r,e))}async confirmRegistration(t,e){const r=this.getStoreUrl(t,"/auth/register/confirm");return this.getResponse(await this.client.request("POST",r,e))}async resendRegistrationConfirmation(t,e){const r=this.getStoreUrl(t,"/auth/register/resend");return this.getResponse(await this.client.request("POST",r,e))}async login(t,e){const r=this.getStoreUrl(t,"/auth/login");return this.getResponse(await this.client.request("POST",r,e))}async dispatchPasswordReset(t,e){const r=this.getStoreUrl(t,"/auth/password/request");return this.getResponse(await this.client.request("POST",r,e))}async resetPassword(t,e){const r=this.getStoreUrl(t,"/auth/password/reset");return this.getResponse(await this.client.request("POST",r,e))}useAuthenticationModal(t,e,r,n={}){const a=`${this.client.getBaseAuthUrl()}/?store_id=${t}&response_type=post_message`;let o=null,l=null;return{initAuthenticationModal:async()=>new Promise(v=>{const w=typeof e=="string"?document.querySelector(e):e;o=new m({...n,container:w,url:a}),o.then(k=>{l=k,l.on("zenky:auth:token",r),l.on("zenky:auth:resize",y=>{l.frame.style.height=`${y}px`}),v(!0)})}),destroyAuthenticationModal:()=>{l&&l.destroy()}}}}class we{constructor(t,e){c(this,"client");c(this,"store");c(this,"auth");c(this,"customer");c(this,"catalog");c(this,"categories");c(this,"products");c(this,"addresses");c(this,"orders");c(this,"collections");c(this,"offers");c(this,"articles");c(this,"feedback");const r=R.build(t,e);this.store=new A(r),this.auth=new ye(r),this.customer=new ce(r),this.catalog=new S(r),this.categories=new q(r),this.products=new N(r),this.addresses=new le(r),this.orders=new G(r),this.collections=new b(r),this.offers=new C(r),this.articles=new U(r),this.feedback=new _(r),this.client=r}setApiToken(t){return this.client.setToken(t),this}}var $=(s=>(s.Female="female",s.Male="male",s.Other="other",s))($||{}),D=(s=>(s.CloudPayments="cloudpayments",s))(D||{}),V=(s=>(s.Visa="visa",s.MasterCard="master-card",s.MIR="mir",s.Maestro="maestro",s.AmericanExpress="american-express",s.DinersClub="diners-club",s.Discover="discover",s.JCB="jcb",s.UnionPay="union-pay",s))(V||{}),I=(s=>(s.Select="select",s.MutipleSelect="mutiple_select",s.Checkboxes="checkboxes",s.Radios="radios",s.Range="range",s.Text="text",s))(I||{}),M=(s=>(s.Integer="integer",s.Float="float",s))(M||{}),L=(s=>(s.Increase="increase",s.Decrease="decrease",s))(L||{}),z=(s=>(s.Pending="pending",s.Confirmed="confirmed",s.Cancelled="cancelled",s.Rejected="rejected",s.Refunded="refunded",s.PartiallyRefunded="partially_refunded",s))(z||{}),j=(s=>(s.Manual="manual",s.Cashback="cashback",s.ReferralReward="referral_reward",s.RecruitReward="recruit_reward",s.Payment="payment",s.Cancellation="cancellation",s.Refund="refund",s.Adjustment="adjustment",s.WelcomeBonuses="welcome_bonuses",s.PromotionReward="promotion_reward",s.External="external",s))(j||{}),F=(s=>(s.Delivery="delivery",s.Pickup="pickup",s.OnPremise="on_premise",s))(F||{}),H=(s=>(s.Payment="payment",s.Refund="refund",s))(H||{}),W=(s=>(s.Cash="cash",s.CreditCard="credit-card",s.CloudPayments="cloudpayments",s.CardToken="card_token",s.Bonuses="bonuses",s))(W||{}),Z=(s=>(s.Pending="pending",s.Confirmed="confirmed",s.Cancelled="cancelled",s.PendingRefund="pending_refund",s.Refunding="refunding",s.Refunded="refunded",s))(Z||{}),B=(s=>(s.Auth="auth",s.Charge="charge",s))(B||{}),J=(s=>(s.PersonsCount="persons_count",s.DeliveryTime="delivery_time",s.DeliveryIntervals="delivery_intervals",s))(J||{}),X=(s=>(s.PriceMismatch="price_mismatch",s.OutOfStock="out_of_stock",s.Unavailable="unavailable",s))(X||{}),Y=(s=>(s.None="none",s.Cleanup="cleanup",s))(Y||{}),K=(s=>(s.Piece="piece",s.Gram="gram",s.Kilogram="kilogram",s.Meter="meter",s))(K||{}),Q=(s=>(s.Weight="weight",s.Width="width",s.Height="height",s.Length="length",s))(Q||{}),x=(s=>(s.Netto="netto",s.Brutto="brutto",s))(x||{}),ee=(s=>(s.Color="color",s))(ee||{}),te=(s=>(s.Category="category",s.Group="group",s.VariantOption="variant_option",s.VariantOptionValue="variant_option_value",s))(te||{}),re=(s=>(s.Amount="amount",s.Percentage="percentage",s))(re||{}),se=(s=>(s.Email="email",s.Website="website",s.Vk="vk",s.Facebook="facebook",s.Instagram="instagram",s.Twitter="twitter",s.Ok="ok",s.Tiktok="tiktok",s))(se||{}),ne=(s=>(s.Yes="yes",s.No="no",s.Both="both",s))(ne||{}),ie=(s=>(s.Disabled="disabled",s.Preauth="preauth",s.Confirmation="confirmation",s))(ie||{}),ae=(s=>(s.Dadata="dadata",s.Manual="manual",s))(ae||{}),oe=(s=>(s.Registration="registration",s.ResendRegistrationCode="resend_registration_code",s.ResetPassword="reset_password",s.OrderSubmission="order_submission",s.FeedbackRequest="feedback_request",s.CallbackRequest="callback_request",s))(oe||{});i.AcquiringType=D,i.AddressSuggestionsProvider=p,i.AddressesProvider=ae,i.ArticlesResource=U,i.BonusesTransactionReason=j,i.BonusesTransactionStatus=z,i.BonusesTransactionType=L,i.CatalogResource=S,i.CategoriesResource=q,i.CloudpaymentsChargeType=B,i.CollectionsResource=b,i.ContactType=se,i.DeliveryMethod=F,i.Dimension=Q,i.DimensionType=x,i.DiscountType=re,i.FeatureRange=M,i.FeatureType=I,i.FeedbackResource=_,i.Gender=$,i.OffersResource=C,i.OrderAuthenticationMethod=ie,i.OrderCartCheckerResultAction=Y,i.OrderCartCheckerResultReason=X,i.OrderOptionKind=J,i.OrderPaymentTransactionStatus=Z,i.OrderPaymentTransactionType=H,i.OrdersResource=G,i.PaymentMethod=W,i.PaymentSystemType=V,i.ProductContextType=te,i.ProductsResource=N,i.RecaptchaAction=oe,i.StoreResource=A,i.TernaryFilter=ne,i.UnitType=K,i.VariantOptionType=ee,i.ZenkyError=O,i.ZenkyErrorBuilder=T,i.ZenkyStorefront=we,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|