@privy-io/js-sdk-core 0.50.2 → 0.50.3

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.50.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.50.3",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})}))}};
@@ -1027,6 +1027,7 @@ declare class EmbeddedWalletApi {
1027
1027
  first_verified_at: number | null;
1028
1028
  latest_verified_at: number | null;
1029
1029
  phoneNumber: string;
1030
+ number?: string | undefined;
1030
1031
  } | {
1031
1032
  type: "wallet";
1032
1033
  address: string;
@@ -1439,6 +1440,7 @@ declare class UserApi {
1439
1440
  first_verified_at: number | null;
1440
1441
  latest_verified_at: number | null;
1441
1442
  phoneNumber: string;
1443
+ number?: string | undefined;
1442
1444
  } | {
1443
1445
  type: "wallet";
1444
1446
  address: string;
@@ -1748,6 +1750,7 @@ declare class EmailApi {
1748
1750
  first_verified_at: number | null;
1749
1751
  latest_verified_at: number | null;
1750
1752
  phoneNumber: string;
1753
+ number?: string | undefined;
1751
1754
  } | {
1752
1755
  type: "wallet";
1753
1756
  address: string;
@@ -2022,6 +2025,7 @@ declare class EmailApi {
2022
2025
  first_verified_at: number | null;
2023
2026
  latest_verified_at: number | null;
2024
2027
  phoneNumber: string;
2028
+ number?: string | undefined;
2025
2029
  } | {
2026
2030
  type: "wallet";
2027
2031
  address: string;
@@ -2285,6 +2289,7 @@ declare class EmailApi {
2285
2289
  first_verified_at: number | null;
2286
2290
  latest_verified_at: number | null;
2287
2291
  phoneNumber: string;
2292
+ number?: string | undefined;
2288
2293
  } | {
2289
2294
  type: "wallet";
2290
2295
  address: string;
@@ -2583,6 +2588,7 @@ declare class FarcasterApi {
2583
2588
  first_verified_at: number | null;
2584
2589
  latest_verified_at: number | null;
2585
2590
  phoneNumber: string;
2591
+ number?: string | undefined;
2586
2592
  } | {
2587
2593
  type: "wallet";
2588
2594
  address: string;
@@ -2851,6 +2857,7 @@ declare class FarcasterApi {
2851
2857
  first_verified_at: number | null;
2852
2858
  latest_verified_at: number | null;
2853
2859
  phoneNumber: string;
2860
+ number?: string | undefined;
2854
2861
  } | {
2855
2862
  type: "wallet";
2856
2863
  address: string;
@@ -3167,6 +3174,7 @@ declare class OAuthApi {
3167
3174
  first_verified_at: number | null;
3168
3175
  latest_verified_at: number | null;
3169
3176
  phoneNumber: string;
3177
+ number?: string | undefined;
3170
3178
  } | {
3171
3179
  type: "wallet";
3172
3180
  address: string;
@@ -3436,6 +3444,7 @@ declare class OAuthApi {
3436
3444
  first_verified_at: number | null;
3437
3445
  latest_verified_at: number | null;
3438
3446
  phoneNumber: string;
3447
+ number?: string | undefined;
3439
3448
  } | {
3440
3449
  type: "wallet";
3441
3450
  address: string;
@@ -3825,6 +3834,7 @@ declare class PasskeyApi {
3825
3834
  first_verified_at: number | null;
3826
3835
  latest_verified_at: number | null;
3827
3836
  phoneNumber: string;
3837
+ number?: string | undefined;
3828
3838
  } | {
3829
3839
  type: "wallet";
3830
3840
  address: string;
@@ -4114,6 +4124,7 @@ declare class PhoneApi {
4114
4124
  first_verified_at: number | null;
4115
4125
  latest_verified_at: number | null;
4116
4126
  phoneNumber: string;
4127
+ number?: string | undefined;
4117
4128
  } | {
4118
4129
  type: "wallet";
4119
4130
  address: string;
@@ -4388,6 +4399,7 @@ declare class PhoneApi {
4388
4399
  first_verified_at: number | null;
4389
4400
  latest_verified_at: number | null;
4390
4401
  phoneNumber: string;
4402
+ number?: string | undefined;
4391
4403
  } | {
4392
4404
  type: "wallet";
4393
4405
  address: string;
@@ -4651,6 +4663,7 @@ declare class PhoneApi {
4651
4663
  first_verified_at: number | null;
4652
4664
  latest_verified_at: number | null;
4653
4665
  phoneNumber: string;
4666
+ number?: string | undefined;
4654
4667
  } | {
4655
4668
  type: "wallet";
4656
4669
  address: string;
@@ -4985,6 +4998,7 @@ declare class SiweApi {
4985
4998
  first_verified_at: number | null;
4986
4999
  latest_verified_at: number | null;
4987
5000
  phoneNumber: string;
5001
+ number?: string | undefined;
4988
5002
  } | {
4989
5003
  type: "wallet";
4990
5004
  address: string;
@@ -5265,6 +5279,7 @@ declare class SiweApi {
5265
5279
  first_verified_at: number | null;
5266
5280
  latest_verified_at: number | null;
5267
5281
  phoneNumber: string;
5282
+ number?: string | undefined;
5268
5283
  } | {
5269
5284
  type: "wallet";
5270
5285
  address: string;
@@ -5578,6 +5593,7 @@ declare class SiwsApi {
5578
5593
  first_verified_at: number | null;
5579
5594
  latest_verified_at: number | null;
5580
5595
  phoneNumber: string;
5596
+ number?: string | undefined;
5581
5597
  } | {
5582
5598
  type: "wallet";
5583
5599
  address: string;
@@ -5863,6 +5879,7 @@ declare class SiwsApi {
5863
5879
  first_verified_at: number | null;
5864
5880
  latest_verified_at: number | null;
5865
5881
  phoneNumber: string;
5882
+ number?: string | undefined;
5866
5883
  } | {
5867
5884
  type: "wallet";
5868
5885
  address: string;
@@ -6183,6 +6200,7 @@ declare class SmartWalletApi {
6183
6200
  first_verified_at: number | null;
6184
6201
  latest_verified_at: number | null;
6185
6202
  phoneNumber: string;
6203
+ number?: string | undefined;
6186
6204
  } | {
6187
6205
  type: "wallet";
6188
6206
  address: string;
@@ -7180,6 +7198,7 @@ declare const delegateWallet: (client: Privy) => ({ address, chainType }: Delega
7180
7198
  first_verified_at: number | null;
7181
7199
  latest_verified_at: number | null;
7182
7200
  phoneNumber: string;
7201
+ number?: string | undefined;
7183
7202
  } | {
7184
7203
  type: "wallet";
7185
7204
  address: string;
@@ -7451,6 +7470,7 @@ declare const revokeWallets: (client: Privy) => () => Promise<{
7451
7470
  first_verified_at: number | null;
7452
7471
  latest_verified_at: number | null;
7453
7472
  phoneNumber: string;
7473
+ number?: string | undefined;
7454
7474
  } | {
7455
7475
  type: "wallet";
7456
7476
  address: string;
@@ -1027,6 +1027,7 @@ declare class EmbeddedWalletApi {
1027
1027
  first_verified_at: number | null;
1028
1028
  latest_verified_at: number | null;
1029
1029
  phoneNumber: string;
1030
+ number?: string | undefined;
1030
1031
  } | {
1031
1032
  type: "wallet";
1032
1033
  address: string;
@@ -1439,6 +1440,7 @@ declare class UserApi {
1439
1440
  first_verified_at: number | null;
1440
1441
  latest_verified_at: number | null;
1441
1442
  phoneNumber: string;
1443
+ number?: string | undefined;
1442
1444
  } | {
1443
1445
  type: "wallet";
1444
1446
  address: string;
@@ -1748,6 +1750,7 @@ declare class EmailApi {
1748
1750
  first_verified_at: number | null;
1749
1751
  latest_verified_at: number | null;
1750
1752
  phoneNumber: string;
1753
+ number?: string | undefined;
1751
1754
  } | {
1752
1755
  type: "wallet";
1753
1756
  address: string;
@@ -2022,6 +2025,7 @@ declare class EmailApi {
2022
2025
  first_verified_at: number | null;
2023
2026
  latest_verified_at: number | null;
2024
2027
  phoneNumber: string;
2028
+ number?: string | undefined;
2025
2029
  } | {
2026
2030
  type: "wallet";
2027
2031
  address: string;
@@ -2285,6 +2289,7 @@ declare class EmailApi {
2285
2289
  first_verified_at: number | null;
2286
2290
  latest_verified_at: number | null;
2287
2291
  phoneNumber: string;
2292
+ number?: string | undefined;
2288
2293
  } | {
2289
2294
  type: "wallet";
2290
2295
  address: string;
@@ -2583,6 +2588,7 @@ declare class FarcasterApi {
2583
2588
  first_verified_at: number | null;
2584
2589
  latest_verified_at: number | null;
2585
2590
  phoneNumber: string;
2591
+ number?: string | undefined;
2586
2592
  } | {
2587
2593
  type: "wallet";
2588
2594
  address: string;
@@ -2851,6 +2857,7 @@ declare class FarcasterApi {
2851
2857
  first_verified_at: number | null;
2852
2858
  latest_verified_at: number | null;
2853
2859
  phoneNumber: string;
2860
+ number?: string | undefined;
2854
2861
  } | {
2855
2862
  type: "wallet";
2856
2863
  address: string;
@@ -3167,6 +3174,7 @@ declare class OAuthApi {
3167
3174
  first_verified_at: number | null;
3168
3175
  latest_verified_at: number | null;
3169
3176
  phoneNumber: string;
3177
+ number?: string | undefined;
3170
3178
  } | {
3171
3179
  type: "wallet";
3172
3180
  address: string;
@@ -3436,6 +3444,7 @@ declare class OAuthApi {
3436
3444
  first_verified_at: number | null;
3437
3445
  latest_verified_at: number | null;
3438
3446
  phoneNumber: string;
3447
+ number?: string | undefined;
3439
3448
  } | {
3440
3449
  type: "wallet";
3441
3450
  address: string;
@@ -3825,6 +3834,7 @@ declare class PasskeyApi {
3825
3834
  first_verified_at: number | null;
3826
3835
  latest_verified_at: number | null;
3827
3836
  phoneNumber: string;
3837
+ number?: string | undefined;
3828
3838
  } | {
3829
3839
  type: "wallet";
3830
3840
  address: string;
@@ -4114,6 +4124,7 @@ declare class PhoneApi {
4114
4124
  first_verified_at: number | null;
4115
4125
  latest_verified_at: number | null;
4116
4126
  phoneNumber: string;
4127
+ number?: string | undefined;
4117
4128
  } | {
4118
4129
  type: "wallet";
4119
4130
  address: string;
@@ -4388,6 +4399,7 @@ declare class PhoneApi {
4388
4399
  first_verified_at: number | null;
4389
4400
  latest_verified_at: number | null;
4390
4401
  phoneNumber: string;
4402
+ number?: string | undefined;
4391
4403
  } | {
4392
4404
  type: "wallet";
4393
4405
  address: string;
@@ -4651,6 +4663,7 @@ declare class PhoneApi {
4651
4663
  first_verified_at: number | null;
4652
4664
  latest_verified_at: number | null;
4653
4665
  phoneNumber: string;
4666
+ number?: string | undefined;
4654
4667
  } | {
4655
4668
  type: "wallet";
4656
4669
  address: string;
@@ -4985,6 +4998,7 @@ declare class SiweApi {
4985
4998
  first_verified_at: number | null;
4986
4999
  latest_verified_at: number | null;
4987
5000
  phoneNumber: string;
5001
+ number?: string | undefined;
4988
5002
  } | {
4989
5003
  type: "wallet";
4990
5004
  address: string;
@@ -5265,6 +5279,7 @@ declare class SiweApi {
5265
5279
  first_verified_at: number | null;
5266
5280
  latest_verified_at: number | null;
5267
5281
  phoneNumber: string;
5282
+ number?: string | undefined;
5268
5283
  } | {
5269
5284
  type: "wallet";
5270
5285
  address: string;
@@ -5578,6 +5593,7 @@ declare class SiwsApi {
5578
5593
  first_verified_at: number | null;
5579
5594
  latest_verified_at: number | null;
5580
5595
  phoneNumber: string;
5596
+ number?: string | undefined;
5581
5597
  } | {
5582
5598
  type: "wallet";
5583
5599
  address: string;
@@ -5863,6 +5879,7 @@ declare class SiwsApi {
5863
5879
  first_verified_at: number | null;
5864
5880
  latest_verified_at: number | null;
5865
5881
  phoneNumber: string;
5882
+ number?: string | undefined;
5866
5883
  } | {
5867
5884
  type: "wallet";
5868
5885
  address: string;
@@ -6183,6 +6200,7 @@ declare class SmartWalletApi {
6183
6200
  first_verified_at: number | null;
6184
6201
  latest_verified_at: number | null;
6185
6202
  phoneNumber: string;
6203
+ number?: string | undefined;
6186
6204
  } | {
6187
6205
  type: "wallet";
6188
6206
  address: string;
@@ -7180,6 +7198,7 @@ declare const delegateWallet: (client: Privy) => ({ address, chainType }: Delega
7180
7198
  first_verified_at: number | null;
7181
7199
  latest_verified_at: number | null;
7182
7200
  phoneNumber: string;
7201
+ number?: string | undefined;
7183
7202
  } | {
7184
7203
  type: "wallet";
7185
7204
  address: string;
@@ -7451,6 +7470,7 @@ declare const revokeWallets: (client: Privy) => () => Promise<{
7451
7470
  first_verified_at: number | null;
7452
7471
  latest_verified_at: number | null;
7453
7472
  phoneNumber: string;
7473
+ number?: string | undefined;
7454
7474
  } | {
7455
7475
  type: "wallet";
7456
7476
  address: string;
@@ -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.50.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.50.3",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.50.2",
3
+ "version": "0.50.3",
4
4
  "description": "Vanilla JS client for the Privy Auth API",
5
5
  "keywords": [
6
6
  "authentication",
@@ -68,7 +68,7 @@
68
68
  "@ethersproject/transactions": "^5.7.0",
69
69
  "@ethersproject/units": "^5.7.0",
70
70
  "@privy-io/api-base": "1.5.1",
71
- "@privy-io/public-api": "2.26.0",
71
+ "@privy-io/public-api": "2.27.0",
72
72
  "canonicalize": "^2.0.0",
73
73
  "@privy-io/chains": "0.0.1",
74
74
  "eventemitter3": "^5.0.1",