@privy-io/js-sdk-core 0.55.2 → 0.55.3-beta-20250925222239

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.55.2",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.55.3-beta-20250925222239",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})}))}};
@@ -1172,7 +1172,7 @@ declare class EmbeddedWalletApi {
1172
1172
  type: "wallet";
1173
1173
  id: string | null;
1174
1174
  address: string;
1175
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
1175
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
1176
1176
  chain_id: string;
1177
1177
  verified_at: number;
1178
1178
  first_verified_at: number | null;
@@ -1612,7 +1612,7 @@ declare class UserApi {
1612
1612
  type: "wallet";
1613
1613
  id: string | null;
1614
1614
  address: string;
1615
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
1615
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
1616
1616
  chain_id: string;
1617
1617
  verified_at: number;
1618
1618
  first_verified_at: number | null;
@@ -1949,7 +1949,7 @@ declare class EmailApi {
1949
1949
  type: "wallet";
1950
1950
  id: string | null;
1951
1951
  address: string;
1952
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
1952
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
1953
1953
  chain_id: string;
1954
1954
  verified_at: number;
1955
1955
  first_verified_at: number | null;
@@ -2251,7 +2251,7 @@ declare class EmailApi {
2251
2251
  type: "wallet";
2252
2252
  id: string | null;
2253
2253
  address: string;
2254
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
2254
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
2255
2255
  chain_id: string;
2256
2256
  verified_at: number;
2257
2257
  first_verified_at: number | null;
@@ -2542,7 +2542,7 @@ declare class EmailApi {
2542
2542
  type: "wallet";
2543
2543
  id: string | null;
2544
2544
  address: string;
2545
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
2545
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
2546
2546
  chain_id: string;
2547
2547
  verified_at: number;
2548
2548
  first_verified_at: number | null;
@@ -2868,7 +2868,7 @@ declare class FarcasterApi {
2868
2868
  type: "wallet";
2869
2869
  id: string | null;
2870
2870
  address: string;
2871
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
2871
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
2872
2872
  chain_id: string;
2873
2873
  verified_at: number;
2874
2874
  first_verified_at: number | null;
@@ -3164,7 +3164,7 @@ declare class FarcasterApi {
3164
3164
  type: "wallet";
3165
3165
  id: string | null;
3166
3166
  address: string;
3167
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
3167
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
3168
3168
  chain_id: string;
3169
3169
  verified_at: number;
3170
3170
  first_verified_at: number | null;
@@ -3508,7 +3508,7 @@ declare class OAuthApi {
3508
3508
  type: "wallet";
3509
3509
  id: string | null;
3510
3510
  address: string;
3511
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
3511
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
3512
3512
  chain_id: string;
3513
3513
  verified_at: number;
3514
3514
  first_verified_at: number | null;
@@ -3805,7 +3805,7 @@ declare class OAuthApi {
3805
3805
  type: "wallet";
3806
3806
  id: string | null;
3807
3807
  address: string;
3808
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
3808
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
3809
3809
  chain_id: string;
3810
3810
  verified_at: number;
3811
3811
  first_verified_at: number | null;
@@ -4222,7 +4222,7 @@ declare class PasskeyApi {
4222
4222
  type: "wallet";
4223
4223
  id: string | null;
4224
4224
  address: string;
4225
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
4225
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
4226
4226
  chain_id: string;
4227
4227
  verified_at: number;
4228
4228
  first_verified_at: number | null;
@@ -4539,7 +4539,7 @@ declare class PhoneApi {
4539
4539
  type: "wallet";
4540
4540
  id: string | null;
4541
4541
  address: string;
4542
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
4542
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
4543
4543
  chain_id: string;
4544
4544
  verified_at: number;
4545
4545
  first_verified_at: number | null;
@@ -4841,7 +4841,7 @@ declare class PhoneApi {
4841
4841
  type: "wallet";
4842
4842
  id: string | null;
4843
4843
  address: string;
4844
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
4844
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
4845
4845
  chain_id: string;
4846
4846
  verified_at: number;
4847
4847
  first_verified_at: number | null;
@@ -5132,7 +5132,7 @@ declare class PhoneApi {
5132
5132
  type: "wallet";
5133
5133
  id: string | null;
5134
5134
  address: string;
5135
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
5135
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
5136
5136
  chain_id: string;
5137
5137
  verified_at: number;
5138
5138
  first_verified_at: number | null;
@@ -5494,7 +5494,7 @@ declare class SiweApi {
5494
5494
  type: "wallet";
5495
5495
  id: string | null;
5496
5496
  address: string;
5497
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
5497
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
5498
5498
  chain_id: string;
5499
5499
  verified_at: number;
5500
5500
  first_verified_at: number | null;
@@ -5802,7 +5802,7 @@ declare class SiweApi {
5802
5802
  type: "wallet";
5803
5803
  id: string | null;
5804
5804
  address: string;
5805
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
5805
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
5806
5806
  chain_id: string;
5807
5807
  verified_at: number;
5808
5808
  first_verified_at: number | null;
@@ -6143,7 +6143,7 @@ declare class SiwsApi {
6143
6143
  type: "wallet";
6144
6144
  id: string | null;
6145
6145
  address: string;
6146
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
6146
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
6147
6147
  chain_id: string;
6148
6148
  verified_at: number;
6149
6149
  first_verified_at: number | null;
@@ -6456,7 +6456,7 @@ declare class SiwsApi {
6456
6456
  type: "wallet";
6457
6457
  id: string | null;
6458
6458
  address: string;
6459
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
6459
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
6460
6460
  chain_id: string;
6461
6461
  verified_at: number;
6462
6462
  first_verified_at: number | null;
@@ -6804,7 +6804,7 @@ declare class SmartWalletApi {
6804
6804
  type: "wallet";
6805
6805
  id: string | null;
6806
6806
  address: string;
6807
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
6807
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
6808
6808
  chain_id: string;
6809
6809
  verified_at: number;
6810
6810
  first_verified_at: number | null;
@@ -7929,7 +7929,7 @@ declare const delegateWallet: (client: Privy) => ({ address, chainType }: Delega
7929
7929
  type: "wallet";
7930
7930
  id: string | null;
7931
7931
  address: string;
7932
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
7932
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
7933
7933
  chain_id: string;
7934
7934
  verified_at: number;
7935
7935
  first_verified_at: number | null;
@@ -8228,7 +8228,7 @@ declare const revokeWallets: (client: Privy) => () => Promise<{
8228
8228
  type: "wallet";
8229
8229
  id: string | null;
8230
8230
  address: string;
8231
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
8231
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
8232
8232
  chain_id: string;
8233
8233
  verified_at: number;
8234
8234
  first_verified_at: number | null;
@@ -1172,7 +1172,7 @@ declare class EmbeddedWalletApi {
1172
1172
  type: "wallet";
1173
1173
  id: string | null;
1174
1174
  address: string;
1175
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
1175
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
1176
1176
  chain_id: string;
1177
1177
  verified_at: number;
1178
1178
  first_verified_at: number | null;
@@ -1612,7 +1612,7 @@ declare class UserApi {
1612
1612
  type: "wallet";
1613
1613
  id: string | null;
1614
1614
  address: string;
1615
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
1615
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
1616
1616
  chain_id: string;
1617
1617
  verified_at: number;
1618
1618
  first_verified_at: number | null;
@@ -1949,7 +1949,7 @@ declare class EmailApi {
1949
1949
  type: "wallet";
1950
1950
  id: string | null;
1951
1951
  address: string;
1952
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
1952
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
1953
1953
  chain_id: string;
1954
1954
  verified_at: number;
1955
1955
  first_verified_at: number | null;
@@ -2251,7 +2251,7 @@ declare class EmailApi {
2251
2251
  type: "wallet";
2252
2252
  id: string | null;
2253
2253
  address: string;
2254
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
2254
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
2255
2255
  chain_id: string;
2256
2256
  verified_at: number;
2257
2257
  first_verified_at: number | null;
@@ -2542,7 +2542,7 @@ declare class EmailApi {
2542
2542
  type: "wallet";
2543
2543
  id: string | null;
2544
2544
  address: string;
2545
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
2545
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
2546
2546
  chain_id: string;
2547
2547
  verified_at: number;
2548
2548
  first_verified_at: number | null;
@@ -2868,7 +2868,7 @@ declare class FarcasterApi {
2868
2868
  type: "wallet";
2869
2869
  id: string | null;
2870
2870
  address: string;
2871
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
2871
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
2872
2872
  chain_id: string;
2873
2873
  verified_at: number;
2874
2874
  first_verified_at: number | null;
@@ -3164,7 +3164,7 @@ declare class FarcasterApi {
3164
3164
  type: "wallet";
3165
3165
  id: string | null;
3166
3166
  address: string;
3167
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
3167
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
3168
3168
  chain_id: string;
3169
3169
  verified_at: number;
3170
3170
  first_verified_at: number | null;
@@ -3508,7 +3508,7 @@ declare class OAuthApi {
3508
3508
  type: "wallet";
3509
3509
  id: string | null;
3510
3510
  address: string;
3511
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
3511
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
3512
3512
  chain_id: string;
3513
3513
  verified_at: number;
3514
3514
  first_verified_at: number | null;
@@ -3805,7 +3805,7 @@ declare class OAuthApi {
3805
3805
  type: "wallet";
3806
3806
  id: string | null;
3807
3807
  address: string;
3808
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
3808
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
3809
3809
  chain_id: string;
3810
3810
  verified_at: number;
3811
3811
  first_verified_at: number | null;
@@ -4222,7 +4222,7 @@ declare class PasskeyApi {
4222
4222
  type: "wallet";
4223
4223
  id: string | null;
4224
4224
  address: string;
4225
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
4225
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
4226
4226
  chain_id: string;
4227
4227
  verified_at: number;
4228
4228
  first_verified_at: number | null;
@@ -4539,7 +4539,7 @@ declare class PhoneApi {
4539
4539
  type: "wallet";
4540
4540
  id: string | null;
4541
4541
  address: string;
4542
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
4542
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
4543
4543
  chain_id: string;
4544
4544
  verified_at: number;
4545
4545
  first_verified_at: number | null;
@@ -4841,7 +4841,7 @@ declare class PhoneApi {
4841
4841
  type: "wallet";
4842
4842
  id: string | null;
4843
4843
  address: string;
4844
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
4844
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
4845
4845
  chain_id: string;
4846
4846
  verified_at: number;
4847
4847
  first_verified_at: number | null;
@@ -5132,7 +5132,7 @@ declare class PhoneApi {
5132
5132
  type: "wallet";
5133
5133
  id: string | null;
5134
5134
  address: string;
5135
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
5135
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
5136
5136
  chain_id: string;
5137
5137
  verified_at: number;
5138
5138
  first_verified_at: number | null;
@@ -5494,7 +5494,7 @@ declare class SiweApi {
5494
5494
  type: "wallet";
5495
5495
  id: string | null;
5496
5496
  address: string;
5497
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
5497
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
5498
5498
  chain_id: string;
5499
5499
  verified_at: number;
5500
5500
  first_verified_at: number | null;
@@ -5802,7 +5802,7 @@ declare class SiweApi {
5802
5802
  type: "wallet";
5803
5803
  id: string | null;
5804
5804
  address: string;
5805
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
5805
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
5806
5806
  chain_id: string;
5807
5807
  verified_at: number;
5808
5808
  first_verified_at: number | null;
@@ -6143,7 +6143,7 @@ declare class SiwsApi {
6143
6143
  type: "wallet";
6144
6144
  id: string | null;
6145
6145
  address: string;
6146
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
6146
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
6147
6147
  chain_id: string;
6148
6148
  verified_at: number;
6149
6149
  first_verified_at: number | null;
@@ -6456,7 +6456,7 @@ declare class SiwsApi {
6456
6456
  type: "wallet";
6457
6457
  id: string | null;
6458
6458
  address: string;
6459
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
6459
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
6460
6460
  chain_id: string;
6461
6461
  verified_at: number;
6462
6462
  first_verified_at: number | null;
@@ -6804,7 +6804,7 @@ declare class SmartWalletApi {
6804
6804
  type: "wallet";
6805
6805
  id: string | null;
6806
6806
  address: string;
6807
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
6807
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
6808
6808
  chain_id: string;
6809
6809
  verified_at: number;
6810
6810
  first_verified_at: number | null;
@@ -7929,7 +7929,7 @@ declare const delegateWallet: (client: Privy) => ({ address, chainType }: Delega
7929
7929
  type: "wallet";
7930
7930
  id: string | null;
7931
7931
  address: string;
7932
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
7932
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
7933
7933
  chain_id: string;
7934
7934
  verified_at: number;
7935
7935
  first_verified_at: number | null;
@@ -8228,7 +8228,7 @@ declare const revokeWallets: (client: Privy) => () => Promise<{
8228
8228
  type: "wallet";
8229
8229
  id: string | null;
8230
8230
  address: string;
8231
- chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "tron" | "bitcoin-segwit" | "near" | "ton";
8231
+ chain_type: "stellar" | "starknet" | "cosmos" | "sui" | "aptos" | "movement" | "tron" | "bitcoin-segwit" | "near" | "ton";
8232
8232
  chain_id: string;
8233
8233
  verified_at: number;
8234
8234
  first_verified_at: number | 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.55.2",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.55.3-beta-20250925222239",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.55.2",
3
+ "version": "0.55.3-beta-20250925222239",
4
4
  "description": "Vanilla JS client for the Privy Auth API",
5
5
  "keywords": [
6
6
  "authentication",
@@ -68,8 +68,8 @@
68
68
  "@ethersproject/providers": "^5.7.2",
69
69
  "@ethersproject/transactions": "^5.7.0",
70
70
  "@ethersproject/units": "^5.7.0",
71
- "@privy-io/api-base": "1.7.0",
72
- "@privy-io/public-api": "2.45.2",
71
+ "@privy-io/api-base": "1.7.1-beta-20250925222239",
72
+ "@privy-io/public-api": "2.46.0-beta-20250925222239",
73
73
  "canonicalize": "^2.0.0",
74
74
  "@privy-io/chains": "0.0.2",
75
75
  "eventemitter3": "^5.0.1",
@@ -83,6 +83,10 @@
83
83
  "devDependencies": {
84
84
  "@privy-io/build-config": "*",
85
85
  "@privy-io/eslint-config-custom": "*",
86
+ "@wallet-standard/base": "*",
87
+ "@wallet-standard/features": "*",
88
+ "@wallet-standard/core": "*",
89
+ "@solana/wallet-standard-features": "*",
86
90
  "@privy-io/tsconfig": "*",
87
91
  "@rollup/plugin-node-resolve": "^15.3.0",
88
92
  "@rollup/plugin-replace": "^6.0.1",