@thefittingroom/sdk 1.0.2 → 1.1.0
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 v1.0
|
|
2
|
+
* thefittingroom v1.1.0 (2024-02-16T20:34:26.286Z)
|
|
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 zf{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 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>Wf)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 zf(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("no frames found"),this.name="NoFramesFoundError"}}class Xf extends Error{constructor(){super("request timeout"),this.name="RequestTimeoutError"}}class Zf extends Error{constructor(){super("user not logged in"),this.name="UserNotLoggedInError"}}class tp extends Error{constructor(){super("no colorway size assets found"),this.name="NoColorwaySizeAssetsFoundError"}}class ep extends Error{constructor(){super("no styles found"),this.name="NoStylesFoundError"}}class np extends Error{constructor(t,e){super("recommended available sizes error"),this.name="RecommendedAvailableSizesError",this.recommended_size=t,this.available_sizes=e}}class sp extends Error{constructor(){super("brand user id not set"),this.name="BrandUserIdNotSetError"}}const rp="avatar not created";var ip=Object.freeze({__proto__:null,AvatarNotCreatedError:Jf,NoFramesFoundError:Yf,RequestTimeoutError:Xf,UserNotLoggedInError:Zf,NoColorwaySizeAssetsFoundError:tp,NoStylesFoundError:ep,RecommendedAvailableSizesError:np,BrandUserIdNotSetError:sp,AvatarNotCreated:rp});class op{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 Zf;return await this.user.getIdToken()}async getUserProfile(){var t;if(!(null===(t=this.user)||void 0===t?void 0:t.uid))throw new Zf;return(await tl(dh(this.firestore,"users",this.id))).data()}watchUserProfileForChanges(t,e){let n;const s=jh(lh(this.firestore,"users"),qh(new Sh("__name__"),"==",this.id)),r=setTimeout((()=>n()),e);return new Promise((e=>{n=sl(s,(async s=>{await t(s)&&(clearTimeout(r),n(),e(s.docs[0].data()))}))}))}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 ap{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 op(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 cp=t=>{if(t.code===dl)throw new Error("account has been disabled");throw new Error(t.message)};var up;!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"}(up||(up={}));const hp={[up.ACROSS_BACK]:"Across back",[up.ACROSS_FRONT]:"Across front",[up.ACROSS_SHOULDER]:"Across shoulder",[up.ANKLE]:"Ankle",[up.ARMEYE]:"Armeye",[up.ARM_LENGTH_FROM_SHOULDER]:"Arm length from shoulder",[up.BACK_CROTCH_LENGTH]:"Back crotch length",[up.BACK_NECK_TO_EBLOW]:"Back neck to eblow",[up.BELOW_KNEE]:"Below knee",[up.BICEP]:"Bicep",[up.BUST]:"Chest/Bust",[up.BUST_POINT_TO_BUST_POINT]:"Bust point to bust point",[up.CALF]:"Calf",[up.CB_NECK_TO_WAIST]:"Cb neck to waist",[up.CB_NECK_TO_WRIST]:"Cb neck to wrist",[up.CF_NECK_TO_WAIST]:"Cf neck to waist",[up.ELBOW]:"Elbow",[up.FOREARM]:"Forearm",[up.FRONT_CROTCH_LENGTH]:"Front crotch length",[up.HIGH_HIP_PLACEMENT_FROM_WAIST]:"High hip placement from waist",[up.HIGH_HIP]:"High hip",[up.HSP_TO_ACROSS_BACK]:"Hsp to across back",[up.HSP_TO_ACROSS_FRONT]:"Hsp to across front",[up.HSP_TO_BUST_POINT]:"Hsp to bust point",[up.HSP_TO_LOW_HIP_POSITION]:"Hsp to low hip position",[up.HSP_TO_WAIST_POSITION]:"Hsp to waist position",[up.INSEAM]:"Inseam",[up.KNEE]:"Knee",[up.LOW_HIP]:"Low hip",[up.LOW_HIP_PLACEMENT_FROM_WAIST]:"Low hip placement from waist",[up.MID_NECK]:"Mid neck",[up.NECK_AT_BASE]:"Neck at base",[up.SHOULDER_DROP]:"Shoulder drop",[up.SHOULDER_TO_SHOULDER]:"Shoulder to shoulder",[up.SIDE_WAIST_TO_FLOOR]:"Side waist to floor",[up.SIDE_WAIST_TO_KNEE]:"Side waist to knee",[up.THIGH]:"Thigh",[up.TOTAL_RISE_LENGTH]:"Total rise length",[up.UNDER_BUST]:"Under bust",[up.VERTICAL_TRUNK]:"Vertical trunk",[up.WAIST]:"Waist",[up.WRIST]:"Wrist"};var lp;!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"}(lp||(lp={}));const dp={[lp.BLOUSES]:[up.BUST,up.ACROSS_SHOULDER,up.WAIST,up.LOW_HIP,up.HIGH_HIP],[lp.COATS]:[up.BUST,up.ACROSS_SHOULDER,up.WAIST,up.LOW_HIP,up.HIGH_HIP],[lp.DRESSES]:[up.LOW_HIP,up.BUST,up.ACROSS_SHOULDER,up.WAIST],[lp.JACKETS]:[up.BUST,up.ACROSS_SHOULDER,up.WAIST,up.LOW_HIP,up.HIGH_HIP],[lp.PANTS]:[up.LOW_HIP,up.WAIST,up.THIGH,up.INSEAM],[lp.PUFFERS_AND_PARKAS]:[up.BUST,up.ACROSS_SHOULDER,up.WAIST,up.LOW_HIP,up.HIGH_HIP],[lp.SHORTS]:[up.LOW_HIP,up.WAIST,up.THIGH,up.INSEAM],[lp.SKIRTS]:[up.LOW_HIP,up.WAIST],[lp.SWEATERS]:[up.BUST,up.ACROSS_SHOULDER,up.WAIST,up.LOW_HIP,up.HIGH_HIP],[lp.T_SHIRTS_AND_TANKS]:[up.BUST,up.ACROSS_SHOULDER,up.WAIST,up.LOW_HIP,up.HIGH_HIP]},fp={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"},pp={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"},gp={activewear:{leggings:lp.PANTS,joggers:lp.PANTS,sweatshirts:lp.SWEATERS},dresses:{a_line:lp.DRESSES,bodycon:lp.DRESSES,fit_and_flare:lp.DRESSES,knit:lp.DRESSES,shirt:lp.DRESSES,slip:lp.DRESSES,straight:lp.DRESSES,wrap:lp.DRESSES},jackets_and_coats:{denim_jackets:lp.JACKETS,parkas:lp.PUFFERS_AND_PARKAS,peacoats:lp.COATS,puffer_jackets:lp.PUFFERS_AND_PARKAS,raincoats:lp.COATS,rompers:lp.COATS,shackets:lp.JACKETS,trench_coats:lp.COATS},jeans:{bootcut:lp.PANTS,flared:lp.PANTS,mom:lp.PANTS,relaxed:lp.PANTS,skinny:lp.PANTS,slim:lp.PANTS,straight:lp.PANTS,tapered:lp.PANTS,wide_leg:lp.PANTS},jumpsuits_and_rompers:{boiler_suits:lp.DRESSES,denim:lp.DRESSES,jumpsuits:lp.DRESSES,overalls:lp.DRESSES,rompers:lp.DRESSES,unitards:lp.DRESSES},pants_and_shorts:{cigarette:lp.PANTS,culottes:lp.SHORTS,denim_shorts:lp.SHORTS,flared:lp.PANTS,joggers:lp.PANTS,leggings:lp.PANTS,skinny:lp.PANTS,wide_leg:lp.PANTS},skirts:{a_line_flared:lp.SKIRTS,denim:lp.SKIRTS,knit:lp.SKIRTS,pencil:lp.SKIRTS,pleated:lp.SKIRTS,skater:lp.SKIRTS,slip:lp.SKIRTS,wrap:lp.SKIRTS},suits_and_tailoring:{blazers:lp.JACKETS,suit_jackets:lp.JACKETS,suit_skirts:lp.SKIRTS,suit_trousers:lp.PANTS,suit_vests:lp.SWEATERS,trousers:lp.PANTS},sweaters:{cardigans:lp.SWEATERS,crewnecks:lp.SWEATERS,hoodies_and_zipups:lp.SWEATERS,sweatshirts:lp.SWEATERS,turtlenecks:lp.SWEATERS,v_necks:lp.SWEATERS},tops:{bodysuits:lp.BLOUSES,corsets_and_bustiers:lp.BLOUSES,polos:lp.T_SHIRTS_AND_TANKS,shirts_and_blouses:lp.BLOUSES,t_shirts:lp.T_SHIRTS_AND_TANKS,tank_tops_and_camisoles:lp.T_SHIRTS_AND_TANKS}};var mp;!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"}(mp||(mp={}));const yp={[mp.TOO_TIGHT]:"Too Tight",[mp.TIGHT]:"Tight",[mp.SLIGHTLY_TIGHT]:"Slightly Tight",[mp.PERFECT_FIT]:"Perfect Fit",[mp.SLIGHTLY_LOOSE]:"Slightly Loose",[mp.LOOSE]:"Loose",[mp.OVERSIZED]:"Oversized"};class vp{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 wp{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 Zf;try{const s=await vp.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)===rp)throw new Jf;throw t}}async submitTelephoneNumber(t){const e=t.replace(/[^\+0-9]/g,""),n=await vp.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 tp;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=(null===(e=gp[s.category])||void 0===e?void 0:e[s.sub_category])||null;return r?dp[r].map((t=>hp[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 cp(t)}}async getStyleCategory(t){try{return await this.firebase.getDoc("style_categories",String(t))}catch(t){return cp(t)}}}const _p=(t,e="dev")=>("dev"!==e&&"development"!==e||console.warn("TfrShop is in development mode"),il.getInstance().setEnv(e),new wp(t,new ap));var Tp;!function(t){t.NOT_CREATED="NOT_CREATED",t.CREATED="CREATED",t.PENDING="PENDING"}(Tp||(Tp={}));var Ip=Object.freeze({__proto__:null,get AvatarState(){return Tp},get MeasurementLocation(){return up},MeasurementLocationName:hp,get Classification(){return lp},ClassificationLocations:dp,CategoryNames:fp,Categories:["activewear","dresses","jackets_and_coats","jeans","jumpsuits_and_rompers","pants_and_shorts","skirts","suits_and_tailoring","sweaters","tops"],SubcategoryNames:pp,Taxonomy:gp,get Fit(){return mp},FitNames:yp});export{ip as Errors,_p as initShop,t as requests,e as responses,Ip as types};
|
|
3167
|
+
const Wf=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>Wf)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 zf(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("no frames found"),this.name="NoFramesFoundError"}}class Xf extends Error{constructor(){super("request timeout"),this.name="RequestTimeoutError"}}class Zf extends Error{constructor(){super("user not logged in"),this.name="UserNotLoggedInError"}}class tp extends Error{constructor(){super("no colorway size assets found"),this.name="NoColorwaySizeAssetsFoundError"}}class ep extends Error{constructor(){super("no styles found"),this.name="NoStylesFoundError"}}class np extends Error{constructor(t,e){super("recommended available sizes error"),this.name="RecommendedAvailableSizesError",this.recommended_size=t,this.available_sizes=e}}class sp extends Error{constructor(){super("brand user id not set"),this.name="BrandUserIdNotSetError"}}const rp="avatar not created";var ip=Object.freeze({__proto__:null,AvatarNotCreatedError:Jf,NoFramesFoundError:Yf,RequestTimeoutError:Xf,UserNotLoggedInError:Zf,NoColorwaySizeAssetsFoundError:tp,NoStylesFoundError:ep,RecommendedAvailableSizesError:np,BrandUserIdNotSetError:sp,AvatarNotCreated:rp});class op{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 Zf;return await this.user.getIdToken()}async getUserProfile(){var t;if(!(null===(t=this.user)||void 0===t?void 0:t.uid))throw new Zf;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 ap{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 op(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 cp=t=>{if(t.code===dl)throw new Error("account has been disabled");throw new Error(t.message)};var up;!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"}(up||(up={}));const hp={[up.ACROSS_BACK]:"Across back",[up.ACROSS_FRONT]:"Across front",[up.ACROSS_SHOULDER]:"Across shoulder",[up.ANKLE]:"Ankle",[up.ARMEYE]:"Armeye",[up.ARM_LENGTH_FROM_SHOULDER]:"Arm length from shoulder",[up.BACK_CROTCH_LENGTH]:"Back crotch length",[up.BACK_NECK_TO_EBLOW]:"Back neck to eblow",[up.BELOW_KNEE]:"Below knee",[up.BICEP]:"Bicep",[up.BUST]:"Chest/Bust",[up.BUST_POINT_TO_BUST_POINT]:"Bust point to bust point",[up.CALF]:"Calf",[up.CB_NECK_TO_WAIST]:"Cb neck to waist",[up.CB_NECK_TO_WRIST]:"Cb neck to wrist",[up.CF_NECK_TO_WAIST]:"Cf neck to waist",[up.ELBOW]:"Elbow",[up.FOREARM]:"Forearm",[up.FRONT_CROTCH_LENGTH]:"Front crotch length",[up.HIGH_HIP_PLACEMENT_FROM_WAIST]:"High hip placement from waist",[up.HIGH_HIP]:"High hip",[up.HSP_TO_ACROSS_BACK]:"Hsp to across back",[up.HSP_TO_ACROSS_FRONT]:"Hsp to across front",[up.HSP_TO_BUST_POINT]:"Hsp to bust point",[up.HSP_TO_LOW_HIP_POSITION]:"Hsp to low hip position",[up.HSP_TO_WAIST_POSITION]:"Hsp to waist position",[up.INSEAM]:"Inseam",[up.KNEE]:"Knee",[up.LOW_HIP]:"Low hip",[up.LOW_HIP_PLACEMENT_FROM_WAIST]:"Low hip placement from waist",[up.MID_NECK]:"Mid neck",[up.NECK_AT_BASE]:"Neck at base",[up.SHOULDER_DROP]:"Shoulder drop",[up.SHOULDER_TO_SHOULDER]:"Shoulder to shoulder",[up.SIDE_WAIST_TO_FLOOR]:"Side waist to floor",[up.SIDE_WAIST_TO_KNEE]:"Side waist to knee",[up.THIGH]:"Thigh",[up.TOTAL_RISE_LENGTH]:"Total rise length",[up.UNDER_BUST]:"Under bust",[up.VERTICAL_TRUNK]:"Vertical trunk",[up.WAIST]:"Waist",[up.WRIST]:"Wrist"};var lp;!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"}(lp||(lp={}));const dp={[lp.BLOUSES]:[up.BUST,up.ACROSS_SHOULDER,up.WAIST,up.LOW_HIP,up.HIGH_HIP],[lp.COATS]:[up.BUST,up.ACROSS_SHOULDER,up.WAIST,up.LOW_HIP,up.HIGH_HIP],[lp.DRESSES]:[up.LOW_HIP,up.BUST,up.ACROSS_SHOULDER,up.WAIST],[lp.JACKETS]:[up.BUST,up.ACROSS_SHOULDER,up.WAIST,up.LOW_HIP,up.HIGH_HIP],[lp.PANTS]:[up.LOW_HIP,up.WAIST,up.THIGH,up.INSEAM],[lp.PUFFERS_AND_PARKAS]:[up.BUST,up.ACROSS_SHOULDER,up.WAIST,up.LOW_HIP,up.HIGH_HIP],[lp.SHORTS]:[up.LOW_HIP,up.WAIST,up.THIGH,up.INSEAM],[lp.SKIRTS]:[up.LOW_HIP,up.WAIST],[lp.SWEATERS]:[up.BUST,up.ACROSS_SHOULDER,up.WAIST,up.LOW_HIP,up.HIGH_HIP],[lp.T_SHIRTS_AND_TANKS]:[up.BUST,up.ACROSS_SHOULDER,up.WAIST,up.LOW_HIP,up.HIGH_HIP]},fp={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"},pp={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"},gp={activewear:{leggings:lp.PANTS,joggers:lp.PANTS,sweatshirts:lp.SWEATERS},dresses:{a_line:lp.DRESSES,bodycon:lp.DRESSES,fit_and_flare:lp.DRESSES,knit:lp.DRESSES,shirt:lp.DRESSES,slip:lp.DRESSES,straight:lp.DRESSES,wrap:lp.DRESSES},jackets_and_coats:{denim_jackets:lp.JACKETS,parkas:lp.PUFFERS_AND_PARKAS,peacoats:lp.COATS,puffer_jackets:lp.PUFFERS_AND_PARKAS,raincoats:lp.COATS,rompers:lp.COATS,shackets:lp.JACKETS,trench_coats:lp.COATS},jeans:{bootcut:lp.PANTS,flared:lp.PANTS,mom:lp.PANTS,relaxed:lp.PANTS,skinny:lp.PANTS,slim:lp.PANTS,straight:lp.PANTS,tapered:lp.PANTS,wide_leg:lp.PANTS},jumpsuits_and_rompers:{boiler_suits:lp.DRESSES,denim:lp.DRESSES,jumpsuits:lp.DRESSES,overalls:lp.DRESSES,rompers:lp.DRESSES,unitards:lp.DRESSES},pants_and_shorts:{cigarette:lp.PANTS,culottes:lp.SHORTS,denim_shorts:lp.SHORTS,flared:lp.PANTS,joggers:lp.PANTS,leggings:lp.PANTS,skinny:lp.PANTS,wide_leg:lp.PANTS},skirts:{a_line_flared:lp.SKIRTS,denim:lp.SKIRTS,knit:lp.SKIRTS,pencil:lp.SKIRTS,pleated:lp.SKIRTS,skater:lp.SKIRTS,slip:lp.SKIRTS,wrap:lp.SKIRTS},suits_and_tailoring:{blazers:lp.JACKETS,suit_jackets:lp.JACKETS,suit_skirts:lp.SKIRTS,suit_trousers:lp.PANTS,suit_vests:lp.SWEATERS,trousers:lp.PANTS},sweaters:{cardigans:lp.SWEATERS,crewnecks:lp.SWEATERS,hoodies_and_zipups:lp.SWEATERS,sweatshirts:lp.SWEATERS,turtlenecks:lp.SWEATERS,v_necks:lp.SWEATERS},tops:{bodysuits:lp.BLOUSES,corsets_and_bustiers:lp.BLOUSES,polos:lp.T_SHIRTS_AND_TANKS,shirts_and_blouses:lp.BLOUSES,t_shirts:lp.T_SHIRTS_AND_TANKS,tank_tops_and_camisoles:lp.T_SHIRTS_AND_TANKS}};var mp;!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"}(mp||(mp={}));const yp={[mp.TOO_TIGHT]:"Too Tight",[mp.TIGHT]:"Tight",[mp.SLIGHTLY_TIGHT]:"Slightly Tight",[mp.PERFECT_FIT]:"Perfect Fit",[mp.SLIGHTLY_LOOSE]:"Slightly Loose",[mp.LOOSE]:"Loose",[mp.OVERSIZED]:"Oversized"};class vp{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 wp{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 Zf;try{const s=await vp.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)===rp)throw new Jf;throw t}}async submitTelephoneNumber(t){const e=t.replace(/[^\+0-9]/g,""),n=await vp.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 tp;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=(null===(e=gp[s.category])||void 0===e?void 0:e[s.sub_category])||null;return r?dp[r].map((t=>hp[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 cp(t)}}async getStyleCategory(t){try{return await this.firebase.getDoc("style_categories",String(t))}catch(t){return cp(t)}}}const _p=(t,e="dev")=>("dev"!==e&&"development"!==e||console.warn("TfrShop is in development mode"),il.getInstance().setEnv(e),new wp(t,new ap));var Tp;!function(t){t.NOT_CREATED="NOT_CREATED",t.CREATED="CREATED",t.PENDING="PENDING"}(Tp||(Tp={}));var Ip=Object.freeze({__proto__:null,get AvatarState(){return Tp},get MeasurementLocation(){return up},MeasurementLocationName:hp,get Classification(){return lp},ClassificationLocations:dp,CategoryNames:fp,Categories:["activewear","dresses","jackets_and_coats","jeans","jumpsuits_and_rompers","pants_and_shorts","skirts","suits_and_tailoring","sweaters","tops"],SubcategoryNames:pp,Taxonomy:gp,get Fit(){return mp},FitNames:yp});export{ip as Errors,_p as initShop,t as requests,e as responses,Ip as types};
|
|
3168
3168
|
//# sourceMappingURL=index.min.js.map
|