@thefittingroom/sdk 1.1.4 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * thefittingroom v1.1.3 (2024-05-16T02:13:08.479Z)
2
+ * thefittingroom v1.1.6 (2024-05-16T02:58:10.847Z)
3
3
  * Copyright 2022-present, TheFittingRoom, Inc. All rights reserved.
4
4
  */
5
5
  var t=Object.freeze({__proto__:null}),e=Object.freeze({__proto__:null});
@@ -3164,5 +3164,5 @@ class Wf{constructor(t){this.auth=t,this.internalListeners=new Map}getUid(){var
3164
3164
  * See the License for the specific language governing permissions and
3165
3165
  * limitations under the License.
3166
3166
  */
3167
- const zf=h("authIdTokenMaxAge")||300;let Gf=null;function $f(t=ht()){const e=it(t,"auth");if(e.isInitialized())return e.getImmediate();const n=function(t,e){const n=it(t,"auth");if(n.isInitialized()){const t=n.getImmediate();if(g(n.getOptions(),null!=e?e:{}))return t;gl(t,"already-initialized")}return n.initialize({options:e})}(t,{popupRedirectResolver:Hf,persistence:[rf,jd,qd]}),s=h("authTokenSyncURL");if(s){const t=(r=s,async t=>{const e=t&&await t.getIdTokenResult(),n=e&&((new Date).getTime()-Date.parse(e.issuedAtTime))/1e3;if(n&&n>zf)return;const s=null==e?void 0:e.token;Gf!==s&&(Gf=s,await fetch(r,{method:s?"POST":"DELETE",headers:s?{Authorization:`Bearer ${s}`}:{}}))});!function(t,e,n){I(t).beforeAuthStateChanged(e,n)}(n,t,(()=>t(n.currentUser))),function(t,e,n,s){I(t).onIdTokenChanged(e,n,s)}(n,(e=>t(e)))}var r;const i=u("auth");return i&&pd(n,`http://${i}`),n}var Qf;Qf="Browser",rt(new E("auth",((t,{options:e})=>{const n=t.getProvider("app").getImmediate(),s=t.getProvider("heartbeat"),{apiKey:r,authDomain:i}=n.options;return((t,n)=>{vl(r&&!r.includes(":"),"invalid-api-key",{appName:t.name}),vl(!(null==i?void 0:i.includes(":")),"argument-error",{appName:t.name});const s={apiKey:r,authDomain:i,clientPlatform:Qf,apiHost:"identitytoolkit.googleapis.com",tokenApiHost:"securetoken.googleapis.com",apiScheme:"https",sdkClientVersion:ud(Qf)},o=new ld(t,n,s);return function(t,e){const n=(null==e?void 0:e.persistence)||[],s=(Array.isArray(n)?n:[n]).map(Il);(null==e?void 0:e.errorMap)&&t._updateErrorMap(e.errorMap),t._initializeWithPersistence(s,null==e?void 0:e.popupRedirectResolver)}(o,e),o})(n,s)}),"PUBLIC").setInstantiationMode("EXPLICIT").setInstanceCreatedCallback(((t,e,n)=>{t.getProvider("auth-internal").initialize()}))),rt(new E("auth-internal",(t=>(t=>new Wf(t))(dd(t.getProvider("auth").getImmediate()))),"PRIVATE").setInstantiationMode("EXPLICIT")),lt(qf,Kf,function(t){switch(t){case"Node":return"node";case"ReactNative":return"rn";case"Worker":return"webworker";case"Cordova":return"cordova";default:return}}(Qf)),lt(qf,Kf,"esm2017");class Jf extends Error{constructor(){super("Avatar not created"),this.name="AvatarNotCreatedError"}}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"}}const Zf="avatar not created";var tp=Object.freeze({__proto__:null,AvatarNotCreatedError:Jf,UserNotLoggedInError:Yf,NoColorwaySizeAssetsFoundError:Xf,AvatarNotCreated:Zf});class ep{constructor(t,e){this.firestore=t,this.brandUserId=null,this.auth=$f(e),this.auth.setPersistence(jd)}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}setBrandUserId(t){this.brandUserId=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;return(await tl(dh(this.firestore,"users",this.id))).data()}watchUserProfileForChanges(t){let e;const n=jh(lh(this.firestore,"users"),qh(new Sh("__name__"),"==",this.id));return e=sl(n,(e=>t(e.docs[0].data()))),()=>e()}async login(t,e){this.auth.currentUser&&await this.auth.signOut();const n=await Ud(this.auth,t,e);this.setUser(n.user)}async logout(){await this.auth.signOut(),this.setUser(null)}async sendPasswordResetEmail(t){await Md(this.auth,t)}async confirmPasswordReset(t,e){await xd(this.auth,t,e)}}class np{constructor(){this.promisefyOnSnapshot=(t,e)=>{let n;return{promise:new Promise((s=>{n=sl(t,(t=>{s(t),e&&n()}))})),unsubscribe:()=>n()}};const t=ut(il.getInstance().firebase);this.firestore=_h(t),this.user=new ep(this.firestore,t)}onInit(){return this.user.onInit()}query(t,e,n=!0){const s=jh(lh(this.firestore,t),e);return this.promisefyOnSnapshot(s,n)}getDocs(t,e){return nl(jh(lh(this.firestore,t),...e))}async getDoc(t,e){const n=dh(this.firestore,t,e),s=await tl(n);return s.exists()?s.data():null}}const sp=t=>{if(t.code===dl)throw new Error("account has been disabled");throw new Error(t.message)};var rp;!function(t){t.ACROSS_BACK="across_back",t.ACROSS_FRONT="across_front",t.ACROSS_SHOULDER="across_shoulder",t.ANKLE="ankle",t.ARMEYE="arm_eye",t.ARM_LENGTH_FROM_SHOULDER="arm_length_from_shoulder",t.BACK_CROTCH_LENGTH="back_crotch_length",t.BACK_NECK_TO_EBLOW="back_neck_to_elbow",t.BELOW_KNEE="below_knee",t.BICEP="bicep",t.BUST="bust",t.BUST_POINT_TO_BUST_POINT="bust_point_to_bust_point",t.CALF="calf",t.CB_NECK_TO_WAIST="cb_neck_to_waist",t.CB_NECK_TO_WRIST="cb_neck_to_wrist",t.CF_NECK_TO_WAIST="cf_neck_to_waist",t.ELBOW="elbow",t.FOREARM="forearm",t.FRONT_CROTCH_LENGTH="front_crotch_length",t.HIGH_HIP_PLACEMENT_FROM_WAIST="high_hip_placement",t.HIGH_HIP="high_hip",t.HSP_TO_ACROSS_BACK="hsp_to_across_back",t.HSP_TO_ACROSS_FRONT="hsp_to_across_front",t.HSP_TO_BUST_POINT="hsp_to_bust_point",t.HSP_TO_LOW_HIP_POSITION="hsp_to_low_hip_position",t.HSP_TO_WAIST_POSITION="hsp_to_waist_position",t.INSEAM="inseam",t.KNEE="knee",t.LOW_HIP="low_hip",t.LOW_HIP_PLACEMENT_FROM_WAIST="low_hip_placement",t.MID_NECK="mid_neck",t.NECK_AT_BASE="neck_base",t.SHOULDER_DROP="shoulder_drop",t.SHOULDER_TO_SHOULDER="shoulder_to_shoulder",t.SIDE_WAIST_TO_FLOOR="side_waist_to_floor",t.SIDE_WAIST_TO_KNEE="side_waist_to_knee",t.THIGH="thigh",t.TOTAL_RISE_LENGTH="total_rise_length",t.UNDER_BUST="under_bust",t.VERTICAL_TRUNK="vertical_trunk",t.WAIST="waist",t.WRIST="wrist"}(rp||(rp={}));const ip={[rp.ACROSS_BACK]:"Across back",[rp.ACROSS_FRONT]:"Across front",[rp.ACROSS_SHOULDER]:"Across shoulder",[rp.ANKLE]:"Ankle",[rp.ARMEYE]:"Armeye",[rp.ARM_LENGTH_FROM_SHOULDER]:"Arm length from shoulder",[rp.BACK_CROTCH_LENGTH]:"Back crotch length",[rp.BACK_NECK_TO_EBLOW]:"Back neck to eblow",[rp.BELOW_KNEE]:"Below knee",[rp.BICEP]:"Bicep",[rp.BUST]:"Chest/Bust",[rp.BUST_POINT_TO_BUST_POINT]:"Bust point to bust point",[rp.CALF]:"Calf",[rp.CB_NECK_TO_WAIST]:"Cb neck to waist",[rp.CB_NECK_TO_WRIST]:"Cb neck to wrist",[rp.CF_NECK_TO_WAIST]:"Cf neck to waist",[rp.ELBOW]:"Elbow",[rp.FOREARM]:"Forearm",[rp.FRONT_CROTCH_LENGTH]:"Front crotch length",[rp.HIGH_HIP_PLACEMENT_FROM_WAIST]:"High hip placement from waist",[rp.HIGH_HIP]:"High hip",[rp.HSP_TO_ACROSS_BACK]:"Hsp to across back",[rp.HSP_TO_ACROSS_FRONT]:"Hsp to across front",[rp.HSP_TO_BUST_POINT]:"Hsp to bust point",[rp.HSP_TO_LOW_HIP_POSITION]:"Hsp to low hip position",[rp.HSP_TO_WAIST_POSITION]:"Hsp to waist position",[rp.INSEAM]:"Inseam",[rp.KNEE]:"Knee",[rp.LOW_HIP]:"Low hip",[rp.LOW_HIP_PLACEMENT_FROM_WAIST]:"Low hip placement from waist",[rp.MID_NECK]:"Mid neck",[rp.NECK_AT_BASE]:"Neck at base",[rp.SHOULDER_DROP]:"Shoulder drop",[rp.SHOULDER_TO_SHOULDER]:"Shoulder to shoulder",[rp.SIDE_WAIST_TO_FLOOR]:"Side waist to floor",[rp.SIDE_WAIST_TO_KNEE]:"Side waist to knee",[rp.THIGH]:"Thigh",[rp.TOTAL_RISE_LENGTH]:"Total rise length",[rp.UNDER_BUST]:"Under bust",[rp.VERTICAL_TRUNK]:"Vertical trunk",[rp.WAIST]:"Waist",[rp.WRIST]:"Wrist"};var op;!function(t){t.BLOUSES="blouses",t.COATS="coats",t.DRESSES="dresses",t.JACKETS="jackets",t.PANTS="pants",t.PUFFERS_AND_PARKAS="puffer_and_parkas",t.SHORTS="shorts",t.SKIRTS="skirts",t.SWEATERS="sweaters",t.T_SHIRTS_AND_TANKS="t_shirts_and_tanks"}(op||(op={}));const ap={[op.BLOUSES]:[rp.BUST,rp.ACROSS_SHOULDER,rp.WAIST,rp.LOW_HIP,rp.HIGH_HIP],[op.COATS]:[rp.BUST,rp.ACROSS_SHOULDER,rp.WAIST,rp.LOW_HIP,rp.HIGH_HIP],[op.DRESSES]:[rp.LOW_HIP,rp.BUST,rp.ACROSS_SHOULDER,rp.WAIST],[op.JACKETS]:[rp.BUST,rp.ACROSS_SHOULDER,rp.WAIST,rp.LOW_HIP,rp.HIGH_HIP],[op.PANTS]:[rp.LOW_HIP,rp.WAIST,rp.THIGH,rp.INSEAM],[op.PUFFERS_AND_PARKAS]:[rp.BUST,rp.ACROSS_SHOULDER,rp.WAIST,rp.LOW_HIP,rp.HIGH_HIP],[op.SHORTS]:[rp.LOW_HIP,rp.WAIST,rp.THIGH,rp.INSEAM],[op.SKIRTS]:[rp.LOW_HIP,rp.WAIST],[op.SWEATERS]:[rp.BUST,rp.ACROSS_SHOULDER,rp.WAIST,rp.LOW_HIP,rp.HIGH_HIP],[op.T_SHIRTS_AND_TANKS]:[rp.BUST,rp.ACROSS_SHOULDER,rp.WAIST,rp.LOW_HIP,rp.HIGH_HIP]},cp={activewear:"Active Wear",dresses:"Dresses",jackets_and_coats:"Jackets and Coats",jeans:"Jeans",jumpsuits_and_rompers:"Jumpsuits and Rompers",pants_and_shorts:"Pants and Shorts",skirts:"Skirts",suits_and_tailoring:"Suits and Tailoring",sweaters:"Sweaters",tops:"Tops"},up={a_line:"A Line",a_line_flared:"A Line Flared",blazers:"Blazers",bodycon:"Bodycon",bodysuits:"Bodysuits",boiler_suits:"Boiler Suits",bootcut:"Bootcut",cardigans:"Cardigans",cigarette:"Cigarette",corsets_and_bustiers:"Corsets and Bustiers",crewnecks:"Crewnecks",culottes:"Culottes",denim:"Denim",denim_jackets:"Denim Jackets",denim_shorts:"Denim Shorts",fit_and_flare:"Fit and Flare",flared:"Flared",hoodies_and_zipups:"Hoodies and Zipups",joggers:"Joggers",jumpsuits:"Jumpsuits",knit:"Knit",leggings:"Leggings",mom:"Mom",overalls:"Overalls",parkas:"Parkas",peacoats:"Peacoats",pencil:"Pencil",pleated:"Pleated",polos:"Polos",puffer_jackets:"Puffer Jackets",raincoats:"Raincoats",relaxed:"Relaxed",rompers:"Rompers",shackets:"Shackets",shirt:"Shirt",shirts_and_blouses:"Shirts and Blouses",skater:"Skater",skinny:"Skinny",slim:"Slim",slip:"Slip",sports_bras:"Sports Bras",straight:"Straight",suit_jackets:"Suit Jackets",suit_skirts:"Suit Skirts",suit_trousers:"Suit Trousers",suit_vests:"Suit Vests",sweatshirts:"Sweatshirts",t_shirts:"T-Shirts",tank_tops_and_camisoles:"Tank Tops and Camisoles",tapered:"Tapered",trench_coats:"Trench Coats",trousers:"Trousers",turtlenecks:"Turtleneck",unitards:"Unitards",v_necks:"V-Necks",wide_leg:"Wide Leg",wrap:"Wrap"},hp={activewear:{leggings:op.PANTS,joggers:op.PANTS,sweatshirts:op.SWEATERS},dresses:{a_line:op.DRESSES,bodycon:op.DRESSES,fit_and_flare:op.DRESSES,knit:op.DRESSES,shirt:op.DRESSES,slip:op.DRESSES,straight:op.DRESSES,wrap:op.DRESSES},jackets_and_coats:{denim_jackets:op.JACKETS,parkas:op.PUFFERS_AND_PARKAS,peacoats:op.COATS,puffer_jackets:op.PUFFERS_AND_PARKAS,raincoats:op.COATS,rompers:op.COATS,shackets:op.JACKETS,trench_coats:op.COATS},jeans:{bootcut:op.PANTS,flared:op.PANTS,mom:op.PANTS,relaxed:op.PANTS,skinny:op.PANTS,slim:op.PANTS,straight:op.PANTS,tapered:op.PANTS,wide_leg:op.PANTS},jumpsuits_and_rompers:{boiler_suits:op.DRESSES,denim:op.DRESSES,jumpsuits:op.DRESSES,overalls:op.DRESSES,rompers:op.DRESSES,unitards:op.DRESSES},pants_and_shorts:{cigarette:op.PANTS,culottes:op.SHORTS,denim_shorts:op.SHORTS,flared:op.PANTS,joggers:op.PANTS,leggings:op.PANTS,skinny:op.PANTS,wide_leg:op.PANTS},skirts:{a_line_flared:op.SKIRTS,denim:op.SKIRTS,knit:op.SKIRTS,pencil:op.SKIRTS,pleated:op.SKIRTS,skater:op.SKIRTS,slip:op.SKIRTS,wrap:op.SKIRTS},suits_and_tailoring:{blazers:op.JACKETS,suit_jackets:op.JACKETS,suit_skirts:op.SKIRTS,suit_trousers:op.PANTS,suit_vests:op.SWEATERS,trousers:op.PANTS},sweaters:{cardigans:op.SWEATERS,crewnecks:op.SWEATERS,hoodies_and_zipups:op.SWEATERS,sweatshirts:op.SWEATERS,turtlenecks:op.SWEATERS,v_necks:op.SWEATERS},tops:{bodysuits:op.BLOUSES,corsets_and_bustiers:op.BLOUSES,polos:op.T_SHIRTS_AND_TANKS,shirts_and_blouses:op.BLOUSES,t_shirts:op.T_SHIRTS_AND_TANKS,tank_tops_and_camisoles:op.T_SHIRTS_AND_TANKS}};var lp;!function(t){t.TOO_TIGHT="too_tight",t.TIGHT="tight",t.SLIGHTLY_TIGHT="slightly_tight",t.PERFECT_FIT="perfect_fit",t.SLIGHTLY_LOOSE="slightly_loose",t.LOOSE="loose",t.OVERSIZED="oversized"}(lp||(lp={}));const dp={[lp.TOO_TIGHT]:"Too Tight",[lp.TIGHT]:"Tight",[lp.SLIGHTLY_TIGHT]:"Slightly Tight",[lp.PERFECT_FIT]:"Perfect Fit",[lp.SLIGHTLY_LOOSE]:"Slightly Loose",[lp.LOOSE]:"Loose",[lp.OVERSIZED]:"Oversized"};class fp{static get endpoint(){return il.getInstance().api.url}static async Fetch({user:t,endpointPath:e,method:n,body:s,useToken:r=!0}){const i=this.getUrl(e,r),o={method:n,headers:await this.getHeaders(t,r),credentials:"include"};s&&(o.body=JSON.stringify(s));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,s){return this.Fetch({user:t,endpointPath:e,method:"POST",body:n,useToken:s})}static Put(t,e,n,s){return this.Fetch({user:t,endpointPath:e,method:"PUT",body:n,useToken:s})}static Patch(t,e,n,s){return this.Fetch({user:t,endpointPath:e,method:"PATCH",body:n,useToken:s})}static Delete(t,e,n,s){return this.Fetch({user:t,endpointPath:e,method:"DELETE",body:n,useToken:s})}}class pp{constructor(t,e){this.brandId=t,this.firebase=e}get user(){return this.firebase.user}get isLoggedIn(){return!this.firebase||Boolean(this.user.id)}onInit(){return this.firebase.onInit()}async getRecommendedSizes(t){var e,n;if(!this.isLoggedIn)throw new Yf;try{const s=await fp.Get(this.user,`/styles/${t}/recommendation`),r=await s.json();return(null===(e=null==r?void 0:r.fits)||void 0===e?void 0:e.length)&&(null===(n=null==r?void 0:r.recommended_size)||void 0===n?void 0:n.id)?r:null}catch(t){if((null==t?void 0:t.error)===Zf)throw new Jf;throw t}}async submitTelephoneNumber(t){const e=t.replace(/[^\+0-9]/g,""),n=await fp.Post(this.user,"/ios-app-link",{phone_number:e},!1);console.log(n)}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 getMeasurementLocationsFromSku(t){var e;const n=await this.getColorwaySizeAssetFromSku(t),s=await this.getStyleCategory(n.style_id),r=await this.getGetTaxonomy(s.style_garment_category_id),i=(null===(e=hp[r.style_category])||void 0===e?void 0:e[r.garment_category])||null;return i?ap[i].map((t=>ip[t])):null}async getColorwaySizeAssets(t,e){const n=[qh("brand_id","==",this.brandId)];t&&n.push(qh("style_id","==",t)),(null==e?void 0:e.length)>0&&n.push(qh("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 sp(t)}}async getStyleCategory(t){try{return await this.firebase.getDoc("styles",String(t))}catch(t){return sp(t)}}async getGetTaxonomy(t){try{return await this.firebase.getDoc("style_garment_categories",String(t))}catch(t){return sp(t)}}}const gp=(t,e="dev")=>("dev"!==e&&"development"!==e||console.warn("TfrShop is in development mode"),il.getInstance().setEnv(e),new pp(t,new np));var mp;!function(t){t.NOT_CREATED="NOT_CREATED",t.CREATED="CREATED",t.PENDING="PENDING"}(mp||(mp={}));var yp=Object.freeze({__proto__:null,get AvatarState(){return mp},get MeasurementLocation(){return rp},MeasurementLocationName:ip,get Classification(){return op},ClassificationLocations:ap,CategoryNames:cp,Categories:["activewear","dresses","jackets_and_coats","jeans","jumpsuits_and_rompers","pants_and_shorts","skirts","suits_and_tailoring","sweaters","tops"],SubcategoryNames:up,Taxonomy:hp,get Fit(){return lp},FitNames:dp});export{tp as Errors,gp as initShop,t as requests,e as responses,yp as types};
3167
+ const zf=h("authIdTokenMaxAge")||300;let Gf=null;function $f(t=ht()){const e=it(t,"auth");if(e.isInitialized())return e.getImmediate();const n=function(t,e){const n=it(t,"auth");if(n.isInitialized()){const t=n.getImmediate();if(g(n.getOptions(),null!=e?e:{}))return t;gl(t,"already-initialized")}return n.initialize({options:e})}(t,{popupRedirectResolver:Hf,persistence:[rf,jd,qd]}),s=h("authTokenSyncURL");if(s){const t=(r=s,async t=>{const e=t&&await t.getIdTokenResult(),n=e&&((new Date).getTime()-Date.parse(e.issuedAtTime))/1e3;if(n&&n>zf)return;const s=null==e?void 0:e.token;Gf!==s&&(Gf=s,await fetch(r,{method:s?"POST":"DELETE",headers:s?{Authorization:`Bearer ${s}`}:{}}))});!function(t,e,n){I(t).beforeAuthStateChanged(e,n)}(n,t,(()=>t(n.currentUser))),function(t,e,n,s){I(t).onIdTokenChanged(e,n,s)}(n,(e=>t(e)))}var r;const i=u("auth");return i&&pd(n,`http://${i}`),n}var Qf;Qf="Browser",rt(new E("auth",((t,{options:e})=>{const n=t.getProvider("app").getImmediate(),s=t.getProvider("heartbeat"),{apiKey:r,authDomain:i}=n.options;return((t,n)=>{vl(r&&!r.includes(":"),"invalid-api-key",{appName:t.name}),vl(!(null==i?void 0:i.includes(":")),"argument-error",{appName:t.name});const s={apiKey:r,authDomain:i,clientPlatform:Qf,apiHost:"identitytoolkit.googleapis.com",tokenApiHost:"securetoken.googleapis.com",apiScheme:"https",sdkClientVersion:ud(Qf)},o=new ld(t,n,s);return function(t,e){const n=(null==e?void 0:e.persistence)||[],s=(Array.isArray(n)?n:[n]).map(Il);(null==e?void 0:e.errorMap)&&t._updateErrorMap(e.errorMap),t._initializeWithPersistence(s,null==e?void 0:e.popupRedirectResolver)}(o,e),o})(n,s)}),"PUBLIC").setInstantiationMode("EXPLICIT").setInstanceCreatedCallback(((t,e,n)=>{t.getProvider("auth-internal").initialize()}))),rt(new E("auth-internal",(t=>(t=>new Wf(t))(dd(t.getProvider("auth").getImmediate()))),"PRIVATE").setInstantiationMode("EXPLICIT")),lt(qf,Kf,function(t){switch(t){case"Node":return"node";case"ReactNative":return"rn";case"Worker":return"webworker";case"Cordova":return"cordova";default:return}}(Qf)),lt(qf,Kf,"esm2017");class Jf extends Error{constructor(){super("Avatar not created"),this.name="AvatarNotCreatedError"}}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"}}const Zf="avatar not created";var tp=Object.freeze({__proto__:null,AvatarNotCreatedError:Jf,UserNotLoggedInError:Yf,NoColorwaySizeAssetsFoundError:Xf,AvatarNotCreated:Zf});class ep{constructor(t,e){this.firestore=t,this.brandUserId=null,this.auth=$f(e),this.auth.setPersistence(jd)}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}setBrandUserId(t){this.brandUserId=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;return(await tl(dh(this.firestore,"users",this.id))).data()}watchUserProfileForChanges(t){let e;const n=jh(lh(this.firestore,"users"),qh(new Sh("__name__"),"==",this.id));return e=sl(n,(e=>t(e.docs[0].data()))),()=>e()}async login(t,e){this.auth.currentUser&&await this.auth.signOut();const n=await Ud(this.auth,t,e);this.setUser(n.user)}async logout(){await this.auth.signOut(),this.setUser(null)}async sendPasswordResetEmail(t){await Md(this.auth,t)}async confirmPasswordReset(t,e){await xd(this.auth,t,e)}}class np{constructor(){this.promisefyOnSnapshot=(t,e)=>{let n;return{promise:new Promise((s=>{n=sl(t,(t=>{s(t),e&&n()}))})),unsubscribe:()=>n()}};const t=ut(il.getInstance().firebase);this.firestore=_h(t),this.user=new ep(this.firestore,t)}onInit(){return this.user.onInit()}query(t,e,n=!0){const s=jh(lh(this.firestore,t),e);return this.promisefyOnSnapshot(s,n)}getDocs(t,e){return nl(jh(lh(this.firestore,t),...e))}async getDoc(t,e){const n=dh(this.firestore,t,e),s=await tl(n);return s.exists()?s.data():null}}const sp=t=>{if(t.code===dl)throw new Error("account has been disabled");throw new Error(t.message)};var rp;!function(t){t.ACROSS_BACK="across_back",t.ACROSS_FRONT="across_front",t.ACROSS_SHOULDER="across_shoulder",t.ANKLE="ankle",t.ARMEYE="arm_eye",t.ARM_LENGTH_FROM_SHOULDER="arm_length_from_shoulder",t.BACK_CROTCH_LENGTH="back_crotch_length",t.BACK_NECK_TO_EBLOW="back_neck_to_elbow",t.BELOW_KNEE="below_knee",t.BICEP="bicep",t.BUST="bust",t.BUST_POINT_TO_BUST_POINT="bust_point_to_bust_point",t.CALF="calf",t.CB_NECK_TO_WAIST="cb_neck_to_waist",t.CB_NECK_TO_WRIST="cb_neck_to_wrist",t.CF_NECK_TO_WAIST="cf_neck_to_waist",t.ELBOW="elbow",t.FOREARM="forearm",t.FRONT_CROTCH_LENGTH="front_crotch_length",t.HIGH_HIP_PLACEMENT_FROM_WAIST="high_hip_placement",t.HIGH_HIP="high_hip",t.HSP_TO_ACROSS_BACK="hsp_to_across_back",t.HSP_TO_ACROSS_FRONT="hsp_to_across_front",t.HSP_TO_BUST_POINT="hsp_to_bust_point",t.HSP_TO_LOW_HIP_POSITION="hsp_to_low_hip_position",t.HSP_TO_WAIST_POSITION="hsp_to_waist_position",t.INSEAM="inseam",t.KNEE="knee",t.LOW_HIP="low_hip",t.LOW_HIP_PLACEMENT_FROM_WAIST="low_hip_placement",t.MID_NECK="mid_neck",t.NECK_AT_BASE="neck_base",t.SHOULDER_DROP="shoulder_drop",t.SHOULDER_TO_SHOULDER="shoulder_to_shoulder",t.SIDE_WAIST_TO_FLOOR="side_waist_to_floor",t.SIDE_WAIST_TO_KNEE="side_waist_to_knee",t.THIGH="thigh",t.TOTAL_RISE_LENGTH="total_rise_length",t.UNDER_BUST="under_bust",t.VERTICAL_TRUNK="vertical_trunk",t.WAIST="waist",t.WRIST="wrist"}(rp||(rp={}));const ip={[rp.ACROSS_BACK]:"Across back",[rp.ACROSS_FRONT]:"Across front",[rp.ACROSS_SHOULDER]:"Across shoulder",[rp.ANKLE]:"Ankle",[rp.ARMEYE]:"Armeye",[rp.ARM_LENGTH_FROM_SHOULDER]:"Arm length from shoulder",[rp.BACK_CROTCH_LENGTH]:"Back crotch length",[rp.BACK_NECK_TO_EBLOW]:"Back neck to eblow",[rp.BELOW_KNEE]:"Below knee",[rp.BICEP]:"Bicep",[rp.BUST]:"Chest/Bust",[rp.BUST_POINT_TO_BUST_POINT]:"Bust point to bust point",[rp.CALF]:"Calf",[rp.CB_NECK_TO_WAIST]:"Cb neck to waist",[rp.CB_NECK_TO_WRIST]:"Cb neck to wrist",[rp.CF_NECK_TO_WAIST]:"Cf neck to waist",[rp.ELBOW]:"Elbow",[rp.FOREARM]:"Forearm",[rp.FRONT_CROTCH_LENGTH]:"Front crotch length",[rp.HIGH_HIP_PLACEMENT_FROM_WAIST]:"High hip placement from waist",[rp.HIGH_HIP]:"High hip",[rp.HSP_TO_ACROSS_BACK]:"Hsp to across back",[rp.HSP_TO_ACROSS_FRONT]:"Hsp to across front",[rp.HSP_TO_BUST_POINT]:"Hsp to bust point",[rp.HSP_TO_LOW_HIP_POSITION]:"Hsp to low hip position",[rp.HSP_TO_WAIST_POSITION]:"Hsp to waist position",[rp.INSEAM]:"Inseam",[rp.KNEE]:"Knee",[rp.LOW_HIP]:"Low hip",[rp.LOW_HIP_PLACEMENT_FROM_WAIST]:"Low hip placement from waist",[rp.MID_NECK]:"Mid neck",[rp.NECK_AT_BASE]:"Neck at base",[rp.SHOULDER_DROP]:"Shoulder drop",[rp.SHOULDER_TO_SHOULDER]:"Shoulder to shoulder",[rp.SIDE_WAIST_TO_FLOOR]:"Side waist to floor",[rp.SIDE_WAIST_TO_KNEE]:"Side waist to knee",[rp.THIGH]:"Thigh",[rp.TOTAL_RISE_LENGTH]:"Total rise length",[rp.UNDER_BUST]:"Under bust",[rp.VERTICAL_TRUNK]:"Vertical trunk",[rp.WAIST]:"Waist",[rp.WRIST]:"Wrist"};var op;!function(t){t.BLOUSES="blouses",t.COATS="coats",t.DRESSES="dresses",t.JACKETS="jackets",t.PANTS="pants",t.PUFFERS_AND_PARKAS="puffer_and_parkas",t.SHORTS="shorts",t.SKIRTS="skirts",t.SWEATERS="sweaters",t.T_SHIRTS_AND_TANKS="t_shirts_and_tanks"}(op||(op={}));const ap={[op.BLOUSES]:[rp.BUST,rp.ACROSS_SHOULDER,rp.WAIST,rp.LOW_HIP,rp.HIGH_HIP],[op.COATS]:[rp.BUST,rp.ACROSS_SHOULDER,rp.WAIST,rp.LOW_HIP,rp.HIGH_HIP],[op.DRESSES]:[rp.LOW_HIP,rp.BUST,rp.ACROSS_SHOULDER,rp.WAIST],[op.JACKETS]:[rp.BUST,rp.ACROSS_SHOULDER,rp.WAIST,rp.LOW_HIP,rp.HIGH_HIP],[op.PANTS]:[rp.LOW_HIP,rp.WAIST,rp.THIGH,rp.INSEAM],[op.PUFFERS_AND_PARKAS]:[rp.BUST,rp.ACROSS_SHOULDER,rp.WAIST,rp.LOW_HIP,rp.HIGH_HIP],[op.SHORTS]:[rp.LOW_HIP,rp.WAIST,rp.THIGH,rp.INSEAM],[op.SKIRTS]:[rp.LOW_HIP,rp.WAIST],[op.SWEATERS]:[rp.BUST,rp.ACROSS_SHOULDER,rp.WAIST,rp.LOW_HIP,rp.HIGH_HIP],[op.T_SHIRTS_AND_TANKS]:[rp.BUST,rp.ACROSS_SHOULDER,rp.WAIST,rp.LOW_HIP,rp.HIGH_HIP]},cp={activewear:"Active Wear",dresses:"Dresses",jackets_and_coats:"Jackets and Coats",jeans:"Jeans",jumpsuits_and_rompers:"Jumpsuits and Rompers",pants_and_shorts:"Pants and Shorts",skirts:"Skirts",suits_and_tailoring:"Suits and Tailoring",sweaters:"Sweaters",tops:"Tops"},up={a_line:"A Line",a_line_flared:"A Line Flared",blazers:"Blazers",bodycon:"Bodycon",bodysuits:"Bodysuits",boiler_suits:"Boiler Suits",bootcut:"Bootcut",cardigans:"Cardigans",cigarette:"Cigarette",corsets_and_bustiers:"Corsets and Bustiers",crewnecks:"Crewnecks",culottes:"Culottes",denim:"Denim",denim_jackets:"Denim Jackets",denim_shorts:"Denim Shorts",fit_and_flare:"Fit and Flare",flared:"Flared",hoodies_and_zipups:"Hoodies and Zipups",joggers:"Joggers",jumpsuits:"Jumpsuits",knit:"Knit",leggings:"Leggings",mom:"Mom",overalls:"Overalls",parkas:"Parkas",peacoats:"Peacoats",pencil:"Pencil",pleated:"Pleated",polos:"Polos",puffer_jackets:"Puffer Jackets",raincoats:"Raincoats",relaxed:"Relaxed",rompers:"Rompers",shackets:"Shackets",shirt:"Shirt",shirts_and_blouses:"Shirts and Blouses",skater:"Skater",skinny:"Skinny",slim:"Slim",slip:"Slip",sports_bras:"Sports Bras",straight:"Straight",suit_jackets:"Suit Jackets",suit_skirts:"Suit Skirts",suit_trousers:"Suit Trousers",suit_vests:"Suit Vests",sweatshirts:"Sweatshirts",t_shirts:"T-Shirts",tank_tops_and_camisoles:"Tank Tops and Camisoles",tapered:"Tapered",trench_coats:"Trench Coats",trousers:"Trousers",turtlenecks:"Turtleneck",unitards:"Unitards",v_necks:"V-Necks",wide_leg:"Wide Leg",wrap:"Wrap"},hp={activewear:{leggings:op.PANTS,joggers:op.PANTS,sweatshirts:op.SWEATERS},dresses:{a_line:op.DRESSES,bodycon:op.DRESSES,fit_and_flare:op.DRESSES,knit:op.DRESSES,shirt:op.DRESSES,slip:op.DRESSES,straight:op.DRESSES,wrap:op.DRESSES},jackets_and_coats:{denim_jackets:op.JACKETS,parkas:op.PUFFERS_AND_PARKAS,peacoats:op.COATS,puffer_jackets:op.PUFFERS_AND_PARKAS,raincoats:op.COATS,rompers:op.COATS,shackets:op.JACKETS,trench_coats:op.COATS},jeans:{bootcut:op.PANTS,flared:op.PANTS,mom:op.PANTS,relaxed:op.PANTS,skinny:op.PANTS,slim:op.PANTS,straight:op.PANTS,tapered:op.PANTS,wide_leg:op.PANTS},jumpsuits_and_rompers:{boiler_suits:op.DRESSES,denim:op.DRESSES,jumpsuits:op.DRESSES,overalls:op.DRESSES,rompers:op.DRESSES,unitards:op.DRESSES},pants_and_shorts:{cigarette:op.PANTS,culottes:op.SHORTS,denim_shorts:op.SHORTS,flared:op.PANTS,joggers:op.PANTS,leggings:op.PANTS,skinny:op.PANTS,wide_leg:op.PANTS},skirts:{a_line_flared:op.SKIRTS,denim:op.SKIRTS,knit:op.SKIRTS,pencil:op.SKIRTS,pleated:op.SKIRTS,skater:op.SKIRTS,slip:op.SKIRTS,wrap:op.SKIRTS},suits_and_tailoring:{blazers:op.JACKETS,suit_jackets:op.JACKETS,suit_skirts:op.SKIRTS,suit_trousers:op.PANTS,suit_vests:op.SWEATERS,trousers:op.PANTS},sweaters:{cardigans:op.SWEATERS,crewnecks:op.SWEATERS,hoodies_and_zipups:op.SWEATERS,sweatshirts:op.SWEATERS,turtlenecks:op.SWEATERS,v_necks:op.SWEATERS},tops:{bodysuits:op.BLOUSES,corsets_and_bustiers:op.BLOUSES,polos:op.T_SHIRTS_AND_TANKS,shirts_and_blouses:op.BLOUSES,t_shirts:op.T_SHIRTS_AND_TANKS,tank_tops_and_camisoles:op.T_SHIRTS_AND_TANKS}};var lp;!function(t){t.TOO_TIGHT="too_tight",t.TIGHT="tight",t.SLIGHTLY_TIGHT="slightly_tight",t.PERFECT_FIT="perfect_fit",t.SLIGHTLY_LOOSE="slightly_loose",t.LOOSE="loose",t.OVERSIZED="oversized"}(lp||(lp={}));const dp={[lp.TOO_TIGHT]:"Too Tight",[lp.TIGHT]:"Tight",[lp.SLIGHTLY_TIGHT]:"Slightly Tight",[lp.PERFECT_FIT]:"Perfect Fit",[lp.SLIGHTLY_LOOSE]:"Slightly Loose",[lp.LOOSE]:"Loose",[lp.OVERSIZED]:"Oversized"};class fp{static get endpoint(){return il.getInstance().api.url}static async Fetch({user:t,endpointPath:e,method:n,body:s,useToken:r=!0}){const i=this.getUrl(e,r),o={method:n,headers:await this.getHeaders(t,r),credentials:"include"};s&&(o.body=JSON.stringify(s));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,s){return this.Fetch({user:t,endpointPath:e,method:"POST",body:n,useToken:s})}static Put(t,e,n,s){return this.Fetch({user:t,endpointPath:e,method:"PUT",body:n,useToken:s})}static Patch(t,e,n,s){return this.Fetch({user:t,endpointPath:e,method:"PATCH",body:n,useToken:s})}static Delete(t,e,n,s){return this.Fetch({user:t,endpointPath:e,method:"DELETE",body:n,useToken:s})}}class pp{constructor(t,e){this.brandId=t,this.firebase=e}get user(){return this.firebase.user}get isLoggedIn(){return!this.firebase||Boolean(this.user.id)}onInit(){return this.firebase.onInit()}async getRecommendedSizes(t){var e,n;if(!this.isLoggedIn)throw new Yf;try{const s=await fp.Get(this.user,`/styles/${t}/recommendation`),r=await s.json();return(null===(e=null==r?void 0:r.fits)||void 0===e?void 0:e.length)&&(null===(n=null==r?void 0:r.recommended_size)||void 0===n?void 0:n.id)?r:null}catch(t){if((null==t?void 0:t.error)===Zf)throw new Jf;throw t}}async submitTelephoneNumber(t){const e=t.replace(/[^\+0-9]/g,""),n=await fp.Post(this.user,"/ios-app-link",{phone_number:e},!1);console.log(n)}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 getMeasurementLocationsFromSku(t){var e;const n=await this.getColorwaySizeAssetFromSku(t);if(!n)throw new Error("No colorway size asset found for sku");const s=await this.getStyleCategory(n.style_id);if(!s)throw new Error("Style category not found for style id");const r=await this.getGetTaxonomy(s.style_garment_category_id);if(!r)throw new Error("Taxonomy not found for style garment category id");const i=(null===(e=hp[r.style_category])||void 0===e?void 0:e[r.garment_category])||null;return i?ap[i].map((t=>ip[t])):null}async getColorwaySizeAssets(t,e){const n=[qh("brand_id","==",this.brandId)];t&&n.push(qh("style_id","==",t)),(null==e?void 0:e.length)>0&&n.push(qh("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 sp(t)}}async getStyleCategory(t){try{return await this.firebase.getDoc("styles",String(t))}catch(t){return sp(t)}}async getGetTaxonomy(t){try{return await this.firebase.getDoc("style_garment_categories",String(t))}catch(t){return sp(t)}}}const gp=(t,e="dev")=>("dev"!==e&&"development"!==e||console.warn("TfrShop is in development mode"),il.getInstance().setEnv(e),new pp(t,new np));var mp;!function(t){t.NOT_CREATED="NOT_CREATED",t.CREATED="CREATED",t.PENDING="PENDING"}(mp||(mp={}));var yp=Object.freeze({__proto__:null,get AvatarState(){return mp},get MeasurementLocation(){return rp},MeasurementLocationName:ip,get Classification(){return op},ClassificationLocations:ap,CategoryNames:cp,Categories:["activewear","dresses","jackets_and_coats","jeans","jumpsuits_and_rompers","pants_and_shorts","skirts","suits_and_tailoring","sweaters","tops"],SubcategoryNames:up,Taxonomy:hp,get Fit(){return lp},FitNames:dp});export{tp as Errors,gp as initShop,t as requests,e as responses,yp as types};
3168
3168
  //# sourceMappingURL=index.min.js.map