@privy-io/js-sdk-core 0.56.0 → 0.56.1-beta-20251010144542

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.
@@ -1 +1 @@
1
- "use strict";var e=require("fetch-retry"),t=require("uuid"),s=require("@privy-io/api-base"),i=require("@privy-io/public-api"),r=require("../Error.js"),a=require("../Session.js"),n=require("../toAbortSignalTimeout.js"),o=require("../utils/toSearchParams.js"),h=require("./logger.js");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("eventemitter3"),require("jose"),require("js-cookie"),require("../Token.js"),require("../utils/allSettled.js"),require("../utils/noop.js");var c=/*#__PURE__*/l(e);let g="privy:caid";exports.PrivyInternal=class{setCallbacks(e){this.callbacks={...this.callbacks,...e}}get isReady(){return!!this._config}get config(){return this._config}get caid(){return this._analyticsId}async _initialize(){if(this.isReady)this.callbacks?.setIsReady?.(!0);else{if(!await this.isStorageAccessible())throw new r.PrivyClientError({code:"storage_error",error:"Unable to access storage"});this._config=await this.getAppConfig(),this._config?.custom_api_url&&(this.baseUrl=this._config.custom_api_url,this.session.isUsingServerCookies=!0),this.callbacks?.setIsReady?.(!0),this._sdkVersion.startsWith("react-auth:")||this.createAnalyticsEvent("sdk_initialize",{})}}getPath(e,{params:t,query:s}){return`${this.baseUrl}${i.getPathWithParams(e.path,t)}${o.toSearchParams(s)}`}async fetch(e,{body:t,params:s,query:i,headers:a,onRequest:n=this._beforeRequest.bind(this)}){let o=new Request(this.getPath(e,{params:s,query:i}),{method:e.method,body:JSON.stringify(t),headers:a}),h=await n(o),l=await this._fetch(o,h),c=await l.json();if(l.status>299)throw new r.PrivyApiError(c);return c}async _beforeRequestWithoutInitialize(e){let t=await this.session.getToken(),s=new Headers(e.headers);s.set("privy-app-id",this.appId),this.appClientId&&s.set("privy-client-id",this.appClientId),s.set("privy-client",this._sdkVersion),t&&s.set("Authorization",`Bearer ${t}`),s.set("Content-Type","application/json"),s.set("Accept","application/json");let i=await this._getOrGenerateClientAnalyticsId();return i&&s.set("privy-ca-id",i),this.nativeAppIdentifier&&s.set("x-native-app-identifier",this.nativeAppIdentifier),{signal:n.default(2e4),headers:s,credentials:"include"}}async beforeRequestWithoutRefresh(e){return await this._initialize(),this._beforeRequestWithoutInitialize(e)}async _beforeRequest(e){return await this._initialize(),await this.getAccessToken(),this.beforeRequestWithoutRefresh(e)}async getAppConfig(){return await this.fetch(i.AppConfig,{params:{app_id:this.appId},onRequest:this._beforeRequestWithoutInitialize.bind(this)})}async _getOrGenerateClientAnalyticsId(){if(this._analyticsId)return this._analyticsId;try{let e=await this._storage.get(g);if("string"==typeof e&&e.length>0)return this._analyticsId=e,e}catch(e){this.logger.error("Unable to load clientId",e)}try{this._analyticsId=t.v4()}catch(e){this.logger.error("Unable to generate uuidv4",e)}if(!this._analyticsId)return null;try{await this._storage.put(g,this._analyticsId)}catch(e){this.logger.error(`Unable to store clientId: ${this._analyticsId}`,e)}return this._analyticsId}async destroyClientAnalyticsId(){try{return await this._storage.del(g)}catch(e){this.logger.error("Unable to delete clientId",e)}}async createAnalyticsEvent(e,t){try{await this.fetch(i.AnalyticsEvent,{body:{event_name:e,client_id:await this._getOrGenerateClientAnalyticsId(),payload:t},onRequest:this.beforeRequestWithoutRefresh.bind(this)})}catch(e){}}async refreshSession(e=!1){if(!await this.isStorageAccessible())throw new r.PrivyClientError({code:"storage_error",error:"Unable to access storage"});let t=await this.session.getRefreshToken()??void 0,s=t??"key",i=this._cache.get(s);if(i)return this.logger.debug("[privy:refresh] found in-flight session refresh request, deduping"),await i;let a=this._refreshSession(t,e);this._cache.set(s,a);try{return await a}finally{this._cache.delete(s)}}async _refreshSession(e,t){let a=await this.session.getToken();if(!this.session.hasRefreshCredentials(a,e??null))throw this.logger.debug("[privy:refresh] missing tokens, skipping request"),await this._initialize(),new r.PrivyApiError({code:s.PrivyErrorCode.MISSING_OR_INVALID_TOKEN,error:"No tokens found in storage"});try{this.logger.debug(`[privy:refresh] fetching: ${i.RefreshSession.path}`);let s=await this.fetch(i.RefreshSession,{body:{refresh_token:e},onRequest:this.beforeRequestWithoutRefresh.bind(this)}),r=s.session_update_action;return this.logger.debug(`[privy:refresh] response: ${r}`),t||this.callbacks?.setUser?.(s.user),"set"===r&&(await this.session.updateWithTokensResponse(s),this.logger.debug("[privy:refresh] tokens stored")),"clear"===r&&(await this.session.destroyLocalState(),this.logger.debug("[privy:refresh] tokens cleared"),t||this.callbacks?.setUser?.(null)),"ignore"===r&&s.token&&(await this.session.storeToken(s.token),this.logger.debug("[privy:refresh] access token stored"),s.identity_token&&(this.logger.debug("[privy:refresh] identity token stored"),await this.session.storeIdentityToken(s.identity_token))),this.logger.debug("[privy:refresh] returning response"),s}catch(e){throw this.logger.debug(`[privy:refresh] error: ${e.message??"unknown error"}`),e instanceof r.PrivyApiError&&e.code===s.PrivyErrorCode.MISSING_OR_INVALID_TOKEN&&(await this.session.destroyLocalState(),t||this.callbacks?.setUser?.(null)),e}}async getAccessToken(){let[e,t]=await Promise.all([this.session.getToken(),this.session.getRefreshToken()]);if(!this.session.tokenIsActive(e)&&this.session.hasRefreshCredentials(e,t)){let t=await this.refreshSession(),s=await this.session.getToken();return t.token||this.logger.debug("[privy:getAccessToken] expected token received null"),t.token===e&&this.logger.debug("[privy:getAccessToken] expected new token in response received existing"),s===e&&this.logger.debug("[privy:getAccessToken] expected new token in storage received existing"),t.token??s}return e}async getIdentityToken(){return await this.session.getIdentityToken()}async isStorageAccessible(){try{let e=`privy:__storage__test-${t.v4()}`,s="blobby";await this._storage.put(e,s);let i=await this._storage.get(e);return await this._storage.del(e),i===s}catch(e){return this.logger.error(e),!1}}constructor(e){this._sdkVersion="js-sdk-core:0.56.0",this._cache=new Map,this.logger=h.toConsoleLogger({level:e.logLevel??"ERROR"}),this._storage=e.storage,this._analyticsId=null,this._getOrGenerateClientAnalyticsId(),this.baseUrl=e.baseUrl??"https://auth.privy.io",this.appId=e.appId,this.appClientId=e.appClientId,this._sdkVersion=e.sdkVersion??this._sdkVersion,this.callbacks=e.callbacks,this.nativeAppIdentifier=e.nativeAppIdentifier,this.session=new a.Session({storage:this._storage,isUsingServerCookies:!1,appId:e.appId}),this._fetch=c.default(globalThis.fetch,{retries:3,retryDelay:e=>3**e*500,retryOn:[408,409,425,500,502,503,504]}),this.session.on("error_storing_tokens",(e=>{this.createAnalyticsEvent("error_updating_tokens_in_storage",{reason:e})}))}};
1
+ "use strict";var e=require("fetch-retry"),t=require("uuid"),s=require("@privy-io/api-base"),i=require("@privy-io/public-api"),r=require("../Error.js"),a=require("../Session.js"),n=require("../toAbortSignalTimeout.js"),o=require("../utils/toSearchParams.js"),h=require("./logger.js");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("eventemitter3"),require("jose"),require("js-cookie"),require("../Token.js"),require("../utils/allSettled.js"),require("../utils/noop.js");var c=/*#__PURE__*/l(e);let g="privy:caid";exports.PrivyInternal=class{setCallbacks(e){this.callbacks={...this.callbacks,...e}}get isReady(){return!!this._config}get config(){return this._config}get caid(){return this._analyticsId}async _initialize(){if(this.isReady)this.callbacks?.setIsReady?.(!0);else{if(!await this.isStorageAccessible())throw new r.PrivyClientError({code:"storage_error",error:"Unable to access storage"});this._config=await this.getAppConfig(),this._config?.custom_api_url&&(this.baseUrl=this._config.custom_api_url,this.session.isUsingServerCookies=!0),this.callbacks?.setIsReady?.(!0),this._sdkVersion.startsWith("react-auth:")||this.createAnalyticsEvent("sdk_initialize",{})}}getPath(e,{params:t,query:s}){return`${this.baseUrl}${i.getPathWithParams(e.path,t)}${o.toSearchParams(s)}`}async fetch(e,{body:t,params:s,query:i,headers:a,onRequest:n=this._beforeRequest.bind(this)}){let o=new Request(this.getPath(e,{params:s,query:i}),{method:e.method,body:JSON.stringify(t),headers:a}),h=await n(o),l=await this._fetch(o,h),c=await l.json();if(l.status>299)throw new r.PrivyApiError(c);return c}async _beforeRequestWithoutInitialize(e){let t=await this.session.getToken(),s=new Headers(e.headers);s.set("privy-app-id",this.appId),this.appClientId&&s.set("privy-client-id",this.appClientId),s.set("privy-client",this._sdkVersion),t&&s.set("Authorization",`Bearer ${t}`),s.set("Content-Type","application/json"),s.set("Accept","application/json");let i=await this._getOrGenerateClientAnalyticsId();return i&&s.set("privy-ca-id",i),this.nativeAppIdentifier&&s.set("x-native-app-identifier",this.nativeAppIdentifier),{signal:n.default(2e4),headers:s,credentials:"include"}}async beforeRequestWithoutRefresh(e){return await this._initialize(),this._beforeRequestWithoutInitialize(e)}async _beforeRequest(e){return await this._initialize(),await this.getAccessToken(),this.beforeRequestWithoutRefresh(e)}async getAppConfig(){return await this.fetch(i.AppConfig,{params:{app_id:this.appId},onRequest:this._beforeRequestWithoutInitialize.bind(this)})}async _getOrGenerateClientAnalyticsId(){if(this._analyticsId)return this._analyticsId;try{let e=await this._storage.get(g);if("string"==typeof e&&e.length>0)return this._analyticsId=e,e}catch(e){this.logger.error("Unable to load clientId",e)}try{this._analyticsId=t.v4()}catch(e){this.logger.error("Unable to generate uuidv4",e)}if(!this._analyticsId)return null;try{await this._storage.put(g,this._analyticsId)}catch(e){this.logger.error(`Unable to store clientId: ${this._analyticsId}`,e)}return this._analyticsId}async destroyClientAnalyticsId(){try{return await this._storage.del(g)}catch(e){this.logger.error("Unable to delete clientId",e)}}async createAnalyticsEvent(e,t){try{await this.fetch(i.AnalyticsEvent,{body:{event_name:e,client_id:await this._getOrGenerateClientAnalyticsId(),payload:t},onRequest:this.beforeRequestWithoutRefresh.bind(this)})}catch(e){}}async refreshSession(e=!1){if(!await this.isStorageAccessible())throw new r.PrivyClientError({code:"storage_error",error:"Unable to access storage"});let t=await this.session.getRefreshToken()??void 0,s=t??"key",i=this._cache.get(s);if(i)return this.logger.debug("[privy:refresh] found in-flight session refresh request, deduping"),await i;let a=this._refreshSession(t,e);this._cache.set(s,a);try{return await a}finally{this._cache.delete(s)}}async _refreshSession(e,t){let a=await this.session.getToken();if(!this.session.hasRefreshCredentials(a,e??null))throw this.logger.debug("[privy:refresh] missing tokens, skipping request"),await this._initialize(),new r.PrivyApiError({code:s.PrivyErrorCode.MISSING_OR_INVALID_TOKEN,error:"No tokens found in storage"});try{this.logger.debug(`[privy:refresh] fetching: ${i.RefreshSession.path}`);let s=await this.fetch(i.RefreshSession,{body:{refresh_token:e},onRequest:this.beforeRequestWithoutRefresh.bind(this)}),r=s.session_update_action;return this.logger.debug(`[privy:refresh] response: ${r}`),t||this.callbacks?.setUser?.(s.user),"set"===r&&(await this.session.updateWithTokensResponse(s),this.logger.debug("[privy:refresh] tokens stored")),"clear"===r&&(await this.session.destroyLocalState(),this.logger.debug("[privy:refresh] tokens cleared"),t||this.callbacks?.setUser?.(null)),"ignore"===r&&s.token&&(await this.session.storeToken(s.token),this.logger.debug("[privy:refresh] access token stored"),s.identity_token&&(this.logger.debug("[privy:refresh] identity token stored"),await this.session.storeIdentityToken(s.identity_token))),this.logger.debug("[privy:refresh] returning response"),s}catch(e){throw this.logger.debug(`[privy:refresh] error: ${e.message??"unknown error"}`),e instanceof r.PrivyApiError&&e.code===s.PrivyErrorCode.MISSING_OR_INVALID_TOKEN&&(await this.session.destroyLocalState(),t||this.callbacks?.setUser?.(null)),e}}async getAccessToken(){let[e,t]=await Promise.all([this.session.getToken(),this.session.getRefreshToken()]);if(!this.session.tokenIsActive(e)&&this.session.hasRefreshCredentials(e,t)){let t=await this.refreshSession(),s=await this.session.getToken();return t.token||this.logger.debug("[privy:getAccessToken] expected token received null"),t.token===e&&this.logger.debug("[privy:getAccessToken] expected new token in response received existing"),s===e&&this.logger.debug("[privy:getAccessToken] expected new token in storage received existing"),t.token??s}return e}async getIdentityToken(){return await this.session.getIdentityToken()}async isStorageAccessible(){try{let e=`privy:__storage__test-${t.v4()}`,s="blobby";await this._storage.put(e,s);let i=await this._storage.get(e);return await this._storage.del(e),i===s}catch(e){return this.logger.error(e),!1}}constructor(e){this._sdkVersion="js-sdk-core:0.56.1-beta-20251010144542",this._cache=new Map,this.logger=h.toConsoleLogger({level:e.logLevel??"ERROR"}),this._storage=e.storage,this._analyticsId=null,this._getOrGenerateClientAnalyticsId(),this.baseUrl=e.baseUrl??"https://auth.privy.io",this.appId=e.appId,this.appClientId=e.appClientId,this._sdkVersion=e.sdkVersion??this._sdkVersion,this.callbacks=e.callbacks,this.nativeAppIdentifier=e.nativeAppIdentifier,this.session=new a.Session({storage:this._storage,isUsingServerCookies:!1,appId:e.appId}),this._fetch=c.default(globalThis.fetch,{retries:3,retryDelay:e=>3**e*500,retryOn:[408,409,425,500,502,503,504]}),this.session.on("error_storing_tokens",(e=>{this.createAnalyticsEvent("error_updating_tokens_in_storage",{reason:e})}))}};
@@ -785,6 +785,7 @@ declare class AppApi {
785
785
  instagram_oauth: boolean;
786
786
  tiktok_oauth: boolean;
787
787
  line_oauth: boolean;
788
+ twitch_oauth: boolean;
788
789
  linkedin_oauth: boolean;
789
790
  apple_oauth: boolean;
790
791
  custom_oauth_providers: {
@@ -1264,6 +1265,13 @@ declare class EmbeddedWalletApi {
1264
1265
  latest_verified_at: number | null;
1265
1266
  profile_picture_url: string | null;
1266
1267
  subject: string;
1268
+ } | {
1269
+ type: "twitch_oauth";
1270
+ username: string | null;
1271
+ verified_at: number;
1272
+ first_verified_at: number | null;
1273
+ latest_verified_at: number | null;
1274
+ subject: string;
1267
1275
  } | {
1268
1276
  type: "apple_oauth";
1269
1277
  email: string | null;
@@ -1715,6 +1723,13 @@ declare class UserApi {
1715
1723
  latest_verified_at: number | null;
1716
1724
  profile_picture_url: string | null;
1717
1725
  subject: string;
1726
+ } | {
1727
+ type: "twitch_oauth";
1728
+ username: string | null;
1729
+ verified_at: number;
1730
+ first_verified_at: number | null;
1731
+ latest_verified_at: number | null;
1732
+ subject: string;
1718
1733
  } | {
1719
1734
  type: "apple_oauth";
1720
1735
  email: string | null;
@@ -2063,6 +2078,13 @@ declare class EmailApi {
2063
2078
  latest_verified_at: number | null;
2064
2079
  profile_picture_url: string | null;
2065
2080
  subject: string;
2081
+ } | {
2082
+ type: "twitch_oauth";
2083
+ username: string | null;
2084
+ verified_at: number;
2085
+ first_verified_at: number | null;
2086
+ latest_verified_at: number | null;
2087
+ subject: string;
2066
2088
  } | {
2067
2089
  type: "apple_oauth";
2068
2090
  email: string | null;
@@ -2376,6 +2398,13 @@ declare class EmailApi {
2376
2398
  latest_verified_at: number | null;
2377
2399
  profile_picture_url: string | null;
2378
2400
  subject: string;
2401
+ } | {
2402
+ type: "twitch_oauth";
2403
+ username: string | null;
2404
+ verified_at: number;
2405
+ first_verified_at: number | null;
2406
+ latest_verified_at: number | null;
2407
+ subject: string;
2379
2408
  } | {
2380
2409
  type: "apple_oauth";
2381
2410
  email: string | null;
@@ -2678,6 +2707,13 @@ declare class EmailApi {
2678
2707
  latest_verified_at: number | null;
2679
2708
  profile_picture_url: string | null;
2680
2709
  subject: string;
2710
+ } | {
2711
+ type: "twitch_oauth";
2712
+ username: string | null;
2713
+ verified_at: number;
2714
+ first_verified_at: number | null;
2715
+ latest_verified_at: number | null;
2716
+ subject: string;
2681
2717
  } | {
2682
2718
  type: "apple_oauth";
2683
2719
  email: string | null;
@@ -3015,6 +3051,13 @@ declare class FarcasterApi {
3015
3051
  latest_verified_at: number | null;
3016
3052
  profile_picture_url: string | null;
3017
3053
  subject: string;
3054
+ } | {
3055
+ type: "twitch_oauth";
3056
+ username: string | null;
3057
+ verified_at: number;
3058
+ first_verified_at: number | null;
3059
+ latest_verified_at: number | null;
3060
+ subject: string;
3018
3061
  } | {
3019
3062
  type: "apple_oauth";
3020
3063
  email: string | null;
@@ -3322,6 +3365,13 @@ declare class FarcasterApi {
3322
3365
  latest_verified_at: number | null;
3323
3366
  profile_picture_url: string | null;
3324
3367
  subject: string;
3368
+ } | {
3369
+ type: "twitch_oauth";
3370
+ username: string | null;
3371
+ verified_at: number;
3372
+ first_verified_at: number | null;
3373
+ latest_verified_at: number | null;
3374
+ subject: string;
3325
3375
  } | {
3326
3376
  type: "apple_oauth";
3327
3377
  email: string | null;
@@ -3677,6 +3727,13 @@ declare class OAuthApi {
3677
3727
  latest_verified_at: number | null;
3678
3728
  profile_picture_url: string | null;
3679
3729
  subject: string;
3730
+ } | {
3731
+ type: "twitch_oauth";
3732
+ username: string | null;
3733
+ verified_at: number;
3734
+ first_verified_at: number | null;
3735
+ latest_verified_at: number | null;
3736
+ subject: string;
3680
3737
  } | {
3681
3738
  type: "apple_oauth";
3682
3739
  email: string | null;
@@ -3985,6 +4042,13 @@ declare class OAuthApi {
3985
4042
  latest_verified_at: number | null;
3986
4043
  profile_picture_url: string | null;
3987
4044
  subject: string;
4045
+ } | {
4046
+ type: "twitch_oauth";
4047
+ username: string | null;
4048
+ verified_at: number;
4049
+ first_verified_at: number | null;
4050
+ latest_verified_at: number | null;
4051
+ subject: string;
3988
4052
  } | {
3989
4053
  type: "apple_oauth";
3990
4054
  email: string | null;
@@ -4413,6 +4477,13 @@ declare class PasskeyApi {
4413
4477
  latest_verified_at: number | null;
4414
4478
  profile_picture_url: string | null;
4415
4479
  subject: string;
4480
+ } | {
4481
+ type: "twitch_oauth";
4482
+ username: string | null;
4483
+ verified_at: number;
4484
+ first_verified_at: number | null;
4485
+ latest_verified_at: number | null;
4486
+ subject: string;
4416
4487
  } | {
4417
4488
  type: "apple_oauth";
4418
4489
  email: string | null;
@@ -4741,6 +4812,13 @@ declare class PhoneApi {
4741
4812
  latest_verified_at: number | null;
4742
4813
  profile_picture_url: string | null;
4743
4814
  subject: string;
4815
+ } | {
4816
+ type: "twitch_oauth";
4817
+ username: string | null;
4818
+ verified_at: number;
4819
+ first_verified_at: number | null;
4820
+ latest_verified_at: number | null;
4821
+ subject: string;
4744
4822
  } | {
4745
4823
  type: "apple_oauth";
4746
4824
  email: string | null;
@@ -5054,6 +5132,13 @@ declare class PhoneApi {
5054
5132
  latest_verified_at: number | null;
5055
5133
  profile_picture_url: string | null;
5056
5134
  subject: string;
5135
+ } | {
5136
+ type: "twitch_oauth";
5137
+ username: string | null;
5138
+ verified_at: number;
5139
+ first_verified_at: number | null;
5140
+ latest_verified_at: number | null;
5141
+ subject: string;
5057
5142
  } | {
5058
5143
  type: "apple_oauth";
5059
5144
  email: string | null;
@@ -5356,6 +5441,13 @@ declare class PhoneApi {
5356
5441
  latest_verified_at: number | null;
5357
5442
  profile_picture_url: string | null;
5358
5443
  subject: string;
5444
+ } | {
5445
+ type: "twitch_oauth";
5446
+ username: string | null;
5447
+ verified_at: number;
5448
+ first_verified_at: number | null;
5449
+ latest_verified_at: number | null;
5450
+ subject: string;
5359
5451
  } | {
5360
5452
  type: "apple_oauth";
5361
5453
  email: string | null;
@@ -5729,6 +5821,13 @@ declare class SiweApi {
5729
5821
  latest_verified_at: number | null;
5730
5822
  profile_picture_url: string | null;
5731
5823
  subject: string;
5824
+ } | {
5825
+ type: "twitch_oauth";
5826
+ username: string | null;
5827
+ verified_at: number;
5828
+ first_verified_at: number | null;
5829
+ latest_verified_at: number | null;
5830
+ subject: string;
5732
5831
  } | {
5733
5832
  type: "apple_oauth";
5734
5833
  email: string | null;
@@ -6048,6 +6147,13 @@ declare class SiweApi {
6048
6147
  latest_verified_at: number | null;
6049
6148
  profile_picture_url: string | null;
6050
6149
  subject: string;
6150
+ } | {
6151
+ type: "twitch_oauth";
6152
+ username: string | null;
6153
+ verified_at: number;
6154
+ first_verified_at: number | null;
6155
+ latest_verified_at: number | null;
6156
+ subject: string;
6051
6157
  } | {
6052
6158
  type: "apple_oauth";
6053
6159
  email: string | null;
@@ -6400,6 +6506,13 @@ declare class SiwsApi {
6400
6506
  latest_verified_at: number | null;
6401
6507
  profile_picture_url: string | null;
6402
6508
  subject: string;
6509
+ } | {
6510
+ type: "twitch_oauth";
6511
+ username: string | null;
6512
+ verified_at: number;
6513
+ first_verified_at: number | null;
6514
+ latest_verified_at: number | null;
6515
+ subject: string;
6403
6516
  } | {
6404
6517
  type: "apple_oauth";
6405
6518
  email: string | null;
@@ -6724,6 +6837,13 @@ declare class SiwsApi {
6724
6837
  latest_verified_at: number | null;
6725
6838
  profile_picture_url: string | null;
6726
6839
  subject: string;
6840
+ } | {
6841
+ type: "twitch_oauth";
6842
+ username: string | null;
6843
+ verified_at: number;
6844
+ first_verified_at: number | null;
6845
+ latest_verified_at: number | null;
6846
+ subject: string;
6727
6847
  } | {
6728
6848
  type: "apple_oauth";
6729
6849
  email: string | null;
@@ -7083,6 +7203,13 @@ declare class SmartWalletApi {
7083
7203
  latest_verified_at: number | null;
7084
7204
  profile_picture_url: string | null;
7085
7205
  subject: string;
7206
+ } | {
7207
+ type: "twitch_oauth";
7208
+ username: string | null;
7209
+ verified_at: number;
7210
+ first_verified_at: number | null;
7211
+ latest_verified_at: number | null;
7212
+ subject: string;
7086
7213
  } | {
7087
7214
  type: "apple_oauth";
7088
7215
  email: string | null;
@@ -8182,6 +8309,13 @@ declare const delegateWallet: (client: Privy) => ({ address, chainType }: Delega
8182
8309
  latest_verified_at: number | null;
8183
8310
  profile_picture_url: string | null;
8184
8311
  subject: string;
8312
+ } | {
8313
+ type: "twitch_oauth";
8314
+ username: string | null;
8315
+ verified_at: number;
8316
+ first_verified_at: number | null;
8317
+ latest_verified_at: number | null;
8318
+ subject: string;
8185
8319
  } | {
8186
8320
  type: "apple_oauth";
8187
8321
  email: string | null;
@@ -8492,6 +8626,13 @@ declare const revokeWallets: (client: Privy) => () => Promise<{
8492
8626
  latest_verified_at: number | null;
8493
8627
  profile_picture_url: string | null;
8494
8628
  subject: string;
8629
+ } | {
8630
+ type: "twitch_oauth";
8631
+ username: string | null;
8632
+ verified_at: number;
8633
+ first_verified_at: number | null;
8634
+ latest_verified_at: number | null;
8635
+ subject: string;
8495
8636
  } | {
8496
8637
  type: "apple_oauth";
8497
8638
  email: string | null;
@@ -785,6 +785,7 @@ declare class AppApi {
785
785
  instagram_oauth: boolean;
786
786
  tiktok_oauth: boolean;
787
787
  line_oauth: boolean;
788
+ twitch_oauth: boolean;
788
789
  linkedin_oauth: boolean;
789
790
  apple_oauth: boolean;
790
791
  custom_oauth_providers: {
@@ -1264,6 +1265,13 @@ declare class EmbeddedWalletApi {
1264
1265
  latest_verified_at: number | null;
1265
1266
  profile_picture_url: string | null;
1266
1267
  subject: string;
1268
+ } | {
1269
+ type: "twitch_oauth";
1270
+ username: string | null;
1271
+ verified_at: number;
1272
+ first_verified_at: number | null;
1273
+ latest_verified_at: number | null;
1274
+ subject: string;
1267
1275
  } | {
1268
1276
  type: "apple_oauth";
1269
1277
  email: string | null;
@@ -1715,6 +1723,13 @@ declare class UserApi {
1715
1723
  latest_verified_at: number | null;
1716
1724
  profile_picture_url: string | null;
1717
1725
  subject: string;
1726
+ } | {
1727
+ type: "twitch_oauth";
1728
+ username: string | null;
1729
+ verified_at: number;
1730
+ first_verified_at: number | null;
1731
+ latest_verified_at: number | null;
1732
+ subject: string;
1718
1733
  } | {
1719
1734
  type: "apple_oauth";
1720
1735
  email: string | null;
@@ -2063,6 +2078,13 @@ declare class EmailApi {
2063
2078
  latest_verified_at: number | null;
2064
2079
  profile_picture_url: string | null;
2065
2080
  subject: string;
2081
+ } | {
2082
+ type: "twitch_oauth";
2083
+ username: string | null;
2084
+ verified_at: number;
2085
+ first_verified_at: number | null;
2086
+ latest_verified_at: number | null;
2087
+ subject: string;
2066
2088
  } | {
2067
2089
  type: "apple_oauth";
2068
2090
  email: string | null;
@@ -2376,6 +2398,13 @@ declare class EmailApi {
2376
2398
  latest_verified_at: number | null;
2377
2399
  profile_picture_url: string | null;
2378
2400
  subject: string;
2401
+ } | {
2402
+ type: "twitch_oauth";
2403
+ username: string | null;
2404
+ verified_at: number;
2405
+ first_verified_at: number | null;
2406
+ latest_verified_at: number | null;
2407
+ subject: string;
2379
2408
  } | {
2380
2409
  type: "apple_oauth";
2381
2410
  email: string | null;
@@ -2678,6 +2707,13 @@ declare class EmailApi {
2678
2707
  latest_verified_at: number | null;
2679
2708
  profile_picture_url: string | null;
2680
2709
  subject: string;
2710
+ } | {
2711
+ type: "twitch_oauth";
2712
+ username: string | null;
2713
+ verified_at: number;
2714
+ first_verified_at: number | null;
2715
+ latest_verified_at: number | null;
2716
+ subject: string;
2681
2717
  } | {
2682
2718
  type: "apple_oauth";
2683
2719
  email: string | null;
@@ -3015,6 +3051,13 @@ declare class FarcasterApi {
3015
3051
  latest_verified_at: number | null;
3016
3052
  profile_picture_url: string | null;
3017
3053
  subject: string;
3054
+ } | {
3055
+ type: "twitch_oauth";
3056
+ username: string | null;
3057
+ verified_at: number;
3058
+ first_verified_at: number | null;
3059
+ latest_verified_at: number | null;
3060
+ subject: string;
3018
3061
  } | {
3019
3062
  type: "apple_oauth";
3020
3063
  email: string | null;
@@ -3322,6 +3365,13 @@ declare class FarcasterApi {
3322
3365
  latest_verified_at: number | null;
3323
3366
  profile_picture_url: string | null;
3324
3367
  subject: string;
3368
+ } | {
3369
+ type: "twitch_oauth";
3370
+ username: string | null;
3371
+ verified_at: number;
3372
+ first_verified_at: number | null;
3373
+ latest_verified_at: number | null;
3374
+ subject: string;
3325
3375
  } | {
3326
3376
  type: "apple_oauth";
3327
3377
  email: string | null;
@@ -3677,6 +3727,13 @@ declare class OAuthApi {
3677
3727
  latest_verified_at: number | null;
3678
3728
  profile_picture_url: string | null;
3679
3729
  subject: string;
3730
+ } | {
3731
+ type: "twitch_oauth";
3732
+ username: string | null;
3733
+ verified_at: number;
3734
+ first_verified_at: number | null;
3735
+ latest_verified_at: number | null;
3736
+ subject: string;
3680
3737
  } | {
3681
3738
  type: "apple_oauth";
3682
3739
  email: string | null;
@@ -3985,6 +4042,13 @@ declare class OAuthApi {
3985
4042
  latest_verified_at: number | null;
3986
4043
  profile_picture_url: string | null;
3987
4044
  subject: string;
4045
+ } | {
4046
+ type: "twitch_oauth";
4047
+ username: string | null;
4048
+ verified_at: number;
4049
+ first_verified_at: number | null;
4050
+ latest_verified_at: number | null;
4051
+ subject: string;
3988
4052
  } | {
3989
4053
  type: "apple_oauth";
3990
4054
  email: string | null;
@@ -4413,6 +4477,13 @@ declare class PasskeyApi {
4413
4477
  latest_verified_at: number | null;
4414
4478
  profile_picture_url: string | null;
4415
4479
  subject: string;
4480
+ } | {
4481
+ type: "twitch_oauth";
4482
+ username: string | null;
4483
+ verified_at: number;
4484
+ first_verified_at: number | null;
4485
+ latest_verified_at: number | null;
4486
+ subject: string;
4416
4487
  } | {
4417
4488
  type: "apple_oauth";
4418
4489
  email: string | null;
@@ -4741,6 +4812,13 @@ declare class PhoneApi {
4741
4812
  latest_verified_at: number | null;
4742
4813
  profile_picture_url: string | null;
4743
4814
  subject: string;
4815
+ } | {
4816
+ type: "twitch_oauth";
4817
+ username: string | null;
4818
+ verified_at: number;
4819
+ first_verified_at: number | null;
4820
+ latest_verified_at: number | null;
4821
+ subject: string;
4744
4822
  } | {
4745
4823
  type: "apple_oauth";
4746
4824
  email: string | null;
@@ -5054,6 +5132,13 @@ declare class PhoneApi {
5054
5132
  latest_verified_at: number | null;
5055
5133
  profile_picture_url: string | null;
5056
5134
  subject: string;
5135
+ } | {
5136
+ type: "twitch_oauth";
5137
+ username: string | null;
5138
+ verified_at: number;
5139
+ first_verified_at: number | null;
5140
+ latest_verified_at: number | null;
5141
+ subject: string;
5057
5142
  } | {
5058
5143
  type: "apple_oauth";
5059
5144
  email: string | null;
@@ -5356,6 +5441,13 @@ declare class PhoneApi {
5356
5441
  latest_verified_at: number | null;
5357
5442
  profile_picture_url: string | null;
5358
5443
  subject: string;
5444
+ } | {
5445
+ type: "twitch_oauth";
5446
+ username: string | null;
5447
+ verified_at: number;
5448
+ first_verified_at: number | null;
5449
+ latest_verified_at: number | null;
5450
+ subject: string;
5359
5451
  } | {
5360
5452
  type: "apple_oauth";
5361
5453
  email: string | null;
@@ -5729,6 +5821,13 @@ declare class SiweApi {
5729
5821
  latest_verified_at: number | null;
5730
5822
  profile_picture_url: string | null;
5731
5823
  subject: string;
5824
+ } | {
5825
+ type: "twitch_oauth";
5826
+ username: string | null;
5827
+ verified_at: number;
5828
+ first_verified_at: number | null;
5829
+ latest_verified_at: number | null;
5830
+ subject: string;
5732
5831
  } | {
5733
5832
  type: "apple_oauth";
5734
5833
  email: string | null;
@@ -6048,6 +6147,13 @@ declare class SiweApi {
6048
6147
  latest_verified_at: number | null;
6049
6148
  profile_picture_url: string | null;
6050
6149
  subject: string;
6150
+ } | {
6151
+ type: "twitch_oauth";
6152
+ username: string | null;
6153
+ verified_at: number;
6154
+ first_verified_at: number | null;
6155
+ latest_verified_at: number | null;
6156
+ subject: string;
6051
6157
  } | {
6052
6158
  type: "apple_oauth";
6053
6159
  email: string | null;
@@ -6400,6 +6506,13 @@ declare class SiwsApi {
6400
6506
  latest_verified_at: number | null;
6401
6507
  profile_picture_url: string | null;
6402
6508
  subject: string;
6509
+ } | {
6510
+ type: "twitch_oauth";
6511
+ username: string | null;
6512
+ verified_at: number;
6513
+ first_verified_at: number | null;
6514
+ latest_verified_at: number | null;
6515
+ subject: string;
6403
6516
  } | {
6404
6517
  type: "apple_oauth";
6405
6518
  email: string | null;
@@ -6724,6 +6837,13 @@ declare class SiwsApi {
6724
6837
  latest_verified_at: number | null;
6725
6838
  profile_picture_url: string | null;
6726
6839
  subject: string;
6840
+ } | {
6841
+ type: "twitch_oauth";
6842
+ username: string | null;
6843
+ verified_at: number;
6844
+ first_verified_at: number | null;
6845
+ latest_verified_at: number | null;
6846
+ subject: string;
6727
6847
  } | {
6728
6848
  type: "apple_oauth";
6729
6849
  email: string | null;
@@ -7083,6 +7203,13 @@ declare class SmartWalletApi {
7083
7203
  latest_verified_at: number | null;
7084
7204
  profile_picture_url: string | null;
7085
7205
  subject: string;
7206
+ } | {
7207
+ type: "twitch_oauth";
7208
+ username: string | null;
7209
+ verified_at: number;
7210
+ first_verified_at: number | null;
7211
+ latest_verified_at: number | null;
7212
+ subject: string;
7086
7213
  } | {
7087
7214
  type: "apple_oauth";
7088
7215
  email: string | null;
@@ -8182,6 +8309,13 @@ declare const delegateWallet: (client: Privy) => ({ address, chainType }: Delega
8182
8309
  latest_verified_at: number | null;
8183
8310
  profile_picture_url: string | null;
8184
8311
  subject: string;
8312
+ } | {
8313
+ type: "twitch_oauth";
8314
+ username: string | null;
8315
+ verified_at: number;
8316
+ first_verified_at: number | null;
8317
+ latest_verified_at: number | null;
8318
+ subject: string;
8185
8319
  } | {
8186
8320
  type: "apple_oauth";
8187
8321
  email: string | null;
@@ -8492,6 +8626,13 @@ declare const revokeWallets: (client: Privy) => () => Promise<{
8492
8626
  latest_verified_at: number | null;
8493
8627
  profile_picture_url: string | null;
8494
8628
  subject: string;
8629
+ } | {
8630
+ type: "twitch_oauth";
8631
+ username: string | null;
8632
+ verified_at: number;
8633
+ first_verified_at: number | null;
8634
+ latest_verified_at: number | null;
8635
+ subject: string;
8495
8636
  } | {
8496
8637
  type: "apple_oauth";
8497
8638
  email: string | null;
@@ -1 +1 @@
1
- import e from"fetch-retry";import{v4 as t}from"uuid";import{PrivyErrorCode as s}from"@privy-io/api-base";import{getPathWithParams as i,AppConfig as r,AnalyticsEvent as a,RefreshSession as n}from"@privy-io/public-api";import{PrivyClientError as o,PrivyApiError as h}from"../Error.mjs";import{Session as l}from"../Session.mjs";import c from"../toAbortSignalTimeout.mjs";import{toSearchParams as g}from"../utils/toSearchParams.mjs";import{toConsoleLogger as d}from"./logger.mjs";import"eventemitter3";import"jose";import"js-cookie";import"../Token.mjs";import"../utils/allSettled.mjs";import"../utils/noop.mjs";let p="privy:caid";class u{setCallbacks(e){this.callbacks={...this.callbacks,...e}}get isReady(){return!!this._config}get config(){return this._config}get caid(){return this._analyticsId}async _initialize(){if(this.isReady)this.callbacks?.setIsReady?.(!0);else{if(!await this.isStorageAccessible())throw new o({code:"storage_error",error:"Unable to access storage"});this._config=await this.getAppConfig(),this._config?.custom_api_url&&(this.baseUrl=this._config.custom_api_url,this.session.isUsingServerCookies=!0),this.callbacks?.setIsReady?.(!0),this._sdkVersion.startsWith("react-auth:")||this.createAnalyticsEvent("sdk_initialize",{})}}getPath(e,{params:t,query:s}){return`${this.baseUrl}${i(e.path,t)}${g(s)}`}async fetch(e,{body:t,params:s,query:i,headers:r,onRequest:a=this._beforeRequest.bind(this)}){let n=new Request(this.getPath(e,{params:s,query:i}),{method:e.method,body:JSON.stringify(t),headers:r}),o=await a(n),l=await this._fetch(n,o),c=await l.json();if(l.status>299)throw new h(c);return c}async _beforeRequestWithoutInitialize(e){let t=await this.session.getToken(),s=new Headers(e.headers);s.set("privy-app-id",this.appId),this.appClientId&&s.set("privy-client-id",this.appClientId),s.set("privy-client",this._sdkVersion),t&&s.set("Authorization",`Bearer ${t}`),s.set("Content-Type","application/json"),s.set("Accept","application/json");let i=await this._getOrGenerateClientAnalyticsId();return i&&s.set("privy-ca-id",i),this.nativeAppIdentifier&&s.set("x-native-app-identifier",this.nativeAppIdentifier),{signal:c(2e4),headers:s,credentials:"include"}}async beforeRequestWithoutRefresh(e){return await this._initialize(),this._beforeRequestWithoutInitialize(e)}async _beforeRequest(e){return await this._initialize(),await this.getAccessToken(),this.beforeRequestWithoutRefresh(e)}async getAppConfig(){return await this.fetch(r,{params:{app_id:this.appId},onRequest:this._beforeRequestWithoutInitialize.bind(this)})}async _getOrGenerateClientAnalyticsId(){if(this._analyticsId)return this._analyticsId;try{let e=await this._storage.get(p);if("string"==typeof e&&e.length>0)return this._analyticsId=e,e}catch(e){this.logger.error("Unable to load clientId",e)}try{this._analyticsId=t()}catch(e){this.logger.error("Unable to generate uuidv4",e)}if(!this._analyticsId)return null;try{await this._storage.put(p,this._analyticsId)}catch(e){this.logger.error(`Unable to store clientId: ${this._analyticsId}`,e)}return this._analyticsId}async destroyClientAnalyticsId(){try{return await this._storage.del(p)}catch(e){this.logger.error("Unable to delete clientId",e)}}async createAnalyticsEvent(e,t){try{await this.fetch(a,{body:{event_name:e,client_id:await this._getOrGenerateClientAnalyticsId(),payload:t},onRequest:this.beforeRequestWithoutRefresh.bind(this)})}catch(e){}}async refreshSession(e=!1){if(!await this.isStorageAccessible())throw new o({code:"storage_error",error:"Unable to access storage"});let t=await this.session.getRefreshToken()??void 0,s=t??"key",i=this._cache.get(s);if(i)return this.logger.debug("[privy:refresh] found in-flight session refresh request, deduping"),await i;let r=this._refreshSession(t,e);this._cache.set(s,r);try{return await r}finally{this._cache.delete(s)}}async _refreshSession(e,t){let i=await this.session.getToken();if(!this.session.hasRefreshCredentials(i,e??null))throw this.logger.debug("[privy:refresh] missing tokens, skipping request"),await this._initialize(),new h({code:s.MISSING_OR_INVALID_TOKEN,error:"No tokens found in storage"});try{this.logger.debug(`[privy:refresh] fetching: ${n.path}`);let s=await this.fetch(n,{body:{refresh_token:e},onRequest:this.beforeRequestWithoutRefresh.bind(this)}),i=s.session_update_action;return this.logger.debug(`[privy:refresh] response: ${i}`),t||this.callbacks?.setUser?.(s.user),"set"===i&&(await this.session.updateWithTokensResponse(s),this.logger.debug("[privy:refresh] tokens stored")),"clear"===i&&(await this.session.destroyLocalState(),this.logger.debug("[privy:refresh] tokens cleared"),t||this.callbacks?.setUser?.(null)),"ignore"===i&&s.token&&(await this.session.storeToken(s.token),this.logger.debug("[privy:refresh] access token stored"),s.identity_token&&(this.logger.debug("[privy:refresh] identity token stored"),await this.session.storeIdentityToken(s.identity_token))),this.logger.debug("[privy:refresh] returning response"),s}catch(e){throw this.logger.debug(`[privy:refresh] error: ${e.message??"unknown error"}`),e instanceof h&&e.code===s.MISSING_OR_INVALID_TOKEN&&(await this.session.destroyLocalState(),t||this.callbacks?.setUser?.(null)),e}}async getAccessToken(){let[e,t]=await Promise.all([this.session.getToken(),this.session.getRefreshToken()]);if(!this.session.tokenIsActive(e)&&this.session.hasRefreshCredentials(e,t)){let t=await this.refreshSession(),s=await this.session.getToken();return t.token||this.logger.debug("[privy:getAccessToken] expected token received null"),t.token===e&&this.logger.debug("[privy:getAccessToken] expected new token in response received existing"),s===e&&this.logger.debug("[privy:getAccessToken] expected new token in storage received existing"),t.token??s}return e}async getIdentityToken(){return await this.session.getIdentityToken()}async isStorageAccessible(){try{let e=`privy:__storage__test-${t()}`,s="blobby";await this._storage.put(e,s);let i=await this._storage.get(e);return await this._storage.del(e),i===s}catch(e){return this.logger.error(e),!1}}constructor(t){this._sdkVersion="js-sdk-core:0.56.0",this._cache=new Map,this.logger=d({level:t.logLevel??"ERROR"}),this._storage=t.storage,this._analyticsId=null,this._getOrGenerateClientAnalyticsId(),this.baseUrl=t.baseUrl??"https://auth.privy.io",this.appId=t.appId,this.appClientId=t.appClientId,this._sdkVersion=t.sdkVersion??this._sdkVersion,this.callbacks=t.callbacks,this.nativeAppIdentifier=t.nativeAppIdentifier,this.session=new l({storage:this._storage,isUsingServerCookies:!1,appId:t.appId}),this._fetch=e(globalThis.fetch,{retries:3,retryDelay:e=>3**e*500,retryOn:[408,409,425,500,502,503,504]}),this.session.on("error_storing_tokens",(e=>{this.createAnalyticsEvent("error_updating_tokens_in_storage",{reason:e})}))}}export{u as PrivyInternal};
1
+ import e from"fetch-retry";import{v4 as t}from"uuid";import{PrivyErrorCode as s}from"@privy-io/api-base";import{getPathWithParams as i,AppConfig as r,AnalyticsEvent as a,RefreshSession as n}from"@privy-io/public-api";import{PrivyClientError as o,PrivyApiError as h}from"../Error.mjs";import{Session as l}from"../Session.mjs";import c from"../toAbortSignalTimeout.mjs";import{toSearchParams as g}from"../utils/toSearchParams.mjs";import{toConsoleLogger as d}from"./logger.mjs";import"eventemitter3";import"jose";import"js-cookie";import"../Token.mjs";import"../utils/allSettled.mjs";import"../utils/noop.mjs";let p="privy:caid";class u{setCallbacks(e){this.callbacks={...this.callbacks,...e}}get isReady(){return!!this._config}get config(){return this._config}get caid(){return this._analyticsId}async _initialize(){if(this.isReady)this.callbacks?.setIsReady?.(!0);else{if(!await this.isStorageAccessible())throw new o({code:"storage_error",error:"Unable to access storage"});this._config=await this.getAppConfig(),this._config?.custom_api_url&&(this.baseUrl=this._config.custom_api_url,this.session.isUsingServerCookies=!0),this.callbacks?.setIsReady?.(!0),this._sdkVersion.startsWith("react-auth:")||this.createAnalyticsEvent("sdk_initialize",{})}}getPath(e,{params:t,query:s}){return`${this.baseUrl}${i(e.path,t)}${g(s)}`}async fetch(e,{body:t,params:s,query:i,headers:r,onRequest:a=this._beforeRequest.bind(this)}){let n=new Request(this.getPath(e,{params:s,query:i}),{method:e.method,body:JSON.stringify(t),headers:r}),o=await a(n),l=await this._fetch(n,o),c=await l.json();if(l.status>299)throw new h(c);return c}async _beforeRequestWithoutInitialize(e){let t=await this.session.getToken(),s=new Headers(e.headers);s.set("privy-app-id",this.appId),this.appClientId&&s.set("privy-client-id",this.appClientId),s.set("privy-client",this._sdkVersion),t&&s.set("Authorization",`Bearer ${t}`),s.set("Content-Type","application/json"),s.set("Accept","application/json");let i=await this._getOrGenerateClientAnalyticsId();return i&&s.set("privy-ca-id",i),this.nativeAppIdentifier&&s.set("x-native-app-identifier",this.nativeAppIdentifier),{signal:c(2e4),headers:s,credentials:"include"}}async beforeRequestWithoutRefresh(e){return await this._initialize(),this._beforeRequestWithoutInitialize(e)}async _beforeRequest(e){return await this._initialize(),await this.getAccessToken(),this.beforeRequestWithoutRefresh(e)}async getAppConfig(){return await this.fetch(r,{params:{app_id:this.appId},onRequest:this._beforeRequestWithoutInitialize.bind(this)})}async _getOrGenerateClientAnalyticsId(){if(this._analyticsId)return this._analyticsId;try{let e=await this._storage.get(p);if("string"==typeof e&&e.length>0)return this._analyticsId=e,e}catch(e){this.logger.error("Unable to load clientId",e)}try{this._analyticsId=t()}catch(e){this.logger.error("Unable to generate uuidv4",e)}if(!this._analyticsId)return null;try{await this._storage.put(p,this._analyticsId)}catch(e){this.logger.error(`Unable to store clientId: ${this._analyticsId}`,e)}return this._analyticsId}async destroyClientAnalyticsId(){try{return await this._storage.del(p)}catch(e){this.logger.error("Unable to delete clientId",e)}}async createAnalyticsEvent(e,t){try{await this.fetch(a,{body:{event_name:e,client_id:await this._getOrGenerateClientAnalyticsId(),payload:t},onRequest:this.beforeRequestWithoutRefresh.bind(this)})}catch(e){}}async refreshSession(e=!1){if(!await this.isStorageAccessible())throw new o({code:"storage_error",error:"Unable to access storage"});let t=await this.session.getRefreshToken()??void 0,s=t??"key",i=this._cache.get(s);if(i)return this.logger.debug("[privy:refresh] found in-flight session refresh request, deduping"),await i;let r=this._refreshSession(t,e);this._cache.set(s,r);try{return await r}finally{this._cache.delete(s)}}async _refreshSession(e,t){let i=await this.session.getToken();if(!this.session.hasRefreshCredentials(i,e??null))throw this.logger.debug("[privy:refresh] missing tokens, skipping request"),await this._initialize(),new h({code:s.MISSING_OR_INVALID_TOKEN,error:"No tokens found in storage"});try{this.logger.debug(`[privy:refresh] fetching: ${n.path}`);let s=await this.fetch(n,{body:{refresh_token:e},onRequest:this.beforeRequestWithoutRefresh.bind(this)}),i=s.session_update_action;return this.logger.debug(`[privy:refresh] response: ${i}`),t||this.callbacks?.setUser?.(s.user),"set"===i&&(await this.session.updateWithTokensResponse(s),this.logger.debug("[privy:refresh] tokens stored")),"clear"===i&&(await this.session.destroyLocalState(),this.logger.debug("[privy:refresh] tokens cleared"),t||this.callbacks?.setUser?.(null)),"ignore"===i&&s.token&&(await this.session.storeToken(s.token),this.logger.debug("[privy:refresh] access token stored"),s.identity_token&&(this.logger.debug("[privy:refresh] identity token stored"),await this.session.storeIdentityToken(s.identity_token))),this.logger.debug("[privy:refresh] returning response"),s}catch(e){throw this.logger.debug(`[privy:refresh] error: ${e.message??"unknown error"}`),e instanceof h&&e.code===s.MISSING_OR_INVALID_TOKEN&&(await this.session.destroyLocalState(),t||this.callbacks?.setUser?.(null)),e}}async getAccessToken(){let[e,t]=await Promise.all([this.session.getToken(),this.session.getRefreshToken()]);if(!this.session.tokenIsActive(e)&&this.session.hasRefreshCredentials(e,t)){let t=await this.refreshSession(),s=await this.session.getToken();return t.token||this.logger.debug("[privy:getAccessToken] expected token received null"),t.token===e&&this.logger.debug("[privy:getAccessToken] expected new token in response received existing"),s===e&&this.logger.debug("[privy:getAccessToken] expected new token in storage received existing"),t.token??s}return e}async getIdentityToken(){return await this.session.getIdentityToken()}async isStorageAccessible(){try{let e=`privy:__storage__test-${t()}`,s="blobby";await this._storage.put(e,s);let i=await this._storage.get(e);return await this._storage.del(e),i===s}catch(e){return this.logger.error(e),!1}}constructor(t){this._sdkVersion="js-sdk-core:0.56.1-beta-20251010144542",this._cache=new Map,this.logger=d({level:t.logLevel??"ERROR"}),this._storage=t.storage,this._analyticsId=null,this._getOrGenerateClientAnalyticsId(),this.baseUrl=t.baseUrl??"https://auth.privy.io",this.appId=t.appId,this.appClientId=t.appClientId,this._sdkVersion=t.sdkVersion??this._sdkVersion,this.callbacks=t.callbacks,this.nativeAppIdentifier=t.nativeAppIdentifier,this.session=new l({storage:this._storage,isUsingServerCookies:!1,appId:t.appId}),this._fetch=e(globalThis.fetch,{retries:3,retryDelay:e=>3**e*500,retryOn:[408,409,425,500,502,503,504]}),this.session.on("error_storing_tokens",(e=>{this.createAnalyticsEvent("error_updating_tokens_in_storage",{reason:e})}))}}export{u as PrivyInternal};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@privy-io/js-sdk-core",
3
- "version": "0.56.0",
3
+ "version": "0.56.1-beta-20251010144542",
4
4
  "description": "Vanilla JS client for the Privy Auth API",
5
5
  "keywords": [
6
6
  "authentication",
@@ -63,7 +63,7 @@
63
63
  ],
64
64
  "dependencies": {
65
65
  "@privy-io/api-base": "1.7.1",
66
- "@privy-io/public-api": "2.48.0",
66
+ "@privy-io/public-api": "2.49.0-beta-20251010144542",
67
67
  "@privy-io/ethereum": "0.0.2",
68
68
  "canonicalize": "^2.0.0",
69
69
  "@privy-io/chains": "0.0.2",