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