@privy-io/js-sdk-core 0.16.1 → 0.16.2-beta-20240412041721

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.
package/dist/index.js CHANGED
@@ -2868,7 +2868,7 @@ class $99761f88b99b6cb6$export$2e2bcd8739ae039 {
2868
2868
 
2869
2869
 
2870
2870
  var $af98a8a573bb7c25$exports = {};
2871
- $af98a8a573bb7c25$exports = JSON.parse('{"name":"@privy-io/js-sdk-core","version":"0.16.1","description":"Vanilla JS client for the Privy Auth API","keywords":["authentication","authorization","identity","privacy","privy","user data","web3"],"license":"Apache-2.0","source":"./src/index.ts","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"targets":{"main":{"isLibrary":true,"sourceMap":false},"module":{"isLibrary":true,"sourceMap":false}},"files":["dist/**/*","LICENSE","README.md"],"scripts":{"build":"npx parcel build --no-cache","clean":"rm -rf dist .turbo","dev":"npx parcel watch -p 1234","test":"jest --testMatch \\"**/test/**/*.test.ts\\"","test:watch":"npm run test -- --watch","test:ci":"npm run test","lint":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" && npx tsc --noEmit","format":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" --fix"},"devDependencies":{"@privy-io/parcel-config":"*","@privy-io/tsconfig":"*","@simplewebauthn/types":"9.0.1","@tsconfig/node16-strictest-esm":"^1.0.3","@types/jest":"^29.5.11","@types/set-cookie-parser":"^2.4.7","@types/text-encoding":"^0.0.37","msw":"^2.0.13","text-encoding":"^0.7.0","ts-jest":"^29.1.1"},"dependencies":{"@ethersproject/abstract-signer":"^5.7.0","@ethersproject/bignumber":"^5.7.0","@ethersproject/providers":"^5.7.2","@ethersproject/units":"^5.7.0","@privy-io/api-base":"^0.4.6","@privy-io/public-api":"1.11.3","eventemitter3":"^5.0.1","fetch-retry":"^5.0.6","jose":"^4.15.5","js-cookie":"^3.0.5","set-cookie-parser":"^2.6.0","uuid":">=8 <10"},"author":"privy.io","browserslist":["defaults","node >= 18","not op_mini all"],"publishConfig":{"access":"public"}}');
2871
+ $af98a8a573bb7c25$exports = JSON.parse('{"name":"@privy-io/js-sdk-core","version":"0.16.2-beta-20240412041721","description":"Vanilla JS client for the Privy Auth API","keywords":["authentication","authorization","identity","privacy","privy","user data","web3"],"license":"Apache-2.0","source":"./src/index.ts","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"targets":{"main":{"isLibrary":true,"sourceMap":false},"module":{"isLibrary":true,"sourceMap":false}},"files":["dist/**/*","LICENSE","README.md"],"scripts":{"build":"npx parcel build --no-cache","clean":"rm -rf dist .turbo","dev":"npx parcel watch -p 1234","test":"jest --testMatch \\"**/test/**/*.test.ts\\"","test:watch":"npm run test -- --watch","test:ci":"npm run test","lint":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" && npx tsc --noEmit","format":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" --fix"},"devDependencies":{"@privy-io/parcel-config":"*","@privy-io/tsconfig":"*","@simplewebauthn/types":"9.0.1","@tsconfig/node16-strictest-esm":"^1.0.3","@types/jest":"^29.5.11","@types/set-cookie-parser":"^2.4.7","@types/text-encoding":"^0.0.37","msw":"^2.0.13","text-encoding":"^0.7.0","ts-jest":"^29.1.1"},"dependencies":{"@ethersproject/abstract-signer":"^5.7.0","@ethersproject/bignumber":"^5.7.0","@ethersproject/providers":"^5.7.2","@ethersproject/units":"^5.7.0","@privy-io/api-base":"^0.4.6","@privy-io/public-api":"1.11.3","eventemitter3":"^5.0.1","fetch-retry":"^5.0.6","jose":"^4.15.5","js-cookie":"^3.0.5","set-cookie-parser":"^2.6.0","uuid":">=8 <10"},"author":"privy.io","browserslist":["defaults","node >= 18","not op_mini all"],"publishConfig":{"access":"public"}}');
2872
2872
 
2873
2873
 
2874
2874
 
@@ -3029,23 +3029,21 @@ class $4a5ceffc04a8e7b0$export$1fb4852a55678982 extends (0, ($parcel$interopDefa
3029
3029
  /**
3030
3030
  * Accepts an optional options object to specify the reason storage is being cleared
3031
3031
  */ async destroyLocalState(opts) {
3032
- if (opts?.reason) this.emit("storage_cleared", {
3033
- reason: opts.reason
3034
- });
3035
- return Promise.all([
3032
+ const res = await Promise.all([
3036
3033
  this._storage.del($4a5ceffc04a8e7b0$var$TOKEN_STORAGE_KEY),
3037
3034
  this._storage.del($4a5ceffc04a8e7b0$var$REFRESH_TOKEN_STORAGE_KEY),
3038
3035
  this.clearForkedToken()
3039
3036
  ]);
3037
+ // TODO: We should always emit (even without reason), but only if the value has changed
3038
+ if (opts?.reason) this.emit("storage_cleared", {
3039
+ reason: opts.reason
3040
+ });
3041
+ return res;
3040
3042
  }
3041
3043
  async storeToken(token) {
3042
3044
  if (typeof token === "string") {
3043
3045
  const previousToken = await this._storage.get($4a5ceffc04a8e7b0$var$TOKEN_STORAGE_KEY);
3044
3046
  await this._storage.put($4a5ceffc04a8e7b0$var$TOKEN_STORAGE_KEY, token);
3045
- // if the token being stored is new, trigger the storage callback
3046
- if (previousToken !== token) this.emit("token_stored", {
3047
- cookiesEnabled: this._isUsingServerCookies
3048
- });
3049
3047
  if (!this._isUsingServerCookies) {
3050
3048
  const exp = (0, $4c28dd58a3e1b414$export$50792b0e93539fde).parse(token)?.expiration;
3051
3049
  (0, ($parcel$interopDefault($bwzhE$jscookie))).set($4a5ceffc04a8e7b0$var$TOKEN_COOKIE_KEY, token, {
@@ -3054,20 +3052,22 @@ class $4a5ceffc04a8e7b0$export$1fb4852a55678982 extends (0, ($parcel$interopDefa
3054
3052
  expires: exp ? new Date(exp * 1000) : undefined
3055
3053
  });
3056
3054
  }
3055
+ // If the token being stored is new, trigger the storage callback
3056
+ if (previousToken !== token) this.emit("token_stored", {
3057
+ cookiesEnabled: this._isUsingServerCookies
3058
+ });
3057
3059
  } else {
3060
+ const previousToken = await this._storage.get($4a5ceffc04a8e7b0$var$TOKEN_STORAGE_KEY);
3058
3061
  await this._storage.del($4a5ceffc04a8e7b0$var$TOKEN_STORAGE_KEY);
3059
- this.emit("token_cleared", {
3062
+ (0, ($parcel$interopDefault($bwzhE$jscookie))).remove($4a5ceffc04a8e7b0$var$TOKEN_COOKIE_KEY);
3063
+ if (previousToken !== null) this.emit("token_cleared", {
3060
3064
  reason: "set_with_non_string_value"
3061
3065
  });
3062
- (0, ($parcel$interopDefault($bwzhE$jscookie))).remove($4a5ceffc04a8e7b0$var$TOKEN_COOKIE_KEY);
3063
3066
  }
3064
3067
  }
3065
3068
  async storeRefreshToken(refreshToken) {
3066
3069
  if (typeof refreshToken === "string") {
3067
3070
  await this._storage.put($4a5ceffc04a8e7b0$var$REFRESH_TOKEN_STORAGE_KEY, refreshToken);
3068
- this.emit("refresh_token_stored", {
3069
- cookiesEnabled: this._isUsingServerCookies
3070
- });
3071
3071
  if (!this._isUsingServerCookies) {
3072
3072
  (0, ($parcel$interopDefault($bwzhE$jscookie))).set($4a5ceffc04a8e7b0$var$SESSION_COOKIE_KEY, "t", {
3073
3073
  sameSite: "Strict",
@@ -3084,13 +3084,20 @@ class $4a5ceffc04a8e7b0$export$1fb4852a55678982 extends (0, ($parcel$interopDefa
3084
3084
  expires: 30
3085
3085
  });
3086
3086
  }
3087
+ // TODO: We don't do this in react-auth because we don't have a use for it
3088
+ // TODO: Make conditional on whether the value was present
3089
+ this.emit("refresh_token_stored", {
3090
+ cookiesEnabled: this._isUsingServerCookies
3091
+ });
3087
3092
  } else {
3088
3093
  await this._storage.del($4a5ceffc04a8e7b0$var$REFRESH_TOKEN_STORAGE_KEY);
3094
+ (0, ($parcel$interopDefault($bwzhE$jscookie))).remove($4a5ceffc04a8e7b0$var$REFRESH_TOKEN_COOKIE_KEY);
3095
+ (0, ($parcel$interopDefault($bwzhE$jscookie))).remove($4a5ceffc04a8e7b0$var$SESSION_COOKIE_KEY);
3096
+ // TODO: We don't do this in react-auth because we don't have a use for it
3097
+ // TODO: Make conditional on whether the value was present
3089
3098
  this.emit("refresh_token_cleared", {
3090
3099
  reason: "set_with_non_string_value"
3091
3100
  });
3092
- (0, ($parcel$interopDefault($bwzhE$jscookie))).remove($4a5ceffc04a8e7b0$var$REFRESH_TOKEN_COOKIE_KEY);
3093
- (0, ($parcel$interopDefault($bwzhE$jscookie))).remove($4a5ceffc04a8e7b0$var$SESSION_COOKIE_KEY);
3094
3101
  }
3095
3102
  }
3096
3103
  async clearForkedToken() {
@@ -3446,8 +3453,10 @@ class $5945f4703f62befa$export$9e80c3751b841788 {
3446
3453
  this.session.getRefreshToken()
3447
3454
  ]);
3448
3455
  if (!this.session.tokenIsActive(token) && this.session.hasRefreshCredentials(token, refreshToken)) try {
3449
- const { token: token } = await this.refreshSession();
3450
- return token;
3456
+ await this.refreshSession();
3457
+ // Return stored token, since there's some chance due to race condition that the token
3458
+ // returned by refreshSession is null even though session is valid
3459
+ return await this.session.getToken();
3451
3460
  } catch (error) {
3452
3461
  return null;
3453
3462
  }
package/dist/index.mjs CHANGED
@@ -2831,7 +2831,7 @@ class $a3295537bbaaa670$export$2e2bcd8739ae039 {
2831
2831
 
2832
2832
 
2833
2833
  var $53a9b3651331d972$exports = {};
2834
- $53a9b3651331d972$exports = JSON.parse('{"name":"@privy-io/js-sdk-core","version":"0.16.1","description":"Vanilla JS client for the Privy Auth API","keywords":["authentication","authorization","identity","privacy","privy","user data","web3"],"license":"Apache-2.0","source":"./src/index.ts","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"targets":{"main":{"isLibrary":true,"sourceMap":false},"module":{"isLibrary":true,"sourceMap":false}},"files":["dist/**/*","LICENSE","README.md"],"scripts":{"build":"npx parcel build --no-cache","clean":"rm -rf dist .turbo","dev":"npx parcel watch -p 1234","test":"jest --testMatch \\"**/test/**/*.test.ts\\"","test:watch":"npm run test -- --watch","test:ci":"npm run test","lint":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" && npx tsc --noEmit","format":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" --fix"},"devDependencies":{"@privy-io/parcel-config":"*","@privy-io/tsconfig":"*","@simplewebauthn/types":"9.0.1","@tsconfig/node16-strictest-esm":"^1.0.3","@types/jest":"^29.5.11","@types/set-cookie-parser":"^2.4.7","@types/text-encoding":"^0.0.37","msw":"^2.0.13","text-encoding":"^0.7.0","ts-jest":"^29.1.1"},"dependencies":{"@ethersproject/abstract-signer":"^5.7.0","@ethersproject/bignumber":"^5.7.0","@ethersproject/providers":"^5.7.2","@ethersproject/units":"^5.7.0","@privy-io/api-base":"^0.4.6","@privy-io/public-api":"1.11.3","eventemitter3":"^5.0.1","fetch-retry":"^5.0.6","jose":"^4.15.5","js-cookie":"^3.0.5","set-cookie-parser":"^2.6.0","uuid":">=8 <10"},"author":"privy.io","browserslist":["defaults","node >= 18","not op_mini all"],"publishConfig":{"access":"public"}}');
2834
+ $53a9b3651331d972$exports = JSON.parse('{"name":"@privy-io/js-sdk-core","version":"0.16.2-beta-20240412041721","description":"Vanilla JS client for the Privy Auth API","keywords":["authentication","authorization","identity","privacy","privy","user data","web3"],"license":"Apache-2.0","source":"./src/index.ts","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"targets":{"main":{"isLibrary":true,"sourceMap":false},"module":{"isLibrary":true,"sourceMap":false}},"files":["dist/**/*","LICENSE","README.md"],"scripts":{"build":"npx parcel build --no-cache","clean":"rm -rf dist .turbo","dev":"npx parcel watch -p 1234","test":"jest --testMatch \\"**/test/**/*.test.ts\\"","test:watch":"npm run test -- --watch","test:ci":"npm run test","lint":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" && npx tsc --noEmit","format":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" --fix"},"devDependencies":{"@privy-io/parcel-config":"*","@privy-io/tsconfig":"*","@simplewebauthn/types":"9.0.1","@tsconfig/node16-strictest-esm":"^1.0.3","@types/jest":"^29.5.11","@types/set-cookie-parser":"^2.4.7","@types/text-encoding":"^0.0.37","msw":"^2.0.13","text-encoding":"^0.7.0","ts-jest":"^29.1.1"},"dependencies":{"@ethersproject/abstract-signer":"^5.7.0","@ethersproject/bignumber":"^5.7.0","@ethersproject/providers":"^5.7.2","@ethersproject/units":"^5.7.0","@privy-io/api-base":"^0.4.6","@privy-io/public-api":"1.11.3","eventemitter3":"^5.0.1","fetch-retry":"^5.0.6","jose":"^4.15.5","js-cookie":"^3.0.5","set-cookie-parser":"^2.6.0","uuid":">=8 <10"},"author":"privy.io","browserslist":["defaults","node >= 18","not op_mini all"],"publishConfig":{"access":"public"}}');
2835
2835
 
2836
2836
 
2837
2837
 
@@ -2992,23 +2992,21 @@ class $0b6eb30d38bf8477$export$1fb4852a55678982 extends (0, $kxB2R$eventemitter3
2992
2992
  /**
2993
2993
  * Accepts an optional options object to specify the reason storage is being cleared
2994
2994
  */ async destroyLocalState(opts) {
2995
- if (opts?.reason) this.emit("storage_cleared", {
2996
- reason: opts.reason
2997
- });
2998
- return Promise.all([
2995
+ const res = await Promise.all([
2999
2996
  this._storage.del($0b6eb30d38bf8477$var$TOKEN_STORAGE_KEY),
3000
2997
  this._storage.del($0b6eb30d38bf8477$var$REFRESH_TOKEN_STORAGE_KEY),
3001
2998
  this.clearForkedToken()
3002
2999
  ]);
3000
+ // TODO: We should always emit (even without reason), but only if the value has changed
3001
+ if (opts?.reason) this.emit("storage_cleared", {
3002
+ reason: opts.reason
3003
+ });
3004
+ return res;
3003
3005
  }
3004
3006
  async storeToken(token) {
3005
3007
  if (typeof token === "string") {
3006
3008
  const previousToken = await this._storage.get($0b6eb30d38bf8477$var$TOKEN_STORAGE_KEY);
3007
3009
  await this._storage.put($0b6eb30d38bf8477$var$TOKEN_STORAGE_KEY, token);
3008
- // if the token being stored is new, trigger the storage callback
3009
- if (previousToken !== token) this.emit("token_stored", {
3010
- cookiesEnabled: this._isUsingServerCookies
3011
- });
3012
3010
  if (!this._isUsingServerCookies) {
3013
3011
  const exp = (0, $efa0c2e06cf7cca2$export$50792b0e93539fde).parse(token)?.expiration;
3014
3012
  (0, $kxB2R$jscookie).set($0b6eb30d38bf8477$var$TOKEN_COOKIE_KEY, token, {
@@ -3017,20 +3015,22 @@ class $0b6eb30d38bf8477$export$1fb4852a55678982 extends (0, $kxB2R$eventemitter3
3017
3015
  expires: exp ? new Date(exp * 1000) : undefined
3018
3016
  });
3019
3017
  }
3018
+ // If the token being stored is new, trigger the storage callback
3019
+ if (previousToken !== token) this.emit("token_stored", {
3020
+ cookiesEnabled: this._isUsingServerCookies
3021
+ });
3020
3022
  } else {
3023
+ const previousToken = await this._storage.get($0b6eb30d38bf8477$var$TOKEN_STORAGE_KEY);
3021
3024
  await this._storage.del($0b6eb30d38bf8477$var$TOKEN_STORAGE_KEY);
3022
- this.emit("token_cleared", {
3025
+ (0, $kxB2R$jscookie).remove($0b6eb30d38bf8477$var$TOKEN_COOKIE_KEY);
3026
+ if (previousToken !== null) this.emit("token_cleared", {
3023
3027
  reason: "set_with_non_string_value"
3024
3028
  });
3025
- (0, $kxB2R$jscookie).remove($0b6eb30d38bf8477$var$TOKEN_COOKIE_KEY);
3026
3029
  }
3027
3030
  }
3028
3031
  async storeRefreshToken(refreshToken) {
3029
3032
  if (typeof refreshToken === "string") {
3030
3033
  await this._storage.put($0b6eb30d38bf8477$var$REFRESH_TOKEN_STORAGE_KEY, refreshToken);
3031
- this.emit("refresh_token_stored", {
3032
- cookiesEnabled: this._isUsingServerCookies
3033
- });
3034
3034
  if (!this._isUsingServerCookies) {
3035
3035
  (0, $kxB2R$jscookie).set($0b6eb30d38bf8477$var$SESSION_COOKIE_KEY, "t", {
3036
3036
  sameSite: "Strict",
@@ -3047,13 +3047,20 @@ class $0b6eb30d38bf8477$export$1fb4852a55678982 extends (0, $kxB2R$eventemitter3
3047
3047
  expires: 30
3048
3048
  });
3049
3049
  }
3050
+ // TODO: We don't do this in react-auth because we don't have a use for it
3051
+ // TODO: Make conditional on whether the value was present
3052
+ this.emit("refresh_token_stored", {
3053
+ cookiesEnabled: this._isUsingServerCookies
3054
+ });
3050
3055
  } else {
3051
3056
  await this._storage.del($0b6eb30d38bf8477$var$REFRESH_TOKEN_STORAGE_KEY);
3057
+ (0, $kxB2R$jscookie).remove($0b6eb30d38bf8477$var$REFRESH_TOKEN_COOKIE_KEY);
3058
+ (0, $kxB2R$jscookie).remove($0b6eb30d38bf8477$var$SESSION_COOKIE_KEY);
3059
+ // TODO: We don't do this in react-auth because we don't have a use for it
3060
+ // TODO: Make conditional on whether the value was present
3052
3061
  this.emit("refresh_token_cleared", {
3053
3062
  reason: "set_with_non_string_value"
3054
3063
  });
3055
- (0, $kxB2R$jscookie).remove($0b6eb30d38bf8477$var$REFRESH_TOKEN_COOKIE_KEY);
3056
- (0, $kxB2R$jscookie).remove($0b6eb30d38bf8477$var$SESSION_COOKIE_KEY);
3057
3064
  }
3058
3065
  }
3059
3066
  async clearForkedToken() {
@@ -3409,8 +3416,10 @@ class $83ff42e2a0f1e24a$export$9e80c3751b841788 {
3409
3416
  this.session.getRefreshToken()
3410
3417
  ]);
3411
3418
  if (!this.session.tokenIsActive(token) && this.session.hasRefreshCredentials(token, refreshToken)) try {
3412
- const { token: token } = await this.refreshSession();
3413
- return token;
3419
+ await this.refreshSession();
3420
+ // Return stored token, since there's some chance due to race condition that the token
3421
+ // returned by refreshSession is null even though session is valid
3422
+ return await this.session.getToken();
3414
3423
  } catch (error) {
3415
3424
  return null;
3416
3425
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@privy-io/js-sdk-core",
3
- "version": "0.16.1",
3
+ "version": "0.16.2-beta-20240412041721",
4
4
  "description": "Vanilla JS client for the Privy Auth API",
5
5
  "keywords": [
6
6
  "authentication",