@wellesley/uploads 1.0.0 → 1.0.1
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/index.mjs +1 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{api as qo,handleBasicResponse as xe,usePostApiV1UploadsMutation as Xg,useDeleteApiV1UploadsByIdMutation as Jg,usePostApiV1UploadsByIdMetaMutation as Qg}from"https://cdn.jsdelivr.net/npm/@wellesley/openapi@1.0.135";import{toast as zi}from"https://cdn.jsdelivr.net/npm/react-toastify@10.0.5/+esm";import{useSelector as qi}from"https://cdn.jsdelivr.net/npm/react-redux@9.1.0/+esm";import{useRef as kg,useState as jg,useEffect as nd}from"https://cdn.jsdelivr.net/npm/react@18.2.0/+esm";import{createSelector as Fn,createSlice as td}from"https://cdn.jsdelivr.net/npm/@reduxjs/toolkit@2.2.1/+esm";const ed=qo.enhanceEndpoints({endpoints:{postApiV1UploadsByIdMeta:{async onQueryStarted(t,{queryFulfilled:n}){await xe(n,"Updated")}},postApiV1UploadsList:{async onQueryStarted(t,{queryFulfilled:n}){await xe(n)}},deleteApiV1UploadsBatch:{async onQueryStarted(t,{queryFulfilled:n}){await xe(n,"Deleted")}},putApiV1UploadsByIdTags:{async onQueryStarted(t,{queryFulfilled:n}){await xe(n)}}}}),{usePostApiV1UploadsByIdMetaMutation:u0,usePostApiV1UploadsListMutation:s0,usePutApiV1UploadsByIdTagsMutation:o0,useDeleteApiV1UploadsBatchMutation:f0}=ed;var Vt=(t=>(t.done="done",t.inprogress="inprogress",t))(Vt||{}),Se=(t=>(t.image="image",t.video="video",t.audio="audio",t))(Se||{}),zo=(t=>(t.post="$post",t.album="$album",t.avatar="$avatar",t.header="$header",t))(zo||{});const Ko=t=>{const n=t.toLowerCase().match(/\.([a-zA-Z0-9]{2,4})(\?|$)+/);return n?n[1]:void 0},rd=async({url:t,...n})=>{const e=await fetch(t,n);if(!e.ok)throw new Error(e.statusText);if("PUT"===n.method)return;const r=await e.json(),i=r;if(i.errorCode)throw new Error(i.message);return r},id=t=>t.replace(/\.[^.]*$/,""),Yo=()=>"object"!=typeof window,ud=()=>!Yo()&&/iPhone|iPod|iPad/gi.test(window.navigator.userAgent),Ae="8.48.0",st=globalThis;function Yi(t,n,e){const r=st,i=r.__SENTRY__=r.__SENTRY__||{},o=i[Ae]=i[Ae]||{};return o[t]||(o[t]=n())}const Zo=typeof __SENTRY_DEBUG__>"u"||__SENTRY_DEBUG__,sd="Sentry Logger ",Uo=["debug","info","warn","error","log","assert","trace"],Mo={};function od(t){if(!("console"in st))return t();const n=st.console,e={},r=Object.keys(Mo);r.forEach((t=>{const r=Mo[t];e[t]=n[t],n[t]=r}));try{return t()}finally{r.forEach((t=>{n[t]=e[t]}))}}function fd(){let t=!1;const n={enable:()=>{t=!0},disable:()=>{t=!1},isEnabled:()=>t};return Zo?Uo.forEach((e=>{n[e]=(...n)=>{t&&od((()=>{st.console[e](`${sd}[${e}]:`,...n)}))}})):Uo.forEach((t=>{n[t]=()=>{}})),n}const Sr=Yi("logger",fd);function Zi(){return Vi(st),st}function Vi(t){const n=t.__SENTRY__=t.__SENTRY__||{};return n.version=n.version||Ae,n[Ae]=n[Ae]||{}}const ad=Object.prototype.toString;function ld(t,n){return ad.call(t)===`[object ${n}]`}function cd(t){return ld(t,"Object")}function hd(t){return!(!t||!t.then||"function"!=typeof t.then)}function pd(t,n,e){try{Object.defineProperty(t,n,{value:e,writable:!0,configurable:!0})}catch{Zo&&Sr.log(`Failed to add non-enumerable property "${n}" to object`,t)}}const Vo=1e3;function Xo(){return Date.now()/Vo}function _d(){const{performance:t}=st;if(!t||!t.now)return Xo;const n=Date.now()-t.now(),e=null==t.timeOrigin?n:t.timeOrigin;return()=>(e+t.now())/Vo}const gd=_d();function Xt(){const t=st,n=t.crypto||t.msCrypto;let e=()=>16*Math.random();try{if(n&&n.randomUUID)return n.randomUUID().replace(/-/g,"");n&&n.getRandomValues&&(e=()=>{const t=new Uint8Array(1);return n.getRandomValues(t),t[0]})}catch{}return"10000000100040008000100000000000".replace(/[018]/g,(t=>(t^(15&e())>>t/4).toString(16)))}function dd(t,n={}){if(n.user&&(!t.ipAddress&&n.user.ip_address&&(t.ipAddress=n.user.ip_address),!t.did&&!n.did&&(t.did=n.user.id||n.user.email||n.user.username)),t.timestamp=n.timestamp||gd(),n.abnormal_mechanism&&(t.abnormal_mechanism=n.abnormal_mechanism),n.ignoreDuration&&(t.ignoreDuration=n.ignoreDuration),n.sid&&(t.sid=32===n.sid.length?n.sid:Xt()),void 0!==n.init&&(t.init=n.init),!t.did&&n.did&&(t.did=`${n.did}`),"number"==typeof n.started&&(t.started=n.started),t.ignoreDuration)t.duration=void 0;else if("number"==typeof n.duration)t.duration=n.duration;else{const n=t.timestamp-t.started;t.duration=n>=0?n:0}n.release&&(t.release=n.release),n.environment&&(t.environment=n.environment),!t.ipAddress&&n.ipAddress&&(t.ipAddress=n.ipAddress),!t.userAgent&&n.userAgent&&(t.userAgent=n.userAgent),"number"==typeof n.errors&&(t.errors=n.errors),n.status&&(t.status=n.status)}function Fo(){return Xt()}function Bo(){return Xt().substring(16)}function Jo(t,n,e=2){if(!n||"object"!=typeof n||e<=0)return n;if(t&&n&&0===Object.keys(n).length)return t;const r={...t};for(const t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=Jo(r[t],n[t],e-1));return r}(()=>{const{performance:t}=st;if(!t||!t.now)return;const n=36e5,e=t.now(),r=Date.now(),i=t.timeOrigin?Math.abs(t.timeOrigin+e-r):n,o=i<n,u=t.timing&&t.timing.navigationStart,a="number"==typeof u?Math.abs(u+e-r):n;(o||a<n)&&(i<=a&&t.timeOrigin)})();const Ki="_sentrySpan";function Do(t,n){n?pd(t,Ki,n):delete t[Ki]}function Wo(t){return t[Ki]}const vd=100;class Xi{constructor(){this._notifyingListeners=!1,this._scopeListeners=[],this._eventProcessors=[],this._breadcrumbs=[],this._attachments=[],this._user={},this._tags={},this._extra={},this._contexts={},this._sdkProcessingMetadata={},this._propagationContext={traceId:Fo(),spanId:Bo()}}clone(){const t=new Xi;return t._breadcrumbs=[...this._breadcrumbs],t._tags={...this._tags},t._extra={...this._extra},t._contexts={...this._contexts},this._contexts.flags&&(t._contexts.flags={values:[...this._contexts.flags.values]}),t._user=this._user,t._level=this._level,t._session=this._session,t._transactionName=this._transactionName,t._fingerprint=this._fingerprint,t._eventProcessors=[...this._eventProcessors],t._requestSession=this._requestSession,t._attachments=[...this._attachments],t._sdkProcessingMetadata={...this._sdkProcessingMetadata},t._propagationContext={...this._propagationContext},t._client=this._client,t._lastEventId=this._lastEventId,Do(t,Wo(this)),t}setClient(t){this._client=t}setLastEventId(t){this._lastEventId=t}getClient(){return this._client}lastEventId(){return this._lastEventId}addScopeListener(t){this._scopeListeners.push(t)}addEventProcessor(t){return this._eventProcessors.push(t),this}setUser(t){return this._user=t||{email:void 0,id:void 0,ip_address:void 0,username:void 0},this._session&&dd(this._session,{user:t}),this._notifyScopeListeners(),this}getUser(){return this._user}getRequestSession(){return this._requestSession}setRequestSession(t){return this._requestSession=t,this}setTags(t){return this._tags={...this._tags,...t},this._notifyScopeListeners(),this}setTag(t,n){return this._tags={...this._tags,[t]:n},this._notifyScopeListeners(),this}setExtras(t){return this._extra={...this._extra,...t},this._notifyScopeListeners(),this}setExtra(t,n){return this._extra={...this._extra,[t]:n},this._notifyScopeListeners(),this}setFingerprint(t){return this._fingerprint=t,this._notifyScopeListeners(),this}setLevel(t){return this._level=t,this._notifyScopeListeners(),this}setTransactionName(t){return this._transactionName=t,this._notifyScopeListeners(),this}setContext(t,n){return null===n?delete this._contexts[t]:this._contexts[t]=n,this._notifyScopeListeners(),this}setSession(t){return t?this._session=t:delete this._session,this._notifyScopeListeners(),this}getSession(){return this._session}update(t){if(!t)return this;const n="function"==typeof t?t(this):t,[e,r]=n instanceof Ie?[n.getScopeData(),n.getRequestSession()]:cd(n)?[t,t.requestSession]:[],{tags:i,extra:o,user:u,contexts:a,level:s,fingerprint:c=[],propagationContext:f}=e||{};return this._tags={...this._tags,...i},this._extra={...this._extra,...o},this._contexts={...this._contexts,...a},u&&Object.keys(u).length&&(this._user=u),s&&(this._level=s),c.length&&(this._fingerprint=c),f&&(this._propagationContext=f),r&&(this._requestSession=r),this}clear(){return this._breadcrumbs=[],this._tags={},this._extra={},this._user={},this._contexts={},this._level=void 0,this._transactionName=void 0,this._fingerprint=void 0,this._requestSession=void 0,this._session=void 0,Do(this,void 0),this._attachments=[],this.setPropagationContext({traceId:Fo()}),this._notifyScopeListeners(),this}addBreadcrumb(t,n){const e="number"==typeof n?n:vd;if(e<=0)return this;const r={timestamp:Xo(),...t},i=this._breadcrumbs;return i.push(r),this._breadcrumbs=i.length>e?i.slice(-e):i,this._notifyScopeListeners(),this}getLastBreadcrumb(){return this._breadcrumbs[this._breadcrumbs.length-1]}clearBreadcrumbs(){return this._breadcrumbs=[],this._notifyScopeListeners(),this}addAttachment(t){return this._attachments.push(t),this}clearAttachments(){return this._attachments=[],this}getScopeData(){return{breadcrumbs:this._breadcrumbs,attachments:this._attachments,contexts:this._contexts,tags:this._tags,extra:this._extra,user:this._user,level:this._level,fingerprint:this._fingerprint||[],eventProcessors:this._eventProcessors,propagationContext:this._propagationContext,sdkProcessingMetadata:this._sdkProcessingMetadata,transactionName:this._transactionName,span:Wo(this)}}setSDKProcessingMetadata(t){return this._sdkProcessingMetadata=Jo(this._sdkProcessingMetadata,t,2),this}setPropagationContext(t){return this._propagationContext={spanId:Bo(),...t},this}getPropagationContext(){return this._propagationContext}captureException(t,n){const e=n&&n.event_id?n.event_id:Xt();if(!this._client)return Sr.warn("No client configured on scope - will not capture exception!"),e;const r=new Error("Sentry syntheticException");return this._client.captureException(t,{originalException:t,syntheticException:r,...n,event_id:e},this),e}captureMessage(t,n,e){const r=e&&e.event_id?e.event_id:Xt();if(!this._client)return Sr.warn("No client configured on scope - will not capture message!"),r;const i=new Error(t);return this._client.captureMessage(t,n,{originalException:t,syntheticException:i,...e,event_id:r},this),r}captureEvent(t,n){const e=n&&n.event_id?n.event_id:Xt();return this._client?(this._client.captureEvent(t,{...n,event_id:e},this),e):(Sr.warn("No client configured on scope - will not capture event!"),e)}_notifyScopeListeners(){this._notifyingListeners||(this._notifyingListeners=!0,this._scopeListeners.forEach((t=>{t(this)})),this._notifyingListeners=!1)}}const Ie=Xi;function wd(){return Yi("defaultCurrentScope",(()=>new Ie))}function md(){return Yi("defaultIsolationScope",(()=>new Ie))}class xd{constructor(t,n){let e,r;e=t||new Ie,r=n||new Ie,this._stack=[{scope:e}],this._isolationScope=r}withScope(t){const n=this._pushScope();let e;try{e=t(n)}catch(t){throw this._popScope(),t}return hd(e)?e.then((t=>(this._popScope(),t)),(t=>{throw this._popScope(),t})):(this._popScope(),e)}getClient(){return this.getStackTop().client}getScope(){return this.getStackTop().scope}getIsolationScope(){return this._isolationScope}getStackTop(){return this._stack[this._stack.length-1]}_pushScope(){const t=this.getScope().clone();return this._stack.push({client:this.getClient(),scope:t}),t}_popScope(){return!(this._stack.length<=1)&&!!this._stack.pop()}}function Jt(){const t=Vi(Zi());return t.stack=t.stack||new xd(wd(),md())}function Sd(t){return Jt().withScope(t)}function yd(t,n){const e=Jt();return e.withScope((()=>(e.getStackTop().scope=t,n(t))))}function No(t){return Jt().withScope((()=>t(Jt().getIsolationScope())))}function Ad(){return{withIsolationScope:No,withScope:Sd,withSetScope:yd,withSetIsolationScope:(t,n)=>No(n),getCurrentScope:()=>Jt().getScope(),getIsolationScope:()=>Jt().getIsolationScope()}}function Qo(t){const n=Vi(t);return n.acs?n.acs:Ad()}function ko(){return Qo(Zi()).getCurrentScope()}function Id(){return Qo(Zi()).getIsolationScope()}function Ed(t,n){return ko().captureException(t,void 0)}function Ld(t,n){const e={captureContext:n};return ko().captureMessage(t,void 0,e)}function Rd(t,n){Id().setExtra(t,n)}var mr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};const Td=(...t)=>{let n="";for(const e of t){if(e instanceof Error){const t=e;return Rd("exceptionMessage",n),void Ed(t)}if("object"!=typeof e)n+=e;else try{n+=" "+JSON.stringify(e)}catch{n+=" "+e}}Ld(n)},$o=["debug","info","warn","error"],Cd=(t,n)=>{const e=$o.indexOf(t);return $o.indexOf(n)>=e},xr=(t,n,e,...r)=>{Cd(n,t)&&console.log(`[${t}] ${e}`,...r)},bd=(t=!Yo()&&(null==window?void 0:window.localStorage.getItem("logger_lvl"))||"warn")=>{let n=t;return{debug:(t,...e)=>xr("debug",n,t,...e),info:(t,...e)=>xr("info",n,t,...e),warn:(t,...e)=>xr("warn",n,t,...e),error:(t,...e)=>(Td(t,...e),xr("error",n,t,...e)),setLevel:t=>{n=t},getLevel:()=>n}},jo=bd(),Od=({src:t,name:n=""})=>new Promise(((e,r)=>{const i=document.createElement("video");i.src=t;const o=()=>{const{duration:t,videoHeight:o,videoWidth:u,src:a}=i,s=id(n);(!t||!o||!u||!a)&&r(),e({src:a,name:s,width:u,height:o,duration:Math.floor(t)})},u=()=>{jo.warn("Failed to load video"),e(null)};return ud()&&i.load(),i.addEventListener("error",u),i.addEventListener("loadeddata",o),()=>{i.removeEventListener("error",u),i.removeEventListener("loadeddata",o)}})),Pd=t=>new Promise(((n,e)=>{const r=new Image,i=URL.createObjectURL(t);r.onload=()=>{n({width:r.naturalWidth,height:r.naturalHeight}),URL.revokeObjectURL(i)},r.onerror=()=>{jo.warn("Failed to load image"),e(null),URL.revokeObjectURL(i)},r.src=i})),Go=t=>{if(!t)return;const n="number"==typeof t?t:parseInt(t,10);if(isNaN(n))throw new Error("Can not get number from income argument");const e=n/1048576;return`${Math.floor(e)} MB`},Ud=async({media:t,config:n})=>{if(!n)return"Instance configuration is missing";const e={IMAGE:n.image_extensions,VIDEO:n.video_extensions,AUDIO:n.audio_extensions,DOCUMENT:n.doc_extensions},r=Ko(t.file.name)||"",i=Object.keys(e).find((t=>{var n;return null==(n=e[t])?void 0:n.includes(r)}));if(!i)return`Extenssion ${r} is not supported`;const o="VIDEO"===i;if("IMAGE"===i){const e=await Pd(t.file),r=t.file.size>n.image_size_limit,i=e&&Math.max(e.width,e.height)>n.image_resolution_limit,o=e&&e.width*e.height>n.image_matrix_limit;switch(!0){case r:return`Image is too big. Max size is ${Go(n.image_size_limit)}`;case i:return`Image resolution is too high. Max resolution is ${n.image_resolution_limit} pixels`;case o:return`The uploaded image exceeds the maximum size allowed. Please choose an image with smaller dimensions or reduce the resolution and try again. Max resolution is ${n.image_matrix_limit} pixels`}}if(o){const e=await Od({src:t.objectUrl}),r=e&&e.duration>n.video_duration_limit,i=e&&Math.max(e.width,e.height)>n.video_resolution_limit,o=t.file.size>n.video_size_limit,u=e&&e.width*e.height>n.video_matrix_limit;switch(!0){case r:return`Video is too long. Max duration is ${n.video_duration_limit} seconds`;case o:return`Video is too big. Max size is ${Go(n.video_size_limit)}`;case i:return`Video resolution is too high. Max resolution is ${n.video_resolution_limit} pixels`;case u:return`The uploaded video exceeds the maximum size allowed. Please choose a video with smaller dimensions or reduce the resolution and try again. Max resolution is ${n.image_matrix_limit} pixels`}}},Md=({config:t})=>{const[n]=Xg(),e=new AbortController,r=e.signal;return[async({media:e,tag:i,onError:o,onUpload:u})=>{var a;const s=Ko(e.file.name),c=await Ud({config:t,media:e});if(c)return zi.error(c),void(null==o||o());try{const t=await n({request1:{extension:s,tags:[i],meta:{name:e.file.name}}});if("error"in t)throw new Error(t.error);const o=null==(a=t.data)?void 0:a.uri;return await rd({url:o,method:"PUT",body:e.file,signal:r}),null==u||u(),t.data.upload.uploadId}catch(t){null==o||o(t),zi(`Could not upload file. ${t}`)}},()=>e.abort("Upload canceled")]};var Ho,ye={exports:{}},Fd=ye.exports;
|
|
1
|
+
import{api as qo,handleBasicResponse as xe,usePostApiV1UploadsMutation as Xg,useDeleteApiV1UploadsByIdMutation as Jg,usePostApiV1UploadsByIdMetaMutation as Qg}from"https://cdn.jsdelivr.net/npm/@wellesley/openapi@1.0.136";import{toast as zi}from"https://cdn.jsdelivr.net/npm/react-toastify@10.0.5/+esm";import{useSelector as qi}from"https://cdn.jsdelivr.net/npm/react-redux@9.1.0/+esm";import{useRef as kg,useState as jg,useEffect as nd}from"https://cdn.jsdelivr.net/npm/react@18.2.0/+esm";import{createSelector as Fn,createSlice as td}from"https://cdn.jsdelivr.net/npm/@reduxjs/toolkit@2.2.1/+esm";const ed=qo.enhanceEndpoints({endpoints:{postApiV1UploadsByIdMeta:{async onQueryStarted(t,{queryFulfilled:n}){await xe(n,"Updated")}},postApiV1UploadsList:{async onQueryStarted(t,{queryFulfilled:n}){await xe(n)}},deleteApiV1UploadsBatch:{async onQueryStarted(t,{queryFulfilled:n}){await xe(n,"Deleted")}},putApiV1UploadsByIdTags:{async onQueryStarted(t,{queryFulfilled:n}){await xe(n)}}}}),{usePostApiV1UploadsByIdMetaMutation:u0,usePostApiV1UploadsListMutation:s0,usePutApiV1UploadsByIdTagsMutation:o0,useDeleteApiV1UploadsBatchMutation:f0}=ed;var Vt=(t=>(t.done="done",t.inprogress="inprogress",t))(Vt||{}),Se=(t=>(t.image="image",t.video="video",t.audio="audio",t))(Se||{}),zo=(t=>(t.post="$post",t.album="$album",t.avatar="$avatar",t.header="$header",t))(zo||{});const Ko=t=>{const n=t.toLowerCase().match(/\.([a-zA-Z0-9]{2,4})(\?|$)+/);return n?n[1]:void 0},rd=async({url:t,...n})=>{const e=await fetch(t,n);if(!e.ok)throw new Error(e.statusText);if("PUT"===n.method)return;const r=await e.json(),i=r;if(i.errorCode)throw new Error(i.message);return r},id=t=>t.replace(/\.[^.]*$/,""),Yo=()=>"object"!=typeof window,ud=()=>!Yo()&&/iPhone|iPod|iPad/gi.test(window.navigator.userAgent),Ae="8.48.0",st=globalThis;function Yi(t,n,e){const r=st,i=r.__SENTRY__=r.__SENTRY__||{},o=i[Ae]=i[Ae]||{};return o[t]||(o[t]=n())}const Zo=typeof __SENTRY_DEBUG__>"u"||__SENTRY_DEBUG__,sd="Sentry Logger ",Uo=["debug","info","warn","error","log","assert","trace"],Mo={};function od(t){if(!("console"in st))return t();const n=st.console,e={},r=Object.keys(Mo);r.forEach((t=>{const r=Mo[t];e[t]=n[t],n[t]=r}));try{return t()}finally{r.forEach((t=>{n[t]=e[t]}))}}function fd(){let t=!1;const n={enable:()=>{t=!0},disable:()=>{t=!1},isEnabled:()=>t};return Zo?Uo.forEach((e=>{n[e]=(...n)=>{t&&od((()=>{st.console[e](`${sd}[${e}]:`,...n)}))}})):Uo.forEach((t=>{n[t]=()=>{}})),n}const Sr=Yi("logger",fd);function Zi(){return Vi(st),st}function Vi(t){const n=t.__SENTRY__=t.__SENTRY__||{};return n.version=n.version||Ae,n[Ae]=n[Ae]||{}}const ad=Object.prototype.toString;function ld(t,n){return ad.call(t)===`[object ${n}]`}function cd(t){return ld(t,"Object")}function hd(t){return!(!t||!t.then||"function"!=typeof t.then)}function pd(t,n,e){try{Object.defineProperty(t,n,{value:e,writable:!0,configurable:!0})}catch{Zo&&Sr.log(`Failed to add non-enumerable property "${n}" to object`,t)}}const Vo=1e3;function Xo(){return Date.now()/Vo}function _d(){const{performance:t}=st;if(!t||!t.now)return Xo;const n=Date.now()-t.now(),e=null==t.timeOrigin?n:t.timeOrigin;return()=>(e+t.now())/Vo}const gd=_d();function Xt(){const t=st,n=t.crypto||t.msCrypto;let e=()=>16*Math.random();try{if(n&&n.randomUUID)return n.randomUUID().replace(/-/g,"");n&&n.getRandomValues&&(e=()=>{const t=new Uint8Array(1);return n.getRandomValues(t),t[0]})}catch{}return"10000000100040008000100000000000".replace(/[018]/g,(t=>(t^(15&e())>>t/4).toString(16)))}function dd(t,n={}){if(n.user&&(!t.ipAddress&&n.user.ip_address&&(t.ipAddress=n.user.ip_address),!t.did&&!n.did&&(t.did=n.user.id||n.user.email||n.user.username)),t.timestamp=n.timestamp||gd(),n.abnormal_mechanism&&(t.abnormal_mechanism=n.abnormal_mechanism),n.ignoreDuration&&(t.ignoreDuration=n.ignoreDuration),n.sid&&(t.sid=32===n.sid.length?n.sid:Xt()),void 0!==n.init&&(t.init=n.init),!t.did&&n.did&&(t.did=`${n.did}`),"number"==typeof n.started&&(t.started=n.started),t.ignoreDuration)t.duration=void 0;else if("number"==typeof n.duration)t.duration=n.duration;else{const n=t.timestamp-t.started;t.duration=n>=0?n:0}n.release&&(t.release=n.release),n.environment&&(t.environment=n.environment),!t.ipAddress&&n.ipAddress&&(t.ipAddress=n.ipAddress),!t.userAgent&&n.userAgent&&(t.userAgent=n.userAgent),"number"==typeof n.errors&&(t.errors=n.errors),n.status&&(t.status=n.status)}function Fo(){return Xt()}function Bo(){return Xt().substring(16)}function Jo(t,n,e=2){if(!n||"object"!=typeof n||e<=0)return n;if(t&&n&&0===Object.keys(n).length)return t;const r={...t};for(const t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=Jo(r[t],n[t],e-1));return r}(()=>{const{performance:t}=st;if(!t||!t.now)return;const n=36e5,e=t.now(),r=Date.now(),i=t.timeOrigin?Math.abs(t.timeOrigin+e-r):n,o=i<n,u=t.timing&&t.timing.navigationStart,a="number"==typeof u?Math.abs(u+e-r):n;(o||a<n)&&(i<=a&&t.timeOrigin)})();const Ki="_sentrySpan";function Do(t,n){n?pd(t,Ki,n):delete t[Ki]}function Wo(t){return t[Ki]}const vd=100;class Xi{constructor(){this._notifyingListeners=!1,this._scopeListeners=[],this._eventProcessors=[],this._breadcrumbs=[],this._attachments=[],this._user={},this._tags={},this._extra={},this._contexts={},this._sdkProcessingMetadata={},this._propagationContext={traceId:Fo(),spanId:Bo()}}clone(){const t=new Xi;return t._breadcrumbs=[...this._breadcrumbs],t._tags={...this._tags},t._extra={...this._extra},t._contexts={...this._contexts},this._contexts.flags&&(t._contexts.flags={values:[...this._contexts.flags.values]}),t._user=this._user,t._level=this._level,t._session=this._session,t._transactionName=this._transactionName,t._fingerprint=this._fingerprint,t._eventProcessors=[...this._eventProcessors],t._requestSession=this._requestSession,t._attachments=[...this._attachments],t._sdkProcessingMetadata={...this._sdkProcessingMetadata},t._propagationContext={...this._propagationContext},t._client=this._client,t._lastEventId=this._lastEventId,Do(t,Wo(this)),t}setClient(t){this._client=t}setLastEventId(t){this._lastEventId=t}getClient(){return this._client}lastEventId(){return this._lastEventId}addScopeListener(t){this._scopeListeners.push(t)}addEventProcessor(t){return this._eventProcessors.push(t),this}setUser(t){return this._user=t||{email:void 0,id:void 0,ip_address:void 0,username:void 0},this._session&&dd(this._session,{user:t}),this._notifyScopeListeners(),this}getUser(){return this._user}getRequestSession(){return this._requestSession}setRequestSession(t){return this._requestSession=t,this}setTags(t){return this._tags={...this._tags,...t},this._notifyScopeListeners(),this}setTag(t,n){return this._tags={...this._tags,[t]:n},this._notifyScopeListeners(),this}setExtras(t){return this._extra={...this._extra,...t},this._notifyScopeListeners(),this}setExtra(t,n){return this._extra={...this._extra,[t]:n},this._notifyScopeListeners(),this}setFingerprint(t){return this._fingerprint=t,this._notifyScopeListeners(),this}setLevel(t){return this._level=t,this._notifyScopeListeners(),this}setTransactionName(t){return this._transactionName=t,this._notifyScopeListeners(),this}setContext(t,n){return null===n?delete this._contexts[t]:this._contexts[t]=n,this._notifyScopeListeners(),this}setSession(t){return t?this._session=t:delete this._session,this._notifyScopeListeners(),this}getSession(){return this._session}update(t){if(!t)return this;const n="function"==typeof t?t(this):t,[e,r]=n instanceof Ie?[n.getScopeData(),n.getRequestSession()]:cd(n)?[t,t.requestSession]:[],{tags:i,extra:o,user:u,contexts:a,level:s,fingerprint:c=[],propagationContext:f}=e||{};return this._tags={...this._tags,...i},this._extra={...this._extra,...o},this._contexts={...this._contexts,...a},u&&Object.keys(u).length&&(this._user=u),s&&(this._level=s),c.length&&(this._fingerprint=c),f&&(this._propagationContext=f),r&&(this._requestSession=r),this}clear(){return this._breadcrumbs=[],this._tags={},this._extra={},this._user={},this._contexts={},this._level=void 0,this._transactionName=void 0,this._fingerprint=void 0,this._requestSession=void 0,this._session=void 0,Do(this,void 0),this._attachments=[],this.setPropagationContext({traceId:Fo()}),this._notifyScopeListeners(),this}addBreadcrumb(t,n){const e="number"==typeof n?n:vd;if(e<=0)return this;const r={timestamp:Xo(),...t},i=this._breadcrumbs;return i.push(r),this._breadcrumbs=i.length>e?i.slice(-e):i,this._notifyScopeListeners(),this}getLastBreadcrumb(){return this._breadcrumbs[this._breadcrumbs.length-1]}clearBreadcrumbs(){return this._breadcrumbs=[],this._notifyScopeListeners(),this}addAttachment(t){return this._attachments.push(t),this}clearAttachments(){return this._attachments=[],this}getScopeData(){return{breadcrumbs:this._breadcrumbs,attachments:this._attachments,contexts:this._contexts,tags:this._tags,extra:this._extra,user:this._user,level:this._level,fingerprint:this._fingerprint||[],eventProcessors:this._eventProcessors,propagationContext:this._propagationContext,sdkProcessingMetadata:this._sdkProcessingMetadata,transactionName:this._transactionName,span:Wo(this)}}setSDKProcessingMetadata(t){return this._sdkProcessingMetadata=Jo(this._sdkProcessingMetadata,t,2),this}setPropagationContext(t){return this._propagationContext={spanId:Bo(),...t},this}getPropagationContext(){return this._propagationContext}captureException(t,n){const e=n&&n.event_id?n.event_id:Xt();if(!this._client)return Sr.warn("No client configured on scope - will not capture exception!"),e;const r=new Error("Sentry syntheticException");return this._client.captureException(t,{originalException:t,syntheticException:r,...n,event_id:e},this),e}captureMessage(t,n,e){const r=e&&e.event_id?e.event_id:Xt();if(!this._client)return Sr.warn("No client configured on scope - will not capture message!"),r;const i=new Error(t);return this._client.captureMessage(t,n,{originalException:t,syntheticException:i,...e,event_id:r},this),r}captureEvent(t,n){const e=n&&n.event_id?n.event_id:Xt();return this._client?(this._client.captureEvent(t,{...n,event_id:e},this),e):(Sr.warn("No client configured on scope - will not capture event!"),e)}_notifyScopeListeners(){this._notifyingListeners||(this._notifyingListeners=!0,this._scopeListeners.forEach((t=>{t(this)})),this._notifyingListeners=!1)}}const Ie=Xi;function wd(){return Yi("defaultCurrentScope",(()=>new Ie))}function md(){return Yi("defaultIsolationScope",(()=>new Ie))}class xd{constructor(t,n){let e,r;e=t||new Ie,r=n||new Ie,this._stack=[{scope:e}],this._isolationScope=r}withScope(t){const n=this._pushScope();let e;try{e=t(n)}catch(t){throw this._popScope(),t}return hd(e)?e.then((t=>(this._popScope(),t)),(t=>{throw this._popScope(),t})):(this._popScope(),e)}getClient(){return this.getStackTop().client}getScope(){return this.getStackTop().scope}getIsolationScope(){return this._isolationScope}getStackTop(){return this._stack[this._stack.length-1]}_pushScope(){const t=this.getScope().clone();return this._stack.push({client:this.getClient(),scope:t}),t}_popScope(){return!(this._stack.length<=1)&&!!this._stack.pop()}}function Jt(){const t=Vi(Zi());return t.stack=t.stack||new xd(wd(),md())}function Sd(t){return Jt().withScope(t)}function yd(t,n){const e=Jt();return e.withScope((()=>(e.getStackTop().scope=t,n(t))))}function No(t){return Jt().withScope((()=>t(Jt().getIsolationScope())))}function Ad(){return{withIsolationScope:No,withScope:Sd,withSetScope:yd,withSetIsolationScope:(t,n)=>No(n),getCurrentScope:()=>Jt().getScope(),getIsolationScope:()=>Jt().getIsolationScope()}}function Qo(t){const n=Vi(t);return n.acs?n.acs:Ad()}function ko(){return Qo(Zi()).getCurrentScope()}function Id(){return Qo(Zi()).getIsolationScope()}function Ed(t,n){return ko().captureException(t,void 0)}function Ld(t,n){const e={captureContext:n};return ko().captureMessage(t,void 0,e)}function Rd(t,n){Id().setExtra(t,n)}var mr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};const Td=(...t)=>{let n="";for(const e of t){if(e instanceof Error){const t=e;return Rd("exceptionMessage",n),void Ed(t)}if("object"!=typeof e)n+=e;else try{n+=" "+JSON.stringify(e)}catch{n+=" "+e}}Ld(n)},$o=["debug","info","warn","error"],Cd=(t,n)=>{const e=$o.indexOf(t);return $o.indexOf(n)>=e},xr=(t,n,e,...r)=>{Cd(n,t)&&console.log(`[${t}] ${e}`,...r)},bd=(t=!Yo()&&(null==window?void 0:window.localStorage.getItem("logger_lvl"))||"warn")=>{let n=t;return{debug:(t,...e)=>xr("debug",n,t,...e),info:(t,...e)=>xr("info",n,t,...e),warn:(t,...e)=>xr("warn",n,t,...e),error:(t,...e)=>(Td(t,...e),xr("error",n,t,...e)),setLevel:t=>{n=t},getLevel:()=>n}},jo=bd(),Od=({src:t,name:n=""})=>new Promise(((e,r)=>{const i=document.createElement("video");i.src=t;const o=()=>{const{duration:t,videoHeight:o,videoWidth:u,src:a}=i,s=id(n);(!t||!o||!u||!a)&&r(),e({src:a,name:s,width:u,height:o,duration:Math.floor(t)})},u=()=>{jo.warn("Failed to load video"),e(null)};return ud()&&i.load(),i.addEventListener("error",u),i.addEventListener("loadeddata",o),()=>{i.removeEventListener("error",u),i.removeEventListener("loadeddata",o)}})),Pd=t=>new Promise(((n,e)=>{const r=new Image,i=URL.createObjectURL(t);r.onload=()=>{n({width:r.naturalWidth,height:r.naturalHeight}),URL.revokeObjectURL(i)},r.onerror=()=>{jo.warn("Failed to load image"),e(null),URL.revokeObjectURL(i)},r.src=i})),Go=t=>{if(!t)return;const n="number"==typeof t?t:parseInt(t,10);if(isNaN(n))throw new Error("Can not get number from income argument");const e=n/1048576;return`${Math.floor(e)} MB`},Ud=async({media:t,config:n})=>{if(!n)return"Instance configuration is missing";const e={IMAGE:n.image_extensions,VIDEO:n.video_extensions,AUDIO:n.audio_extensions,DOCUMENT:n.doc_extensions},r=Ko(t.file.name)||"",i=Object.keys(e).find((t=>{var n;return null==(n=e[t])?void 0:n.includes(r)}));if(!i)return`Extenssion ${r} is not supported`;const o="VIDEO"===i;if("IMAGE"===i){const e=await Pd(t.file),r=t.file.size>n.image_size_limit,i=e&&Math.max(e.width,e.height)>n.image_resolution_limit,o=e&&e.width*e.height>n.image_matrix_limit;switch(!0){case r:return`Image is too big. Max size is ${Go(n.image_size_limit)}`;case i:return`Image resolution is too high. Max resolution is ${n.image_resolution_limit} pixels`;case o:return`The uploaded image exceeds the maximum size allowed. Please choose an image with smaller dimensions or reduce the resolution and try again. Max resolution is ${n.image_matrix_limit} pixels`}}if(o){const e=await Od({src:t.objectUrl}),r=e&&e.duration>n.video_duration_limit,i=e&&Math.max(e.width,e.height)>n.video_resolution_limit,o=t.file.size>n.video_size_limit,u=e&&e.width*e.height>n.video_matrix_limit;switch(!0){case r:return`Video is too long. Max duration is ${n.video_duration_limit} seconds`;case o:return`Video is too big. Max size is ${Go(n.video_size_limit)}`;case i:return`Video resolution is too high. Max resolution is ${n.video_resolution_limit} pixels`;case u:return`The uploaded video exceeds the maximum size allowed. Please choose a video with smaller dimensions or reduce the resolution and try again. Max resolution is ${n.image_matrix_limit} pixels`}}},Md=({config:t})=>{const[n]=Xg(),e=new AbortController,r=e.signal;return[async({media:e,tag:i,onError:o,onUpload:u})=>{var a;const s=Ko(e.file.name),c=await Ud({config:t,media:e});if(c)return zi.error(c),void(null==o||o());try{const t=await n({request1:{extension:s,tags:[i],meta:{name:e.file.name}}});if("error"in t)throw new Error(t.error);const o=null==(a=t.data)?void 0:a.uri;return await rd({url:o,method:"PUT",body:e.file,signal:r}),null==u||u(),t.data.upload.uploadId}catch(t){null==o||o(t),zi(`Could not upload file. ${t}`)}},()=>e.abort("Upload canceled")]};var Ho,ye={exports:{}},Fd=ye.exports;
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Lodash <https://lodash.com/>
|