@thefittingroom/sdk 1.1.9 → 1.1.11

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.9 (2024-06-20T18:09:09.877Z)
2
+ * thefittingroom v1.1.11 (2024-06-20T18:20:57.355Z)
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 Gf{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 Wf=h("authIdTokenMaxAge")||300;let zf=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:jf,persistence:[rf,Hd,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>Wf)return;const s=null==e?void 0:e.token;zf!==s&&(zf=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 Gf(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(Hd)}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=Hh(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=Hh(lh(this.firestore,t),e);return this.promisefyOnSnapshot(s,n)}getDocs(t,e){return nl(Hh(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)};class rp{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 ip{constructor(t,e){this.brandId=t,this.firebase=e,this.measurementLocations=new Map}get user(){return this.firebase.user}get isLoggedIn(){return!this.firebase||Boolean(this.user.id)}async onInit(){return await this.getMeasurementLocations(),this.firebase.onInit()}async getRecommendedSizes(t){var e,n;if(!this.isLoggedIn)throw new Yf;try{const s=await rp.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 rp.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){const e=await this.getColorwaySizeAssetFromSku(t);if(!e)throw new Error("No colorway size asset found for sku");const n=await this.getStyle(e.style_id);if(!n)throw new Error("Style category not found for style id");const s=await this.getGetTaxonomy(n.style_garment_category_id);if(!s)throw new Error("Taxonomy not found for style garment category id");return s.garment_measurement_locations.female.map((t=>this.measurementLocations.has(t)?this.measurementLocations.get(t):t))}async getStyleByBrandStyleId(t){try{return(await this.firebase.getDocs("styles",[qh("brand_style_id","==",t)])).docs[0].data()}catch(t){return sp(t)}}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 getStyle(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)}}async getMeasurementLocations(){(await this.fetchMeasurementLocations()).forEach((t=>{this.measurementLocations.set(t.name,t.label)}))}async fetchMeasurementLocations(){try{return(await this.firebase.getDocs("garment_measurement_locations",[])).docs.map((t=>t.data()))}catch(t){return sp(t)}}}const op=(t,e="dev")=>("dev"!==e&&"development"!==e||console.warn("TfrShop is in development mode"),il.getInstance().setEnv(e),new ip(t,new np));var ap;!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"}(ap||(ap={}));const cp={[ap.ACROSS_BACK]:"Across back",[ap.ACROSS_FRONT]:"Across front",[ap.ACROSS_SHOULDER]:"Across shoulder",[ap.ANKLE]:"Ankle",[ap.ARMEYE]:"Armeye",[ap.ARM_LENGTH_FROM_SHOULDER]:"Arm length from shoulder",[ap.BACK_CROTCH_LENGTH]:"Back crotch length",[ap.BACK_NECK_TO_EBLOW]:"Back neck to eblow",[ap.BELOW_KNEE]:"Below knee",[ap.BICEP]:"Bicep",[ap.BUST]:"Chest/Bust",[ap.BUST_POINT_TO_BUST_POINT]:"Bust point to bust point",[ap.CALF]:"Calf",[ap.CB_NECK_TO_WAIST]:"Cb neck to waist",[ap.CB_NECK_TO_WRIST]:"Cb neck to wrist",[ap.CF_NECK_TO_WAIST]:"Cf neck to waist",[ap.ELBOW]:"Elbow",[ap.FOREARM]:"Forearm",[ap.FRONT_CROTCH_LENGTH]:"Front crotch length",[ap.HIGH_HIP_PLACEMENT_FROM_WAIST]:"High hip placement from waist",[ap.HIGH_HIP]:"High hip",[ap.HSP_TO_ACROSS_BACK]:"Hsp to across back",[ap.HSP_TO_ACROSS_FRONT]:"Hsp to across front",[ap.HSP_TO_BUST_POINT]:"Hsp to bust point",[ap.HSP_TO_LOW_HIP_POSITION]:"Hsp to low hip position",[ap.HSP_TO_WAIST_POSITION]:"Hsp to waist position",[ap.INSEAM]:"Inseam",[ap.KNEE]:"Knee",[ap.LOW_HIP]:"Low hip",[ap.LOW_HIP_PLACEMENT_FROM_WAIST]:"Low hip placement from waist",[ap.MID_NECK]:"Mid neck",[ap.NECK_AT_BASE]:"Neck at base",[ap.SHOULDER_DROP]:"Shoulder drop",[ap.SHOULDER_TO_SHOULDER]:"Shoulder to shoulder",[ap.SIDE_WAIST_TO_FLOOR]:"Side waist to floor",[ap.SIDE_WAIST_TO_KNEE]:"Side waist to knee",[ap.THIGH]:"Thigh",[ap.TOTAL_RISE_LENGTH]:"Total rise length",[ap.UNDER_BUST]:"Under bust",[ap.VERTICAL_TRUNK]:"Vertical trunk",[ap.WAIST]:"Waist",[ap.WRIST]:"Wrist"};var up;!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"}(up||(up={}));const hp={[up.BLOUSES]:[ap.BUST,ap.ACROSS_SHOULDER,ap.WAIST,ap.LOW_HIP,ap.HIGH_HIP],[up.COATS]:[ap.BUST,ap.ACROSS_SHOULDER,ap.WAIST,ap.LOW_HIP,ap.HIGH_HIP],[up.DRESSES]:[ap.LOW_HIP,ap.BUST,ap.ACROSS_SHOULDER,ap.WAIST],[up.JACKETS]:[ap.BUST,ap.ACROSS_SHOULDER,ap.WAIST,ap.LOW_HIP,ap.HIGH_HIP],[up.PANTS]:[ap.LOW_HIP,ap.WAIST,ap.THIGH,ap.INSEAM],[up.PUFFERS_AND_PARKAS]:[ap.BUST,ap.ACROSS_SHOULDER,ap.WAIST,ap.LOW_HIP,ap.HIGH_HIP],[up.SHORTS]:[ap.LOW_HIP,ap.WAIST,ap.THIGH,ap.INSEAM],[up.SKIRTS]:[ap.LOW_HIP,ap.WAIST],[up.SWEATERS]:[ap.BUST,ap.ACROSS_SHOULDER,ap.WAIST,ap.LOW_HIP,ap.HIGH_HIP],[up.T_SHIRTS_AND_TANKS]:[ap.BUST,ap.ACROSS_SHOULDER,ap.WAIST,ap.LOW_HIP,ap.HIGH_HIP]},lp={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"},dp={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"},fp={activewear:{leggings:up.PANTS,joggers:up.PANTS,sweatshirts:up.SWEATERS},dresses:{a_line:up.DRESSES,bodycon:up.DRESSES,fit_and_flare:up.DRESSES,knit:up.DRESSES,shirt:up.DRESSES,slip:up.DRESSES,straight:up.DRESSES,wrap:up.DRESSES},jackets_and_coats:{denim_jackets:up.JACKETS,parkas:up.PUFFERS_AND_PARKAS,peacoats:up.COATS,puffer_jackets:up.PUFFERS_AND_PARKAS,raincoats:up.COATS,rompers:up.COATS,shackets:up.JACKETS,trench_coats:up.COATS},jeans:{bootcut:up.PANTS,flared:up.PANTS,mom:up.PANTS,relaxed:up.PANTS,skinny:up.PANTS,slim:up.PANTS,straight:up.PANTS,tapered:up.PANTS,wide_leg:up.PANTS},jumpsuits_and_rompers:{boiler_suits:up.DRESSES,denim:up.DRESSES,jumpsuits:up.DRESSES,overalls:up.DRESSES,rompers:up.DRESSES,unitards:up.DRESSES},pants_and_shorts:{cigarette:up.PANTS,culottes:up.SHORTS,denim_shorts:up.SHORTS,flared:up.PANTS,joggers:up.PANTS,leggings:up.PANTS,skinny:up.PANTS,wide_leg:up.PANTS},skirts:{a_line_flared:up.SKIRTS,denim:up.SKIRTS,knit:up.SKIRTS,pencil:up.SKIRTS,pleated:up.SKIRTS,skater:up.SKIRTS,slip:up.SKIRTS,wrap:up.SKIRTS},suits_and_tailoring:{blazers:up.JACKETS,suit_jackets:up.JACKETS,suit_skirts:up.SKIRTS,suit_trousers:up.PANTS,suit_vests:up.SWEATERS,trousers:up.PANTS},sweaters:{cardigans:up.SWEATERS,crewnecks:up.SWEATERS,hoodies_and_zipups:up.SWEATERS,sweatshirts:up.SWEATERS,turtlenecks:up.SWEATERS,v_necks:up.SWEATERS},tops:{bodysuits:up.BLOUSES,corsets_and_bustiers:up.BLOUSES,polos:up.T_SHIRTS_AND_TANKS,shirts_and_blouses:up.BLOUSES,t_shirts:up.T_SHIRTS_AND_TANKS,tank_tops_and_camisoles:up.T_SHIRTS_AND_TANKS}};var pp;!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",t.TOO_SHORT="too_short",t.SHORT="short",t.SLIGHTLY_SHORT="slightly_short",t.SLIGHTLY_LONG="slightly_long",t.LONG="long",t.TOO_LONG="too_long"}(pp||(pp={}));const gp={[pp.TOO_TIGHT]:"Too Tight",[pp.TIGHT]:"Tight",[pp.SLIGHTLY_TIGHT]:"Slightly Tight",[pp.PERFECT_FIT]:"Perfect Fit",[pp.SLIGHTLY_LOOSE]:"Slightly Loose",[pp.LOOSE]:"Loose",[pp.OVERSIZED]:"Oversized",[pp.TOO_SHORT]:"Too Short",[pp.SHORT]:"Short",[pp.SLIGHTLY_SHORT]:"Slightly Short",[pp.SLIGHTLY_LONG]:"Slightly Long",[pp.LONG]:"Long",[pp.TOO_LONG]:"Too Long"};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 ap},MeasurementLocationName:cp,get Classification(){return up},ClassificationLocations:hp,CategoryNames:lp,Categories:["activewear","dresses","jackets_and_coats","jeans","jumpsuits_and_rompers","pants_and_shorts","skirts","suits_and_tailoring","sweaters","tops"],SubcategoryNames:dp,Taxonomy:fp,get Fit(){return pp},FitNames:gp});export{tp as Errors,op as initShop,t as requests,e as responses,yp as types};
3167
+ const Wf=h("authIdTokenMaxAge")||300;let zf=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:jf,persistence:[rf,Hd,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>Wf)return;const s=null==e?void 0:e.token;zf!==s&&(zf=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 Gf(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(Hd)}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=Hh(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=Hh(lh(this.firestore,t),e);return this.promisefyOnSnapshot(s,n)}getDocs(t,e){return nl(Hh(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)};class rp{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 ip{constructor(t,e){this.brandId=t,this.firebase=e,this.measurementLocations=new Map}get user(){return this.firebase.user}get isLoggedIn(){return!this.firebase||Boolean(this.user.id)}async onInit(){return await this.getMeasurementLocations(),this.firebase.onInit()}async getRecommendedSizes(t){var e,n;if(!this.isLoggedIn)throw new Yf;try{const s=await rp.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 rp.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){const e=await this.getColorwaySizeAssetFromSku(t);if(!e)throw new Error("No colorway size asset found for sku");const n=await this.getStyle(e.style_id);if(!n)throw new Error("Style category not found for style id");const s=await this.getGetTaxonomy(n.style_garment_category_id);if(!s)throw new Error("Taxonomy not found for style garment category id");return s.garment_measurement_locations.female.map((t=>this.measurementLocations.has(t)?this.measurementLocations.get(t):t))}async getStyleByBrandStyleId(t){try{const e=[qh("brand_id","==",this.brandId)];e.push(qh("brand_style_id","==",t));return(await this.firebase.getDocs("styles",e)).docs[0].data()}catch(t){return sp(t)}}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 getStyle(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)}}async getMeasurementLocations(){(await this.fetchMeasurementLocations()).forEach((t=>{this.measurementLocations.set(t.name,t.label)}))}async fetchMeasurementLocations(){try{return(await this.firebase.getDocs("garment_measurement_locations",[])).docs.map((t=>t.data()))}catch(t){return sp(t)}}}const op=(t,e="dev")=>("dev"!==e&&"development"!==e||console.warn("TfrShop is in development mode"),il.getInstance().setEnv(e),new ip(t,new np));var ap;!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"}(ap||(ap={}));const cp={[ap.ACROSS_BACK]:"Across back",[ap.ACROSS_FRONT]:"Across front",[ap.ACROSS_SHOULDER]:"Across shoulder",[ap.ANKLE]:"Ankle",[ap.ARMEYE]:"Armeye",[ap.ARM_LENGTH_FROM_SHOULDER]:"Arm length from shoulder",[ap.BACK_CROTCH_LENGTH]:"Back crotch length",[ap.BACK_NECK_TO_EBLOW]:"Back neck to eblow",[ap.BELOW_KNEE]:"Below knee",[ap.BICEP]:"Bicep",[ap.BUST]:"Chest/Bust",[ap.BUST_POINT_TO_BUST_POINT]:"Bust point to bust point",[ap.CALF]:"Calf",[ap.CB_NECK_TO_WAIST]:"Cb neck to waist",[ap.CB_NECK_TO_WRIST]:"Cb neck to wrist",[ap.CF_NECK_TO_WAIST]:"Cf neck to waist",[ap.ELBOW]:"Elbow",[ap.FOREARM]:"Forearm",[ap.FRONT_CROTCH_LENGTH]:"Front crotch length",[ap.HIGH_HIP_PLACEMENT_FROM_WAIST]:"High hip placement from waist",[ap.HIGH_HIP]:"High hip",[ap.HSP_TO_ACROSS_BACK]:"Hsp to across back",[ap.HSP_TO_ACROSS_FRONT]:"Hsp to across front",[ap.HSP_TO_BUST_POINT]:"Hsp to bust point",[ap.HSP_TO_LOW_HIP_POSITION]:"Hsp to low hip position",[ap.HSP_TO_WAIST_POSITION]:"Hsp to waist position",[ap.INSEAM]:"Inseam",[ap.KNEE]:"Knee",[ap.LOW_HIP]:"Low hip",[ap.LOW_HIP_PLACEMENT_FROM_WAIST]:"Low hip placement from waist",[ap.MID_NECK]:"Mid neck",[ap.NECK_AT_BASE]:"Neck at base",[ap.SHOULDER_DROP]:"Shoulder drop",[ap.SHOULDER_TO_SHOULDER]:"Shoulder to shoulder",[ap.SIDE_WAIST_TO_FLOOR]:"Side waist to floor",[ap.SIDE_WAIST_TO_KNEE]:"Side waist to knee",[ap.THIGH]:"Thigh",[ap.TOTAL_RISE_LENGTH]:"Total rise length",[ap.UNDER_BUST]:"Under bust",[ap.VERTICAL_TRUNK]:"Vertical trunk",[ap.WAIST]:"Waist",[ap.WRIST]:"Wrist"};var up;!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"}(up||(up={}));const hp={[up.BLOUSES]:[ap.BUST,ap.ACROSS_SHOULDER,ap.WAIST,ap.LOW_HIP,ap.HIGH_HIP],[up.COATS]:[ap.BUST,ap.ACROSS_SHOULDER,ap.WAIST,ap.LOW_HIP,ap.HIGH_HIP],[up.DRESSES]:[ap.LOW_HIP,ap.BUST,ap.ACROSS_SHOULDER,ap.WAIST],[up.JACKETS]:[ap.BUST,ap.ACROSS_SHOULDER,ap.WAIST,ap.LOW_HIP,ap.HIGH_HIP],[up.PANTS]:[ap.LOW_HIP,ap.WAIST,ap.THIGH,ap.INSEAM],[up.PUFFERS_AND_PARKAS]:[ap.BUST,ap.ACROSS_SHOULDER,ap.WAIST,ap.LOW_HIP,ap.HIGH_HIP],[up.SHORTS]:[ap.LOW_HIP,ap.WAIST,ap.THIGH,ap.INSEAM],[up.SKIRTS]:[ap.LOW_HIP,ap.WAIST],[up.SWEATERS]:[ap.BUST,ap.ACROSS_SHOULDER,ap.WAIST,ap.LOW_HIP,ap.HIGH_HIP],[up.T_SHIRTS_AND_TANKS]:[ap.BUST,ap.ACROSS_SHOULDER,ap.WAIST,ap.LOW_HIP,ap.HIGH_HIP]},lp={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"},dp={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"},fp={activewear:{leggings:up.PANTS,joggers:up.PANTS,sweatshirts:up.SWEATERS},dresses:{a_line:up.DRESSES,bodycon:up.DRESSES,fit_and_flare:up.DRESSES,knit:up.DRESSES,shirt:up.DRESSES,slip:up.DRESSES,straight:up.DRESSES,wrap:up.DRESSES},jackets_and_coats:{denim_jackets:up.JACKETS,parkas:up.PUFFERS_AND_PARKAS,peacoats:up.COATS,puffer_jackets:up.PUFFERS_AND_PARKAS,raincoats:up.COATS,rompers:up.COATS,shackets:up.JACKETS,trench_coats:up.COATS},jeans:{bootcut:up.PANTS,flared:up.PANTS,mom:up.PANTS,relaxed:up.PANTS,skinny:up.PANTS,slim:up.PANTS,straight:up.PANTS,tapered:up.PANTS,wide_leg:up.PANTS},jumpsuits_and_rompers:{boiler_suits:up.DRESSES,denim:up.DRESSES,jumpsuits:up.DRESSES,overalls:up.DRESSES,rompers:up.DRESSES,unitards:up.DRESSES},pants_and_shorts:{cigarette:up.PANTS,culottes:up.SHORTS,denim_shorts:up.SHORTS,flared:up.PANTS,joggers:up.PANTS,leggings:up.PANTS,skinny:up.PANTS,wide_leg:up.PANTS},skirts:{a_line_flared:up.SKIRTS,denim:up.SKIRTS,knit:up.SKIRTS,pencil:up.SKIRTS,pleated:up.SKIRTS,skater:up.SKIRTS,slip:up.SKIRTS,wrap:up.SKIRTS},suits_and_tailoring:{blazers:up.JACKETS,suit_jackets:up.JACKETS,suit_skirts:up.SKIRTS,suit_trousers:up.PANTS,suit_vests:up.SWEATERS,trousers:up.PANTS},sweaters:{cardigans:up.SWEATERS,crewnecks:up.SWEATERS,hoodies_and_zipups:up.SWEATERS,sweatshirts:up.SWEATERS,turtlenecks:up.SWEATERS,v_necks:up.SWEATERS},tops:{bodysuits:up.BLOUSES,corsets_and_bustiers:up.BLOUSES,polos:up.T_SHIRTS_AND_TANKS,shirts_and_blouses:up.BLOUSES,t_shirts:up.T_SHIRTS_AND_TANKS,tank_tops_and_camisoles:up.T_SHIRTS_AND_TANKS}};var pp;!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",t.TOO_SHORT="too_short",t.SHORT="short",t.SLIGHTLY_SHORT="slightly_short",t.SLIGHTLY_LONG="slightly_long",t.LONG="long",t.TOO_LONG="too_long"}(pp||(pp={}));const gp={[pp.TOO_TIGHT]:"Too Tight",[pp.TIGHT]:"Tight",[pp.SLIGHTLY_TIGHT]:"Slightly Tight",[pp.PERFECT_FIT]:"Perfect Fit",[pp.SLIGHTLY_LOOSE]:"Slightly Loose",[pp.LOOSE]:"Loose",[pp.OVERSIZED]:"Oversized",[pp.TOO_SHORT]:"Too Short",[pp.SHORT]:"Short",[pp.SLIGHTLY_SHORT]:"Slightly Short",[pp.SLIGHTLY_LONG]:"Slightly Long",[pp.LONG]:"Long",[pp.TOO_LONG]:"Too Long"};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 ap},MeasurementLocationName:cp,get Classification(){return up},ClassificationLocations:hp,CategoryNames:lp,Categories:["activewear","dresses","jackets_and_coats","jeans","jumpsuits_and_rompers","pants_and_shorts","skirts","suits_and_tailoring","sweaters","tops"],SubcategoryNames:dp,Taxonomy:fp,get Fit(){return pp},FitNames:gp});export{tp as Errors,op as initShop,t as requests,e as responses,yp as types};
3168
3168
  //# sourceMappingURL=index.min.js.map