Build 533169stable
Module 428539
2,582 characters · in 30a277b9d32d70b1.jsDependencies
Source Raw
function(e,t,n){n.d(t,{A:()=>p});var i=n(73153),l=n(77468),a=n(573648),r=n(882997),s=n(962173),o=n(203982),d=n(636401),c=n(90924),u=n(629471),A=n(613057),h=n(652215),_=n(360469),m=n(818348);let g=new Set([_.AM,_.eK]),p={[m.e$.GET_PROVIDER_ACCESS_TOKEN]:{scope:{[A.sm.ANY]:[A.VH]},validation:e=>(0,u.A)(e).required().keys({provider:e.string().required(),connection_redirect:e.string()}),handler:e=>{let{socket:t,args:{provider:n,connection_redirect:u}}=e;(0,c.lG)(t.transport);let A=(0,c.D2)(t.application),_=a.A.get(n);if(null==_)throw new d.A({errorCode:m.Lw.INVALID_PROVIDER},`Platform not found for provider "${n}"`);if(n===h.fg2.AMAZON_MUSIC){if(!g.has(A))throw new d.A({errorCode:m.Lw.UNAUTHORIZED_FOR_APPLICATION},"Command not available for this application")}else throw new d.A({errorCode:m.Lw.UNAUTHORIZED_FOR_APPLICATION},"Command not available for this application");return new Promise(async(e,t)=>{let a=s.A.getAccount(null,n);if(null==a){function c(t){if(null==_)return;let n=(t.accounts??[]).find(e=>e.type===_.type);null!=n&&(e({access_token:n.access_token}),g())}function A(){t(new d.A({errorCode:m.Lw.OAUTH2_ERROR},`OAuth2 setup for "${n}" failed`)),g()}function g(){i.h.unsubscribe("USER_CONNECTIONS_UPDATE",c),o._.unsubscribe(h.jej.CONNECTIONS_CALLBACK_ERROR,A)}i.h.subscribe("USER_CONNECTIONS_UPDATE",c),o._.subscribe(h.jej.CONNECTIONS_CALLBACK_ERROR,A),(0,r.A)({platformType:_.type,location:h.ThZ.ACTIVITY_RPC,successRedirect:u})}else try{let t=await l.A.refreshAccessToken(_.type,a.id);if(null==t)throw new d.A({errorCode:m.Lw.OAUTH2_ERROR},"Refreshing access token did not return a new access token");e({access_token:t})}catch(e){t(e)}})}},[m.e$.MAYBE_GET_PROVIDER_ACCESS_TOKEN]:{scope:{[A.sm.ANY]:[A.VH]},validation:e=>(0,u.A)(e).required().keys({provider:e.string().required()}),handler:async e=>{let{socket:t,args:{provider:n}}=e;(0,c.lG)(t.transport);let i=(0,c.D2)(t.application),r=a.A.get(n);if(null==r)throw new d.A({errorCode:m.Lw.INVALID_PROVIDER},`Platform not found for provider "${n}"`);if(n===h.fg2.AMAZON_MUSIC){if(!g.has(i))throw new d.A({errorCode:m.Lw.UNAUTHORIZED_FOR_APPLICATION},"Command not available for this application")}else throw new d.A({errorCode:m.Lw.UNAUTHORIZED_FOR_APPLICATION},"Command not available for this application");let o=s.A.getAccount(null,n);if(null==o)throw new d.A({errorCode:m.Lw.NO_CONNECTION_FOUND},"No connection found");let u=await l.A.refreshAccessToken(r.type,o.id);if(null==u)throw new d.A({errorCode:m.Lw.OAUTH2_ERROR},"Refreshing access token did not return a new access token");return{access_token:u}}}}}