psn-api
Version:
A well-tested library that lets you get trophy, user, and game data from the PlayStation Network.
3 lines (2 loc) • 22.2 kB
JavaScript
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var r=e(require("isomorphic-unfetch"));function t(){t=function(){return e};var e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(e,r,t){e[r]=t.value},a="function"==typeof Symbol?Symbol:{},i=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",s=a.toStringTag||"@@toStringTag";function c(e,r,t){return Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}),e[r]}try{c({},"")}catch(e){c=function(e,r,t){return e[r]=t}}function p(e,r,t,n){var a=Object.create((r&&r.prototype instanceof h?r:h).prototype),i=new _(n||[]);return o(a,"_invoke",{value:k(e,t,i)}),a}function l(e,r,t){try{return{type:"normal",arg:e.call(r,t)}}catch(e){return{type:"throw",arg:e}}}e.wrap=p;var f={};function h(){}function d(){}function v(){}var m={};c(m,i,(function(){return this}));var y=Object.getPrototypeOf,x=y&&y(y(O([])));x&&x!==r&&n.call(x,i)&&(m=x);var w=v.prototype=h.prototype=Object.create(m);function g(e){["next","throw","return"].forEach((function(r){c(e,r,(function(e){return this._invoke(r,e)}))}))}function b(e,r){function t(o,a,i,u){var s=l(e[o],e,a);if("throw"!==s.type){var c=s.arg,p=c.value;return p&&"object"==typeof p&&n.call(p,"__await")?r.resolve(p.__await).then((function(e){t("next",e,i,u)}),(function(e){t("throw",e,i,u)})):r.resolve(p).then((function(e){c.value=e,i(c)}),(function(e){return t("throw",e,i,u)}))}u(s.arg)}var a;o(this,"_invoke",{value:function(e,n){function o(){return new r((function(r,o){t(e,n,r,o)}))}return a=a?a.then(o,o):o()}})}function k(e,r,t){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(t.method=o,t.arg=a;;){var i=t.delegate;if(i){var u=T(i,t);if(u){if(u===f)continue;return u}}if("next"===t.method)t.sent=t._sent=t.arg;else if("throw"===t.method){if("suspendedStart"===n)throw n="completed",t.arg;t.dispatchException(t.arg)}else"return"===t.method&&t.abrupt("return",t.arg);n="executing";var s=l(e,r,t);if("normal"===s.type){if(n=t.done?"completed":"suspendedYield",s.arg===f)continue;return{value:s.arg,done:t.done}}"throw"===s.type&&(n="completed",t.method="throw",t.arg=s.arg)}}}function T(e,r){var t=r.method,n=e.iterator[t];if(void 0===n)return r.delegate=null,"throw"===t&&e.iterator.return&&(r.method="return",r.arg=void 0,T(e,r),"throw"===r.method)||"return"!==t&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+t+"' method")),f;var o=l(n,e.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,f;var a=o.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,f):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,f)}function I(e){var r={tryLoc:e[0]};1 in e&&(r.catchLoc=e[1]),2 in e&&(r.finallyLoc=e[2],r.afterLoc=e[3]),this.tryEntries.push(r)}function E(e){var r=e.completion||{};r.type="normal",delete r.arg,e.completion=r}function _(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(I,this),this.reset(!0)}function O(e){if(e){var r=e[i];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var t=-1,o=function r(){for(;++t<e.length;)if(n.call(e,t))return r.value=e[t],r.done=!1,r;return r.value=void 0,r.done=!0,r};return o.next=o}}return{next:S}}function S(){return{value:void 0,done:!0}}return d.prototype=v,o(w,"constructor",{value:v,configurable:!0}),o(v,"constructor",{value:d,configurable:!0}),d.displayName=c(v,s,"GeneratorFunction"),e.isGeneratorFunction=function(e){var r="function"==typeof e&&e.constructor;return!!r&&(r===d||"GeneratorFunction"===(r.displayName||r.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,v):(e.__proto__=v,c(e,s,"GeneratorFunction")),e.prototype=Object.create(w),e},e.awrap=function(e){return{__await:e}},g(b.prototype),c(b.prototype,u,(function(){return this})),e.AsyncIterator=b,e.async=function(r,t,n,o,a){void 0===a&&(a=Promise);var i=new b(p(r,t,n,o),a);return e.isGeneratorFunction(t)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},g(w),c(w,s,"Generator"),c(w,i,(function(){return this})),c(w,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var r=Object(e),t=[];for(var n in r)t.push(n);return t.reverse(),function e(){for(;t.length;){var n=t.pop();if(n in r)return e.value=n,e.done=!1,e}return e.done=!0,e}},e.values=O,_.prototype={constructor:_,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function t(t,n){return i.type="throw",i.arg=e,r.next=t,n&&(r.method="next",r.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return t("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return t(a.catchLoc,!0);if(this.prev<a.finallyLoc)return t(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return t(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return t(a.finallyLoc)}}}},abrupt:function(e,r){for(var t=this.tryEntries.length-1;t>=0;--t){var o=this.tryEntries[t];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=r&&r<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=r,a?(this.method="next",this.next=a.finallyLoc,f):this.complete(i)},complete:function(e,r){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&r&&(this.next=r),f},finish:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.finallyLoc===e)return this.complete(t.completion,t.afterLoc),E(t),f}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.tryLoc===e){var n=t.completion;if("throw"===n.type){var o=n.arg;E(t)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,t){return this.delegate={iterator:O(e),resultName:r,nextLoc:t},"next"===this.method&&(this.arg=void 0),f}},e}function n(e,r,t,n,o,a,i){try{var u=e[a](i),s=u.value}catch(e){return void t(e)}u.done?r(s):Promise.resolve(s).then(n,o)}function o(e){return function(){var r=this,t=arguments;return new Promise((function(o,a){var i=e.apply(r,t);function u(e){n(i,o,a,u,s,"next",e)}function s(e){n(i,o,a,u,s,"throw",e)}u(void 0)}))}}function a(){return a=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},a.apply(this,arguments)}function i(e,r){if(null==e)return{};var t,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)r.indexOf(t=a[n])>=0||(o[t]=e[t]);return o}var u,s=function(){var e=o(t().mark((function e(n){var o,a;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=3,r.default("https://ca.account.sony.com/api/authz/v3/oauth/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Authorization:"Basic MDk1MTUxNTktNzIzNy00MzcwLTliNDAtMzgwNmU2N2MwODkxOnVjUGprYTV0bnRCMktxc1A="},body:new URLSearchParams({code:n,redirect_uri:"com.scee.psxandroid.scecompcall://redirect",grant_type:"authorization_code",token_format:"jwt"}).toString()});case 3:return o=e.sent,e.next=6,o.json();case 6:return e.abrupt("return",{accessToken:(a=e.sent).access_token,expiresIn:a.expires_in,idToken:a.id_token,refreshToken:a.refresh_token,refreshTokenExpiresIn:a.refresh_token_expires_in,scope:a.scope,tokenType:a.token_type});case 8:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}(),c=s,p=function(){var e=o(t().mark((function e(n){var o,a,i,u,s,c;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=new URLSearchParams({access_type:"offline",client_id:"09515159-7237-4370-9b40-3806e67c0891",redirect_uri:"com.scee.psxandroid.scecompcall://redirect",response_type:"code",scope:"psn:mobile.v2.core psn:clientapp"}).toString(),i="https://ca.account.sony.com/api/authz/v3/oauth/authorize?"+a,e.next=4,r.default(i,{headers:{Cookie:"npsso="+n},redirect:"manual"});case 4:if((u=e.sent.headers).has("location")&&null!=(o=u.get("location"))&&o.includes("?code=")){e.next=8;break}throw new Error("\n There was a problem retrieving your PSN access code. Is your NPSSO code valid?\n To get a new NPSSO code, visit https://ca.account.sony.com/api/v1/ssocookie.\n ");case 8:return s=u.get("location"),c=new URLSearchParams(s.split("redirect/")[1]),e.abrupt("return",c.get("code"));case 11:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}(),l=p,f=function(){var e=o(t().mark((function e(n){var o,a;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=3,r.default("https://ca.account.sony.com/api/authz/v3/oauth/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Authorization:"Basic MDk1MTUxNTktNzIzNy00MzcwLTliNDAtMzgwNmU2N2MwODkxOnVjUGprYTV0bnRCMktxc1A="},body:new URLSearchParams({refresh_token:n,grant_type:"refresh_token",token_format:"jwt",scope:"psn:mobile.v2.core psn:clientapp"}).toString()});case 3:return o=e.sent,e.next=6,o.json();case 6:return e.abrupt("return",{accessToken:(a=e.sent).access_token,expiresIn:a.expires_in,idToken:a.id_token,refreshToken:a.refresh_token,refreshTokenExpiresIn:a.refresh_token_expires_in,scope:a.scope,tokenType:a.token_type});case 8:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}(),h=function(){var e=o(t().mark((function e(n,o,i){var u,s;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,r.default(n.url,{method:null!=(u=null==n?void 0:n.method)?u:"GET",headers:a({Authorization:"Bearer "+o.accessToken,"Content-Type":"application/json"},null==n?void 0:n.headers),body:JSON.stringify(i)});case 2:return s=e.sent,e.next=5,s.json();case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}}),e)})));return function(r,t,n){return e.apply(this,arguments)}}(),d=function(){var e=o(t().mark((function e(r,n){var o,a,i,u,s,c,p;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===n&&(n={}),i=void 0===(a=(o=n).limit)?50:a,s=void 0===(u=o.categories)?["ps4_game","ps5_native_game"]:u,(c=new URL("https://web.np.playstation.com/api/graphql/v1/op")).searchParams.set("operationName","getUserGameList"),c.searchParams.set("variables",JSON.stringify({limit:i,categories:s.join(",")})),c.searchParams.set("extensions",JSON.stringify({persistedQuery:{version:1,sha256Hash:"e780a6d8b921ef0c59ec01ea5c5255671272ca0d819edb61320914cf7a78b3ae"}})),e.next=8,h({url:c.toString()},r);case 8:if((p=e.sent).data&&p.data.gameLibraryTitlesRetrieve){e.next=11;break}throw new Error(JSON.stringify(p));case 11:return e.abrupt("return",p);case 12:case"end":return e.stop()}}),e)})));return function(r,t){return e.apply(this,arguments)}}();exports.TrophyRarity=void 0,(u=exports.TrophyRarity||(exports.TrophyRarity={}))[u.UltraRare=0]="UltraRare",u[u.VeryRare=1]="VeryRare",u[u.Rare=2]="Rare",u[u.Common=3]="Common";var v=["headerOverrides"],m=function(e,r,t,n){void 0===t&&(t={}),void 0===n&&(n={});for(var o=i(t,v),u=(e+"/"+r).replace(/([^:]\/)\/+/g,"$1"),s={},c=0,p=Object.entries(a({},n,o));c<p.length;c++){var l=p[c],f=l[0],h=l[1];u.includes(":"+f)?u=u.replace(":"+f,String(h)):void 0!==h&&(s[f]=String(h))}var d=new URLSearchParams(s).toString();return d.length>0?u+"?"+d:u},y=function(){var e=o(t().mark((function e(r,n,o){var a;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=m("https://m.np.playstation.com/api/search","/v1/universalSearch"),e.next=3,h({url:a,method:"POST"},r,{searchTerm:n,domainRequests:[{domain:o}]});case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}}),e)})));return function(r,t,n){return e.apply(this,arguments)}}(),x="https://m.np.playstation.com/api/trophy",w=function(){var e=o(t().mark((function e(r,n,o,a){var i;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=m(x,"/v1/npCommunicationIds/:npCommunicationId/trophyGroups/:trophyGroupId/trophies",a,{npCommunicationId:n,trophyGroupId:o}),e.next=3,h({url:i,headers:null==a?void 0:a.headerOverrides},r);case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}}),e)})));return function(r,t,n,o){return e.apply(this,arguments)}}(),g=function(){var e=o(t().mark((function e(r,n,o){var a;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=m(x,"/v1/npCommunicationIds/:npCommunicationId/trophyGroups",o,{npCommunicationId:n}),e.next=3,h({url:a,headers:null==o?void 0:o.headerOverrides},r);case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}}),e)})));return function(r,t,n){return e.apply(this,arguments)}}(),b=function(){var e=o(t().mark((function e(r,n,o){var a;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=m(x,"/v1/users/:accountId/trophyTitles",o,{accountId:n}),e.next=3,h({url:a,headers:null==o?void 0:o.headerOverrides},r);case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}}),e)})));return function(r,t,n){return e.apply(this,arguments)}}(),k=function(){var e=o(t().mark((function e(r,n,o,a,i){var u,s,c,p;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return u=m(x,"/v1/users/:accountId/npCommunicationIds/:npCommunicationId/trophyGroups/:trophyGroupId/trophies",i,{accountId:n,npCommunicationId:o,trophyGroupId:a}),e.next=3,h({url:u,headers:null==i?void 0:i.headerOverrides},r);case 3:if(null==(s=e.sent)||!s.error){e.next=6;break}throw new Error(null!=(c=null==s||null==(p=s.error)?void 0:p.message)?c:"Unexpected Error");case 6:return e.abrupt("return",s);case 7:case"end":return e.stop()}}),e)})));return function(r,t,n,o,a){return e.apply(this,arguments)}}(),T=["headerOverrides"],I=function(){var e=o(t().mark((function e(r,n,o){var u,s,c;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return u=o.headerOverrides,s=i(o,T),c=m(x,"/v1/users/:accountId/titles/trophyTitles",{},a({accountId:n},s)),e.next=4,h({url:c,headers:u},r);case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e)})));return function(r,t,n){return e.apply(this,arguments)}}(),E=function(){var e=o(t().mark((function e(r,n,o,a){var i,u,s,c;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=m(x,"/v1/users/:accountId/npCommunicationIds/:npCommunicationId/trophyGroups",a,{accountId:n,npCommunicationId:o}),e.next=3,h({url:i,headers:null==a?void 0:a.headerOverrides},r);case 3:if(null==(u=e.sent)||!u.error){e.next=6;break}throw new Error(null!=(s=null==u||null==(c=u.error)?void 0:c.message)?s:"Unexpected Error");case 6:return e.abrupt("return",u);case 7:case"end":return e.stop()}}),e)})));return function(r,t,n,o){return e.apply(this,arguments)}}(),_=function(){var e=o(t().mark((function e(r,n,o){var a;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=m(x,"/v1/users/:accountId/trophySummary",o,{accountId:n}),e.next=3,h({url:a,headers:null==o?void 0:o.headerOverrides},r);case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}}),e)})));return function(r,t,n){return e.apply(this,arguments)}}(),O="https://m.np.playstation.com/api/userProfile/v1/internal/users",S=function(){var e=o(t().mark((function e(r,n){var o,i,u,s;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=m("https://dms.api.playstation.com/api","/v1/devices/accounts/:accountId",a({},n,{includeFields:"device,systemData",platform:"PS5,PS4,PS3,PSVita"}),{accountId:"me"}),e.next=4,h({url:o},r);case 4:if(null==(i=e.sent)||!i.error){e.next=7;break}throw new Error(null!=(u=null==i||null==(s=i.error)?void 0:s.message)?u:"Unexpected Error");case 7:return e.abrupt("return",i);case 8:case"end":return e.stop()}}),e)})));return function(r,t){return e.apply(this,arguments)}}(),P=function(){var e=o(t().mark((function e(r,n,o){var a,i,u,s;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=m(O,"/:accountId/basicPresences?type=primary",o,{accountId:n}),e.next=3,h({url:a},r);case 3:if(null==(i=e.sent)||!i.error){e.next=6;break}throw new Error(null!=(u=null==i||null==(s=i.error)?void 0:s.message)?u:"Unexpected Error");case 6:return e.abrupt("return",i);case 7:case"end":return e.stop()}}),e)})));return function(r,t,n){return e.apply(this,arguments)}}(),L=function(){var e=o(t().mark((function e(r,n,o){var a,i,u,s;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=m(O,"/:accountId/profiles",o,{accountId:n}),e.next=3,h({url:a},r);case 3:if(null==(i=e.sent)||!i.error){e.next=6;break}throw new Error(null!=(u=null==i||null==(s=i.error)?void 0:s.message)?u:"Unexpected Error");case 6:return e.abrupt("return",i);case 7:case"end":return e.stop()}}),e)})));return function(r,t,n){return e.apply(this,arguments)}}(),U=function(){var e=o(t().mark((function e(r,n){var o,a,i,u,s;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=["npId,onlineId,accountId,avatarUrls,plus,aboutMe,languagesUsed","trophySummary(@default,level,progress,earnedTrophies)","isOfficiallyVerified,personalDetail(@default,profilePictureUrls),personalDetailSharing,personalDetailSharingRequestMessageFlag","primaryOnlineStatus,presences(@default,@titleInfo,platform,lastOnlineDate,hasBroadcastData)","requestMessageFlag,blocking,friendRelation,following,consoleAvailability"].join(","),a=m("https://us-prof.np.community.playstation.net/userProfile/v1/users",":userName/profile2",{},{userName:n,fields:o}),e.next=9,h({url:a},r);case 9:if(null==(i=e.sent)||!i.error){e.next=12;break}throw new Error(null!=(u=null==i||null==(s=i.error)?void 0:s.message)?u:"Unexpected Error");case 12:return e.abrupt("return",i);case 13:case"end":return e.stop()}}),e)})));return function(r,t){return e.apply(this,arguments)}}(),N=function(){var e=o(t().mark((function e(r,n){var o,a,i,u;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=m("https://m.np.playstation.com/api/cpss","/v1/share/profile/:accountId",{},{accountId:n}),e.next=3,h({url:o},r);case 3:if(null==(a=e.sent)||!a.error){e.next=6;break}throw new Error(null!=(i=null==a||null==(u=a.error)?void 0:u.message)?i:"Unexpected Error");case 6:return e.abrupt("return",a);case 7:case"end":return e.stop()}}),e)})));return function(r,t){return e.apply(this,arguments)}}(),j=function(){var e=o(t().mark((function e(r,n,o){var a,i,u,s;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=m(O,"/:accountId/friends",o,{accountId:n}),e.next=3,h({url:a},r);case 3:if(null==(i=e.sent)||!i.error){e.next=6;break}throw new Error(null!=(u=null==i||null==(s=i.error)?void 0:s.message)?u:"Unexpected Error");case 6:return e.abrupt("return",i);case 7:case"end":return e.stop()}}),e)})));return function(r,t,n){return e.apply(this,arguments)}}();function C(){return(C=o(t().mark((function e(r,n,o){var a,i,u,s;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=m("https://m.np.playstation.com/api/gamelist/v2/users","/:accountId/titles",o,{accountId:n}),e.next=3,h({url:a},r);case 3:if(null==(i=e.sent)||!i.error){e.next=6;break}throw new Error(null!=(u=null==i||null==(s=i.error)?void 0:s.message)?u:"Unexpected Error");case 6:return e.abrupt("return",i);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var G=function(e){if(!e)return null;try{var r=function(e){try{if("undefined"!=typeof window&&"function"==typeof window.atob)return window.atob(e);if("undefined"!=typeof Buffer)return Buffer.from(e,"base64").toString("utf8");throw new TypeError("Base64 decoding unsupported in this environment")}catch(e){throw new Error("Base64 decoding error: "+e)}}(e);if(r.includes("@")&&r.includes(".")){var t=r.split(".").pop();if(t&&2===t.length&&/^[A-Za-z]+$/.test(t))return t.toUpperCase()}return null}catch(e){return console.error("Failed to extract region from NPID:",e),null}},R=function(){var e=o(t().mark((function e(r,n,o){var a,i,u,s,c,p;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===o&&(o=["en"]),e.next=3,U(r,n);case 3:if(u=null==(i=e.sent)||null==(a=i.profile)?void 0:a.npId){e.next=7;break}return e.abrupt("return",null);case 7:if(s=G(u)){e.next=10;break}return e.abrupt("return",null);case 10:return e.prev=10,c=new Intl.DisplayNames(o,{type:"region"}),p=c.of(s),e.abrupt("return",{code:s,name:p});case 16:return e.prev=16,e.t0=e.catch(10),e.abrupt("return",{code:s,name:"Unknown"});case 19:case"end":return e.stop()}}),e,null,[[10,16]])})));return function(r,t,n){return e.apply(this,arguments)}}();exports.call=h,exports.exchangeAccessCodeForAuthTokens=s,exports.exchangeCodeForAccessToken=c,exports.exchangeNpssoForAccessCode=p,exports.exchangeNpssoForCode=l,exports.exchangeRefreshTokenForAuthTokens=f,exports.getAccountDevices=S,exports.getBasicPresence=P,exports.getProfileFromAccountId=L,exports.getProfileFromUserName=U,exports.getProfileShareableLink=N,exports.getRecentlyPlayedGames=d,exports.getTitleTrophies=w,exports.getTitleTrophyGroups=g,exports.getUserFriendsAccountIds=j,exports.getUserPlayedGames=function(e,r,t){return C.apply(this,arguments)},exports.getUserRegion=R,exports.getUserTitles=b,exports.getUserTrophiesEarnedForTitle=k,exports.getUserTrophiesForSpecificTitle=I,exports.getUserTrophyGroupEarningsForTitle=E,exports.getUserTrophyProfileSummary=_,exports.makeUniversalSearch=y;
//# sourceMappingURL=psn-api.cjs.production.min.js.map