@getpara/core-sdk 2.0.0-alpha.34 → 2.0.0-alpha.36

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.
@@ -891,8 +891,8 @@ const _ParaCore = class _ParaCore {
891
891
  return __privateGet(this, _authInfo);
892
892
  });
893
893
  }
894
- assertUserId() {
895
- if (!this.userId || this.isGuestMode) {
894
+ assertUserId({ allowGuestMode = false } = {}) {
895
+ if (!this.userId || !allowGuestMode && this.isGuestMode) {
896
896
  throw new Error("no userId is set");
897
897
  }
898
898
  return this.userId;
@@ -1535,7 +1535,7 @@ const _ParaCore = class _ParaCore {
1535
1535
  }
1536
1536
  break;
1537
1537
  }
1538
- const userId = this.assertUserId();
1538
+ const userId = this.assertUserId({ allowGuestMode: true });
1539
1539
  if (type !== "EMAIL" && type !== "PHONE") {
1540
1540
  throw new Error("invalid auth type for verification code");
1541
1541
  }
@@ -1785,9 +1785,6 @@ const _ParaCore = class _ParaCore {
1785
1785
  return __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, __spreadProps(__spreadValues({}, opts), { sessionLookupId }));
1786
1786
  });
1787
1787
  }
1788
- getOAuthUrlSync(opts) {
1789
- return __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, opts);
1790
- }
1791
1788
  /**
1792
1789
  * Awaits the response from a user's attempt to log in with OAuth.
1793
1790
  * If successful, this returns the user's email address and indicates whether the user already exists.
@@ -1805,6 +1802,7 @@ const _ParaCore = class _ParaCore {
1805
1802
  onCancel,
1806
1803
  onPoll,
1807
1804
  onOAuthUrl,
1805
+ onOAuthPopup,
1808
1806
  isLinkAccount
1809
1807
  } = _j, urlOptions = __objRest(_j, [
1810
1808
  "method",
@@ -1813,10 +1811,19 @@ const _ParaCore = class _ParaCore {
1813
1811
  "onCancel",
1814
1812
  "onPoll",
1815
1813
  "onOAuthUrl",
1814
+ "onOAuthPopup",
1816
1815
  "isLinkAccount"
1817
1816
  ]);
1817
+ let popupWindow;
1818
+ if (onOAuthPopup) {
1819
+ try {
1820
+ popupWindow = yield this.platformUtils.openPopup("about:blank", { type: import_types.PopupType.OAUTH });
1821
+ } catch (error) {
1822
+ throw new Error(`Failed to open OAuth popup: ${error}`);
1823
+ }
1824
+ }
1818
1825
  let sessionLookupId, accountLinkInProgress;
1819
- if (onOAuthUrl) {
1826
+ if (onOAuthUrl || onOAuthPopup) {
1820
1827
  if (isLinkAccount) {
1821
1828
  accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, method);
1822
1829
  sessionLookupId = (yield this.touchSession()).sessionLookupId;
@@ -1824,7 +1831,17 @@ const _ParaCore = class _ParaCore {
1824
1831
  sessionLookupId = yield this.prepareLogin();
1825
1832
  }
1826
1833
  const oAuthUrl = yield __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, { method, appScheme, sessionLookupId, accountLinkInProgress });
1827
- onOAuthUrl(oAuthUrl);
1834
+ switch (true) {
1835
+ case !!onOAuthUrl: {
1836
+ onOAuthUrl(oAuthUrl);
1837
+ break;
1838
+ }
1839
+ case (!!onOAuthPopup && !!popupWindow): {
1840
+ popupWindow.location.href = oAuthUrl;
1841
+ onOAuthPopup(popupWindow);
1842
+ break;
1843
+ }
1844
+ }
1828
1845
  } else {
1829
1846
  ({ sessionLookupId } = yield this.touchSession());
1830
1847
  }
@@ -3015,7 +3032,7 @@ const _ParaCore = class _ParaCore {
3015
3032
  "verificationCode"
3016
3033
  ]);
3017
3034
  this.assertIsAuthSet(["email", "phone"]);
3018
- const userId = this.assertUserId();
3035
+ const userId = this.assertUserId({ allowGuestMode: true });
3019
3036
  const serverAuthState = yield this.ctx.client.verifyNewAccount(userId, {
3020
3037
  verificationCode
3021
3038
  });
@@ -40,7 +40,7 @@ __export(constants_exports, {
40
40
  SHORT_POLLING_INTERVAL_MS: () => SHORT_POLLING_INTERVAL_MS
41
41
  });
42
42
  module.exports = __toCommonJS(constants_exports);
43
- const PARA_CORE_VERSION = "2.0.0-alpha.34";
43
+ const PARA_CORE_VERSION = "2.0.0-alpha.36";
44
44
  const PREFIX = "@CAPSULE/";
45
45
  const LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
46
46
  const LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
@@ -856,8 +856,8 @@ const _ParaCore = class _ParaCore {
856
856
  return __privateGet(this, _authInfo);
857
857
  });
858
858
  }
859
- assertUserId() {
860
- if (!this.userId || this.isGuestMode) {
859
+ assertUserId({ allowGuestMode = false } = {}) {
860
+ if (!this.userId || !allowGuestMode && this.isGuestMode) {
861
861
  throw new Error("no userId is set");
862
862
  }
863
863
  return this.userId;
@@ -1500,7 +1500,7 @@ const _ParaCore = class _ParaCore {
1500
1500
  }
1501
1501
  break;
1502
1502
  }
1503
- const userId = this.assertUserId();
1503
+ const userId = this.assertUserId({ allowGuestMode: true });
1504
1504
  if (type !== "EMAIL" && type !== "PHONE") {
1505
1505
  throw new Error("invalid auth type for verification code");
1506
1506
  }
@@ -1750,9 +1750,6 @@ const _ParaCore = class _ParaCore {
1750
1750
  return __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, __spreadProps(__spreadValues({}, opts), { sessionLookupId }));
1751
1751
  });
1752
1752
  }
1753
- getOAuthUrlSync(opts) {
1754
- return __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, opts);
1755
- }
1756
1753
  /**
1757
1754
  * Awaits the response from a user's attempt to log in with OAuth.
1758
1755
  * If successful, this returns the user's email address and indicates whether the user already exists.
@@ -1770,6 +1767,7 @@ const _ParaCore = class _ParaCore {
1770
1767
  onCancel,
1771
1768
  onPoll,
1772
1769
  onOAuthUrl,
1770
+ onOAuthPopup,
1773
1771
  isLinkAccount
1774
1772
  } = _j, urlOptions = __objRest(_j, [
1775
1773
  "method",
@@ -1778,10 +1776,19 @@ const _ParaCore = class _ParaCore {
1778
1776
  "onCancel",
1779
1777
  "onPoll",
1780
1778
  "onOAuthUrl",
1779
+ "onOAuthPopup",
1781
1780
  "isLinkAccount"
1782
1781
  ]);
1782
+ let popupWindow;
1783
+ if (onOAuthPopup) {
1784
+ try {
1785
+ popupWindow = yield this.platformUtils.openPopup("about:blank", { type: PopupType.OAUTH });
1786
+ } catch (error) {
1787
+ throw new Error(`Failed to open OAuth popup: ${error}`);
1788
+ }
1789
+ }
1783
1790
  let sessionLookupId, accountLinkInProgress;
1784
- if (onOAuthUrl) {
1791
+ if (onOAuthUrl || onOAuthPopup) {
1785
1792
  if (isLinkAccount) {
1786
1793
  accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, method);
1787
1794
  sessionLookupId = (yield this.touchSession()).sessionLookupId;
@@ -1789,7 +1796,17 @@ const _ParaCore = class _ParaCore {
1789
1796
  sessionLookupId = yield this.prepareLogin();
1790
1797
  }
1791
1798
  const oAuthUrl = yield __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, { method, appScheme, sessionLookupId, accountLinkInProgress });
1792
- onOAuthUrl(oAuthUrl);
1799
+ switch (true) {
1800
+ case !!onOAuthUrl: {
1801
+ onOAuthUrl(oAuthUrl);
1802
+ break;
1803
+ }
1804
+ case (!!onOAuthPopup && !!popupWindow): {
1805
+ popupWindow.location.href = oAuthUrl;
1806
+ onOAuthPopup(popupWindow);
1807
+ break;
1808
+ }
1809
+ }
1793
1810
  } else {
1794
1811
  ({ sessionLookupId } = yield this.touchSession());
1795
1812
  }
@@ -2980,7 +2997,7 @@ const _ParaCore = class _ParaCore {
2980
2997
  "verificationCode"
2981
2998
  ]);
2982
2999
  this.assertIsAuthSet(["email", "phone"]);
2983
- const userId = this.assertUserId();
3000
+ const userId = this.assertUserId({ allowGuestMode: true });
2984
3001
  const serverAuthState = yield this.ctx.client.verifyNewAccount(userId, {
2985
3002
  verificationCode
2986
3003
  });
@@ -1,5 +1,5 @@
1
1
  import "./chunk-7B52C2XE.js";
2
- const PARA_CORE_VERSION = "2.0.0-alpha.34";
2
+ const PARA_CORE_VERSION = "2.0.0-alpha.36";
3
3
  const PREFIX = "@CAPSULE/";
4
4
  const LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
5
5
  const LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
@@ -222,7 +222,9 @@ export declare abstract class ParaCore implements CoreInterface {
222
222
  extras?: AuthExtras;
223
223
  userId?: string;
224
224
  }): Promise<typeof this.authInfo>;
225
- protected assertUserId(): string;
225
+ protected assertUserId({ allowGuestMode }?: {
226
+ allowGuestMode?: boolean;
227
+ }): string;
226
228
  protected assertIsAuthSet(allowed?: AuthType[]): PrimaryAuthInfo;
227
229
  /**
228
230
  * Sets the email associated with the `ParaCore` instance.
@@ -435,9 +437,6 @@ export declare abstract class ParaCore implements CoreInterface {
435
437
  verifyFarcaster(opts: CoreMethodParams<'verifyFarcaster'>): CoreMethodResponse<'verifyFarcaster'>;
436
438
  protected verifyFarcasterLink(opts: InternalMethodParams<'verifyFarcasterLink'>): InternalMethodResponse<'verifyFarcasterLink'>;
437
439
  getOAuthUrl(opts: CoreMethodParams<'getOAuthUrl'>): CoreMethodResponse<'getOAuthUrl'>;
438
- getOAuthUrlSync(opts: Omit<CoreMethodParams<'getOAuthUrl'>, 'sessionLookupId'> & {
439
- sessionLookupId: string;
440
- }): Awaited<CoreMethodResponse<'getOAuthUrl'>>;
441
440
  protected verifyOAuthProcess(_: InternalMethodParams<'verifyOAuthLink'> & {
442
441
  isLinkAccount: true;
443
442
  }): InternalMethodResponse<'verifyOAuthLink'>;
@@ -110,8 +110,17 @@ export type OAuthParams = OAuthUrlParams & PollParams & {
110
110
  /**
111
111
  * A callback function that will be invoked with the OAuth URL when it is available.
112
112
  * For example, you can use this to open the URL in a new window or tab.
113
+ *
114
+ * You should pass one of `onOAuthUrl` or `onOAuthPopup`, not both.
113
115
  */
114
116
  onOAuthUrl?: (url: string) => void;
117
+ /**
118
+ * A callback function that will be invoked with the OAuth popup window when it is available.
119
+ * If supplied, a window will automatically be opened for you if running on an applicable platform.
120
+ *
121
+ * You should pass one of `onOAuthUrl` or `onOAuthPopup`, not both.
122
+ */
123
+ onOAuthPopup?: (popup: Window) => void;
115
124
  };
116
125
  export type AuthStateBaseParams = WithCustomTheme & WithUseShortUrls;
117
126
  export type AuthStateVerify = ServerAuthStateVerify;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@getpara/core-sdk",
3
- "version": "2.0.0-alpha.34",
3
+ "version": "2.0.0-alpha.36",
4
4
  "dependencies": {
5
5
  "@celo/utils": "^8.0.2",
6
6
  "@cosmjs/encoding": "^0.32.4",
7
7
  "@ethereumjs/util": "^9.1.0",
8
- "@getpara/user-management-client": "2.0.0-alpha.34",
8
+ "@getpara/user-management-client": "2.0.0-alpha.36",
9
9
  "@noble/hashes": "^1.5.0",
10
10
  "base64url": "^3.0.1",
11
11
  "libphonenumber-js": "^1.11.7",
@@ -27,7 +27,7 @@
27
27
  "dist",
28
28
  "package.json"
29
29
  ],
30
- "gitHead": "cff5cb1fa7284a850e688b20a6596d435315a475",
30
+ "gitHead": "2f05b64622b5813679e11282e5ed5c78c9a00e6c",
31
31
  "main": "dist/cjs/index.js",
32
32
  "module": "dist/esm/index.js",
33
33
  "scripts": {