@thefittingroom/sdk 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* thefittingroom v0.0.
|
|
2
|
+
* thefittingroom v0.0.8 (2023-07-19T17:34:22.852Z)
|
|
3
3
|
* Copyright 2022-present, TheFittingRoom, Inc. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
@@ -3163,5 +3163,5 @@ class zf{constructor(t){this.auth=t,this.internalListeners=new Map}getUid(){var
|
|
|
3163
3163
|
* See the License for the specific language governing permissions and
|
|
3164
3164
|
* limitations under the License.
|
|
3165
3165
|
*/
|
|
3166
|
-
const $f=c("authIdTokenMaxAge")||300;let Kf=null;function Hf(t=ct()){const e=rt(t,"auth");if(e.isInitialized())return e.getImmediate();const n=function(t,e){const n=rt(t,"auth");if(n.isInitialized()){const t=n.getImmediate();if(f(n.getOptions(),null!=e?e:{}))return t;fl(t,"already-initialized")}return n.initialize({options:e})}(t,{popupRedirectResolver:qf,persistence:[nf,Vd,jd]}),r=c("authTokenSyncURL");if(r){const t=(s=r,async t=>{const e=t&&await t.getIdTokenResult(),n=e&&((new Date).getTime()-Date.parse(e.issuedAtTime))/1e3;if(n&&n>$f)return;const r=null==e?void 0:e.token;Kf!==r&&(Kf=r,await fetch(s,{method:r?"POST":"DELETE",headers:r?{Authorization:`Bearer ${r}`}:{}}))});!function(t,e,n){I(t).beforeAuthStateChanged(e,n)}(n,t,(()=>t(n.currentUser))),function(t,e,n,r){I(t).onIdTokenChanged(e,n,r)}(n,(e=>t(e)))}var s;const i=a("auth");return i&&dd(n,`http://${i}`),n}var Gf;Gf="Browser",nt(new b("auth",((t,{options:e})=>{const n=t.getProvider("app").getImmediate(),r=t.getProvider("heartbeat"),{apiKey:s,authDomain:i}=n.options;return((t,n)=>{ml(s&&!s.includes(":"),"invalid-api-key",{appName:t.name}),ml(!(null==i?void 0:i.includes(":")),"argument-error",{appName:t.name});const r={apiKey:s,authDomain:i,clientPlatform:Gf,apiHost:"identitytoolkit.googleapis.com",tokenApiHost:"securetoken.googleapis.com",apiScheme:"https",sdkClientVersion:ad(Gf)},o=new ud(t,n,r);return function(t,e){const n=(null==e?void 0:e.persistence)||[],r=(Array.isArray(n)?n:[n]).map(Il);(null==e?void 0:e.errorMap)&&t._updateErrorMap(e.errorMap),t._initializeWithPersistence(r,null==e?void 0:e.popupRedirectResolver)}(o,e),o})(n,r)}),"PUBLIC").setInstantiationMode("EXPLICIT").setInstanceCreatedCallback(((t,e,n)=>{t.getProvider("auth-internal").initialize()}))),nt(new b("auth-internal",(t=>(t=>new zf(t))(hd(t.getProvider("auth").getImmediate()))),"PRIVATE").setInstantiationMode("EXPLICIT")),ut(jf,Bf,function(t){switch(t){case"Node":return"node";case"ReactNative":return"rn";case"Worker":return"webworker";case"Cordova":return"cordova";default:return}}(Gf)),ut(jf,Bf,"esm2017");class Wf extends Error{constructor(){super("no frames found"),this.name="NoFramesFoundError"}}class Qf extends Error{constructor(){super("request timeout"),this.name="RequestTimeoutError"}}class Yf extends Error{constructor(){super("user not logged in"),this.name="UserNotLoggedInError"}}class Xf extends Error{constructor(){super("no colorway size assets found"),this.name="NoColorwaySizeAssetsFoundError"}}class Jf extends Error{constructor(){super("no styles found"),this.name="NoStylesFoundError"}}class Zf extends Error{constructor(t,e){super("recommended available sizes error"),this.name="RecommendedAvailableSizesError",this.recommended_size=t,this.available_sizes=e}}var tp=Object.freeze({__proto__:null,NoFramesFoundError:Wf,RequestTimeoutError:Qf,UserNotLoggedInError:Yf,NoColorwaySizeAssetsFoundError:Xf,NoStylesFoundError:Jf,RecommendedAvailableSizesError:Zf});class ep{constructor(t,e){this.firestore=t,this.auth=Hf(e),this.auth.setPersistence(Vd)}get id(){var t;return null===(t=this.user)||void 0===t?void 0:t.uid}onInit(){return new Promise((t=>{const e=this.auth.onAuthStateChanged((n=>{this.setUser(n),t(Boolean(n)),e()}))}))}setUser(t){this.user=t}async getToken(){var t;if(!(null===(t=this.user)||void 0===t?void 0:t.uid))throw new Yf;return await this.user.getIdToken()}async getUserProfile(){var t;if(!(null===(t=this.user)||void 0===t?void 0:t.uid))throw new Yf;const e=await Jh(function(t,e,...n){if(t=I(t),1===arguments.length&&(e=Ys.R()),Xu("doc","path",e),t instanceof sh){const r=ni.fromString(e,...n);return Ju(r),new oh(t,null,new ii(r))}{if(!(t instanceof oh||t instanceof ch))throw new Vs(Fs.INVALID_ARGUMENT,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");const r=t._path.child(ni.fromString(e,...n));return Ju(r),new oh(t.firestore,t instanceof ch?t.converter:null,new ii(r))}}(this.firestore,"users",this.id));return e.data()}watchUserProfileForChanges(t,e){let n;const r=Vh(uh(this.firestore,"users"),jh(Th(),"==",this.id)),s=setTimeout((()=>n()),e);return new Promise((e=>{n=el(r,(r=>{t(r)&&(clearTimeout(s),n(),e(r.docs[0].data()))}))}))}async login(t,e){this.auth.currentUser&&await this.auth.signOut();const n=await Md(this.auth,t,e);this.setUser(n.user)}async logout(){await this.auth.signOut(),this.setUser(null)}async sendPasswordResetEmail(t){await Ld(this.auth,t)}async confirmPasswordReset(t,e){await Pd(this.auth,t,e)}}class np{constructor(){this.promisefyOnSnapshot=(t,e)=>{let n;return{promise:new Promise((r=>{n=el(t,(t=>{r(t),e&&n()}))})),unsubscribe:()=>n()}};const t=at(rl.getInstance().firebase);this.firestore=yh(t),this.user=new ep(this.firestore,t)}onInit(){return this.user.onInit()}query(t,e,n=!0){const r=Vh(uh(this.firestore,t),e);return this.promisefyOnSnapshot(r,n)}getDocs(t,e){return tl(Vh(uh(this.firestore,t),...e))}}const rp=t=>{if(t.code===hl)throw new Error("account has been disabled");throw new Error(t.message)};class sp{static get endpoint(){return rl.getInstance().api.url}static async Fetch({user:t,endpointPath:e,method:n,body:r,useToken:s=!0}){const i=this.getUrl(e,s),o={method:n,headers:await this.getHeaders(t,s),credentials:"include"};r&&(o.body=JSON.stringify(r));const a=await fetch(i,o);if(a.ok)return a;if(500===a.status)throw new Error(a.statusText);const c=await a.json();return Promise.reject(c)}static getUrl(t,e){return e?`${this.endpoint}/v1${t}`:this.endpoint+t}static async getHeaders(t,e){if(!e)return{"Content-Type":"application/json"};return{"Content-Type":"application/json",Authorization:`Bearer ${await t.getToken()}`}}static Get(t,e,n){return this.Fetch({user:t,endpointPath:e,method:"GET",body:null,useToken:n})}static Post(t,e,n=null,r){return this.Fetch({user:t,endpointPath:e,method:"POST",body:n,useToken:r})}static Put(t,e,n,r){return this.Fetch({user:t,endpointPath:e,method:"PUT",body:n,useToken:r})}static Patch(t,e,n,r){return this.Fetch({user:t,endpointPath:e,method:"PATCH",body:n,useToken:r})}static Delete(t,e,n,r){return this.Fetch({user:t,endpointPath:e,method:"DELETE",body:n,useToken:r})}}class ip{constructor(t,e){this.brandId=t,this.firebase=e;const n=rl.getInstance().config;ip.avatarTimeout=n.avatarTimeout?Number(n.avatarTimeout):12e4,ip.vtoTimeout=n.vtoTimeout?Number(n.vtoTimeout):12e4}get user(){return this.firebase.user}get isLoggedIn(){return!this.firebase||Boolean(this.user.id)}onInit(){return this.firebase.onInit()}async tryOn(t){if(!this.isLoggedIn)throw new Yf;try{return await this.getColorwaySizeAssetFrames(t)}catch(e){if(!(e instanceof Wf))throw e;return this.requestThenGetColorwaySizeAssetFrames(t)}}async awaitAvatarCreated(){if(!this.isLoggedIn)throw new Yf;const{promise:t,unsubscribe:e}=this.firebase.query("users",jh(Th(),"==",this.user.id)),n=setTimeout((()=>{throw e(),new Qf}),ip.avatarTimeout),r=await t;clearTimeout(n);return"CREATED"===r.docs[0].data().avatar_status}async getRecommendedSizes(t){if(!this.isLoggedIn)throw new Yf;const e=await sp.Get(this.user,`/styles/${t}/recommendation`);return await e.json()}async getStyles(t,e){const n=[jh("brand_id","==",this.brandId)];(null==t?void 0:t.length)>0&&n.push(jh("id","in",t)),(null==e?void 0:e.length)>0&&n.push(jh("brand_style_id","in",e));try{const t=await this.firebase.getDocs("styles",n),e=new Map;return t.forEach((t=>{const n=t.data();e.set(n.id,n)})),e}catch(t){return rp(t)}}async submitTelephoneNumber(t){const e=t.replace(/[^\+0-9]/g,""),n=await sp.Post(this.user,"/ios-app-link",{phone_number:e},!1);console.log(n)}async awaitColorwaySizeAssetFrames(t){var e,n,r,s;if(!this.isLoggedIn)throw new Yf;const i=await this.user.watchUserProfileForChanges((e=>{var n,r,s;return Boolean(null===(s=null===(r=null===(n=e.docs[0].data())||void 0===n?void 0:n.vto)||void 0===r?void 0:r[this.brandId])||void 0===s?void 0:s[t])}),ip.vtoTimeout);if(!(null===(s=null===(r=null===(n=null===(e=null==i?void 0:i.vto)||void 0===e?void 0:e[this.brandId])||void 0===n?void 0:n[t])||void 0===r?void 0:r.frames)||void 0===s?void 0:s.length))throw new Wf;return i.vto[this.brandId][t].frames}async requestThenGetColorwaySizeAssetFrames(t){var e,n;const[r,s]=await(i=this.getColorwaySizeAssetFromSku(t),i.then((t=>[null,t])).catch((t=>[t])));var i;if(r)throw r;try{return await this.requestColorwaySizeAssetFrames(s.id),this.awaitColorwaySizeAssetFrames(t)}catch(r){if(!r.recommended_size_id)throw new Error(r);const t=r,i=(await this.getStyles([s.style_id],null)).get(s.style_id);if(!(null==i?void 0:i.sizes))throw new Jf;const o=(null===(e=i.sizes[t.recommended_size_id])||void 0===e?void 0:e.label)||(null===(n=i.sizes[t.recommended_size_id])||void 0===n?void 0:n.size),a=t.available_size_ids.filter((t=>{var e;return(null===(e=i.sizes[t])||void 0===e?void 0:e.size)!==o})).map((t=>{var e,n;return(null===(e=i.sizes[t])||void 0===e?void 0:e.label)||(null===(n=i.sizes[t])||void 0===n?void 0:n.size)}));throw new Zf(o,a)}}async getColorwaySizeAssetFromSku(t){const e=await this.getColorwaySizeAssets(null,[t]);if(!(null==e?void 0:e.size))throw new Xf;return Array.from(e.values())[0]}async getColorwaySizeAssets(t,e){const n=[jh("brand_id","==",this.brandId)];t&&n.push(jh("style_id","==",t)),(null==e?void 0:e.length)>0&&n.push(jh("sku","in",e));try{const t=await this.firebase.getDocs("colorway_size_assets",n),e=new Map;return t.forEach((t=>{const n=t.data();e.set(n.id,n)})),e}catch(t){return rp(t)}}async requestColorwaySizeAssetFrames(t){if(!this.isLoggedIn)throw new Yf;await sp.Post(this.user,`/colorway-size-assets/${t}/frames`)}async getColorwaySizeAssetFrames(t){var e,n,r;const s=await this.user.getUserProfile(),i=(null===(r=null===(n=null===(e=null==s?void 0:s.vto)||void 0===e?void 0:e[this.brandId])||void 0===n?void 0:n[t])||void 0===r?void 0:r.frames)||[];if(!i.length)throw new Wf;if(!await(t=>{const e=new Image;return e.src=t,new Promise((t=>{e.onerror=()=>t(!1),e.onload=()=>t(!0)}))})(i[0]))throw new Wf;return i}}ip.avatarTimeout=12e4,ip.vtoTimeout=12e4;const op=(t,e="dev")=>("dev"!==e&&"development"!==e||console.warn("TfrShop is in development mode"),rl.getInstance().setEnv(e),new ip(t,new np));var ap,cp=Object.freeze({__proto__:null}),up=Object.freeze({__proto__:null});!function(t){t.NOT_CREATED="NOT_CREATED",t.CREATED="CREATED",t.PENDING="PENDING"}(ap||(ap={}));var hp=Object.freeze({__proto__:null,get AvatarState(){return ap}});const lp=ip.vtoTimeout;export{tp as Errors,lp as VTO_TIMEOUT_MS,op as initShop,cp as requests,up as responses,hp as types};
|
|
3166
|
+
const $f=c("authIdTokenMaxAge")||300;let Kf=null;function Hf(t=ct()){const e=rt(t,"auth");if(e.isInitialized())return e.getImmediate();const n=function(t,e){const n=rt(t,"auth");if(n.isInitialized()){const t=n.getImmediate();if(f(n.getOptions(),null!=e?e:{}))return t;fl(t,"already-initialized")}return n.initialize({options:e})}(t,{popupRedirectResolver:qf,persistence:[nf,Vd,jd]}),r=c("authTokenSyncURL");if(r){const t=(s=r,async t=>{const e=t&&await t.getIdTokenResult(),n=e&&((new Date).getTime()-Date.parse(e.issuedAtTime))/1e3;if(n&&n>$f)return;const r=null==e?void 0:e.token;Kf!==r&&(Kf=r,await fetch(s,{method:r?"POST":"DELETE",headers:r?{Authorization:`Bearer ${r}`}:{}}))});!function(t,e,n){I(t).beforeAuthStateChanged(e,n)}(n,t,(()=>t(n.currentUser))),function(t,e,n,r){I(t).onIdTokenChanged(e,n,r)}(n,(e=>t(e)))}var s;const i=a("auth");return i&&dd(n,`http://${i}`),n}var Gf;Gf="Browser",nt(new b("auth",((t,{options:e})=>{const n=t.getProvider("app").getImmediate(),r=t.getProvider("heartbeat"),{apiKey:s,authDomain:i}=n.options;return((t,n)=>{ml(s&&!s.includes(":"),"invalid-api-key",{appName:t.name}),ml(!(null==i?void 0:i.includes(":")),"argument-error",{appName:t.name});const r={apiKey:s,authDomain:i,clientPlatform:Gf,apiHost:"identitytoolkit.googleapis.com",tokenApiHost:"securetoken.googleapis.com",apiScheme:"https",sdkClientVersion:ad(Gf)},o=new ud(t,n,r);return function(t,e){const n=(null==e?void 0:e.persistence)||[],r=(Array.isArray(n)?n:[n]).map(Il);(null==e?void 0:e.errorMap)&&t._updateErrorMap(e.errorMap),t._initializeWithPersistence(r,null==e?void 0:e.popupRedirectResolver)}(o,e),o})(n,r)}),"PUBLIC").setInstantiationMode("EXPLICIT").setInstanceCreatedCallback(((t,e,n)=>{t.getProvider("auth-internal").initialize()}))),nt(new b("auth-internal",(t=>(t=>new zf(t))(hd(t.getProvider("auth").getImmediate()))),"PRIVATE").setInstantiationMode("EXPLICIT")),ut(jf,Bf,function(t){switch(t){case"Node":return"node";case"ReactNative":return"rn";case"Worker":return"webworker";case"Cordova":return"cordova";default:return}}(Gf)),ut(jf,Bf,"esm2017");class Wf extends Error{constructor(){super("Avatar not created"),this.name="AvatarNotCreatedError"}}class Qf extends Error{constructor(){super("no frames found"),this.name="NoFramesFoundError"}}class Yf extends Error{constructor(){super("request timeout"),this.name="RequestTimeoutError"}}class Xf extends Error{constructor(){super("user not logged in"),this.name="UserNotLoggedInError"}}class Jf extends Error{constructor(){super("no colorway size assets found"),this.name="NoColorwaySizeAssetsFoundError"}}class Zf extends Error{constructor(){super("no styles found"),this.name="NoStylesFoundError"}}class tp extends Error{constructor(t,e){super("recommended available sizes error"),this.name="RecommendedAvailableSizesError",this.recommended_size=t,this.available_sizes=e}}const ep="avatar not created";var np=Object.freeze({__proto__:null,AvatarNotCreatedError:Wf,NoFramesFoundError:Qf,RequestTimeoutError:Yf,UserNotLoggedInError:Xf,NoColorwaySizeAssetsFoundError:Jf,NoStylesFoundError:Zf,RecommendedAvailableSizesError:tp,AvatarNotCreated:ep});class rp{constructor(t,e){this.firestore=t,this.auth=Hf(e),this.auth.setPersistence(Vd)}get id(){var t;return null===(t=this.user)||void 0===t?void 0:t.uid}onInit(){return new Promise((t=>{const e=this.auth.onAuthStateChanged((n=>{this.setUser(n),t(Boolean(n)),e()}))}))}setUser(t){this.user=t}async getToken(){var t;if(!(null===(t=this.user)||void 0===t?void 0:t.uid))throw new Xf;return await this.user.getIdToken()}async getUserProfile(){var t;if(!(null===(t=this.user)||void 0===t?void 0:t.uid))throw new Xf;const e=await Jh(function(t,e,...n){if(t=I(t),1===arguments.length&&(e=Ys.R()),Xu("doc","path",e),t instanceof sh){const r=ni.fromString(e,...n);return Ju(r),new oh(t,null,new ii(r))}{if(!(t instanceof oh||t instanceof ch))throw new Vs(Fs.INVALID_ARGUMENT,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");const r=t._path.child(ni.fromString(e,...n));return Ju(r),new oh(t.firestore,t instanceof ch?t.converter:null,new ii(r))}}(this.firestore,"users",this.id));return e.data()}watchUserProfileForChanges(t,e){let n;const r=Vh(uh(this.firestore,"users"),jh(Th(),"==",this.id)),s=setTimeout((()=>n()),e);return new Promise((e=>{n=el(r,(r=>{t(r)&&(clearTimeout(s),n(),e(r.docs[0].data()))}))}))}async login(t,e){this.auth.currentUser&&await this.auth.signOut();const n=await Md(this.auth,t,e);this.setUser(n.user)}async logout(){await this.auth.signOut(),this.setUser(null)}async sendPasswordResetEmail(t){await Ld(this.auth,t)}async confirmPasswordReset(t,e){await Pd(this.auth,t,e)}}class sp{constructor(){this.promisefyOnSnapshot=(t,e)=>{let n;return{promise:new Promise((r=>{n=el(t,(t=>{r(t),e&&n()}))})),unsubscribe:()=>n()}};const t=at(rl.getInstance().firebase);this.firestore=yh(t),this.user=new rp(this.firestore,t)}onInit(){return this.user.onInit()}query(t,e,n=!0){const r=Vh(uh(this.firestore,t),e);return this.promisefyOnSnapshot(r,n)}getDocs(t,e){return tl(Vh(uh(this.firestore,t),...e))}}const ip=t=>{if(t.code===hl)throw new Error("account has been disabled");throw new Error(t.message)};class op{static get endpoint(){return rl.getInstance().api.url}static async Fetch({user:t,endpointPath:e,method:n,body:r,useToken:s=!0}){const i=this.getUrl(e,s),o={method:n,headers:await this.getHeaders(t,s),credentials:"include"};r&&(o.body=JSON.stringify(r));const a=await fetch(i,o);if(a.ok)return a;if(500===a.status)throw new Error(a.statusText);const c=await a.json();return Promise.reject(c)}static getUrl(t,e){return e?`${this.endpoint}/v1${t}`:this.endpoint+t}static async getHeaders(t,e){if(!e)return{"Content-Type":"application/json"};return{"Content-Type":"application/json",Authorization:`Bearer ${await t.getToken()}`}}static Get(t,e,n){return this.Fetch({user:t,endpointPath:e,method:"GET",body:null,useToken:n})}static Post(t,e,n=null,r){return this.Fetch({user:t,endpointPath:e,method:"POST",body:n,useToken:r})}static Put(t,e,n,r){return this.Fetch({user:t,endpointPath:e,method:"PUT",body:n,useToken:r})}static Patch(t,e,n,r){return this.Fetch({user:t,endpointPath:e,method:"PATCH",body:n,useToken:r})}static Delete(t,e,n,r){return this.Fetch({user:t,endpointPath:e,method:"DELETE",body:n,useToken:r})}}class ap{constructor(t,e){this.brandId=t,this.firebase=e;const n=rl.getInstance().config;ap.avatarTimeout=n.avatarTimeout?Number(n.avatarTimeout):12e4,ap.vtoTimeout=n.vtoTimeout?Number(n.vtoTimeout):12e4}get user(){return this.firebase.user}get isLoggedIn(){return!this.firebase||Boolean(this.user.id)}onInit(){return this.firebase.onInit()}async tryOn(t){if(!this.isLoggedIn)throw new Xf;try{return await this.getColorwaySizeAssetFrames(t)}catch(e){if(!(e instanceof Qf))throw e;return this.requestThenGetColorwaySizeAssetFrames(t)}}async awaitAvatarCreated(){if(!this.isLoggedIn)throw new Xf;const{promise:t,unsubscribe:e}=this.firebase.query("users",jh(Th(),"==",this.user.id)),n=setTimeout((()=>{throw e(),new Yf}),ap.avatarTimeout),r=await t;clearTimeout(n);return"CREATED"===r.docs[0].data().avatar_status}async getRecommendedSizes(t){if(!this.isLoggedIn)throw new Xf;try{const e=await op.Get(this.user,`/styles/${t}/recommendation`);return await e.json()}catch(t){if((null==t?void 0:t.error)===ep)throw new Wf;throw t}}async getStyles(t,e){const n=[jh("brand_id","==",this.brandId)];(null==t?void 0:t.length)>0&&n.push(jh("id","in",t)),(null==e?void 0:e.length)>0&&n.push(jh("brand_style_id","in",e));try{const t=await this.firebase.getDocs("styles",n),e=new Map;return t.forEach((t=>{const n=t.data();e.set(n.id,n)})),e}catch(t){return ip(t)}}async submitTelephoneNumber(t){const e=t.replace(/[^\+0-9]/g,""),n=await op.Post(this.user,"/ios-app-link",{phone_number:e},!1);console.log(n)}async awaitColorwaySizeAssetFrames(t){var e,n,r,s;if(!this.isLoggedIn)throw new Xf;const i=await this.user.watchUserProfileForChanges((e=>{var n,r,s;return Boolean(null===(s=null===(r=null===(n=e.docs[0].data())||void 0===n?void 0:n.vto)||void 0===r?void 0:r[this.brandId])||void 0===s?void 0:s[t])}),ap.vtoTimeout);if(!(null===(s=null===(r=null===(n=null===(e=null==i?void 0:i.vto)||void 0===e?void 0:e[this.brandId])||void 0===n?void 0:n[t])||void 0===r?void 0:r.frames)||void 0===s?void 0:s.length))throw new Qf;return i.vto[this.brandId][t].frames}async requestThenGetColorwaySizeAssetFrames(t){var e,n;const[r,s]=await(i=this.getColorwaySizeAssetFromSku(t),i.then((t=>[null,t])).catch((t=>[t])));var i;if(r)throw r;try{return await this.requestColorwaySizeAssetFrames(s.id),this.awaitColorwaySizeAssetFrames(t)}catch(r){if((null==r?void 0:r.error)===ep)throw new Wf;if(!r.recommended_size_id)throw new Error(r);const t=r,i=(await this.getStyles([s.style_id],null)).get(s.style_id);if(!(null==i?void 0:i.sizes))throw new Zf;const o=(null===(e=i.sizes[t.recommended_size_id])||void 0===e?void 0:e.label)||(null===(n=i.sizes[t.recommended_size_id])||void 0===n?void 0:n.size),a=t.available_size_ids.filter((t=>{var e;return(null===(e=i.sizes[t])||void 0===e?void 0:e.size)!==o})).map((t=>{var e,n;return(null===(e=i.sizes[t])||void 0===e?void 0:e.label)||(null===(n=i.sizes[t])||void 0===n?void 0:n.size)}));throw new tp(o,a)}}async getColorwaySizeAssetFromSku(t){const e=await this.getColorwaySizeAssets(null,[t]);if(!(null==e?void 0:e.size))throw new Jf;return Array.from(e.values())[0]}async getColorwaySizeAssets(t,e){const n=[jh("brand_id","==",this.brandId)];t&&n.push(jh("style_id","==",t)),(null==e?void 0:e.length)>0&&n.push(jh("sku","in",e));try{const t=await this.firebase.getDocs("colorway_size_assets",n),e=new Map;return t.forEach((t=>{const n=t.data();e.set(n.id,n)})),e}catch(t){return ip(t)}}async requestColorwaySizeAssetFrames(t){if(!this.isLoggedIn)throw new Xf;await op.Post(this.user,`/colorway-size-assets/${t}/frames`)}async getColorwaySizeAssetFrames(t){var e,n,r;const s=await this.user.getUserProfile(),i=(null===(r=null===(n=null===(e=null==s?void 0:s.vto)||void 0===e?void 0:e[this.brandId])||void 0===n?void 0:n[t])||void 0===r?void 0:r.frames)||[];if(!i.length)throw new Qf;if(!await(t=>{const e=new Image;return e.src=t,new Promise((t=>{e.onerror=()=>t(!1),e.onload=()=>t(!0)}))})(i[0]))throw new Qf;return i}}ap.avatarTimeout=12e4,ap.vtoTimeout=12e4;const cp=(t,e="dev")=>("dev"!==e&&"development"!==e||console.warn("TfrShop is in development mode"),rl.getInstance().setEnv(e),new ap(t,new sp));var up,hp=Object.freeze({__proto__:null}),lp=Object.freeze({__proto__:null});!function(t){t.NOT_CREATED="NOT_CREATED",t.CREATED="CREATED",t.PENDING="PENDING"}(up||(up={}));var dp=Object.freeze({__proto__:null,get AvatarState(){return up}});const fp=ap.vtoTimeout;export{np as Errors,fp as VTO_TIMEOUT_MS,cp as initShop,hp as requests,lp as responses,dp as types};
|
|
3167
3167
|
//# sourceMappingURL=index.min.js.map
|