thirdweb 5.77.0 → 5.78.0

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.
Files changed (145) hide show
  1. package/dist/cjs/exports/react.js +4 -2
  2. package/dist/cjs/exports/react.js.map +1 -1
  3. package/dist/cjs/exports/react.native.js +4 -1
  4. package/dist/cjs/exports/react.native.js.map +1 -1
  5. package/dist/cjs/exports/wallets/in-app.js +2 -1
  6. package/dist/cjs/exports/wallets/in-app.js.map +1 -1
  7. package/dist/cjs/exports/wallets/in-app.native.js +2 -1
  8. package/dist/cjs/exports/wallets/in-app.native.js.map +1 -1
  9. package/dist/cjs/exports/wallets.js +2 -1
  10. package/dist/cjs/exports/wallets.js.map +1 -1
  11. package/dist/cjs/exports/wallets.native.js +2 -1
  12. package/dist/cjs/exports/wallets.native.js.map +1 -1
  13. package/dist/cjs/react/native/hooks/wallets/useUnlinkProfile.js +58 -0
  14. package/dist/cjs/react/native/hooks/wallets/useUnlinkProfile.js.map +1 -0
  15. package/dist/cjs/react/web/hooks/wallets/useUnlinkProfile.js +58 -0
  16. package/dist/cjs/react/web/hooks/wallets/useUnlinkProfile.js.map +1 -0
  17. package/dist/cjs/react/web/ui/ConnectWallet/screens/LinkedProfilesScreen.js +22 -6
  18. package/dist/cjs/react/web/ui/ConnectWallet/screens/LinkedProfilesScreen.js.map +1 -1
  19. package/dist/cjs/react/web/wallets/in-app/CountrySelector.js +11 -10
  20. package/dist/cjs/react/web/wallets/in-app/CountrySelector.js.map +1 -1
  21. package/dist/cjs/react/web/wallets/in-app/InputSelectionUI.js +3 -1
  22. package/dist/cjs/react/web/wallets/in-app/InputSelectionUI.js.map +1 -1
  23. package/dist/cjs/react/web/wallets/in-app/supported-sms-countries.js.map +1 -1
  24. package/dist/cjs/react/web/wallets/shared/ConnectWalletSocialOptions.js +1 -1
  25. package/dist/cjs/react/web/wallets/shared/ConnectWalletSocialOptions.js.map +1 -1
  26. package/dist/cjs/version.js +1 -1
  27. package/dist/cjs/wallets/in-app/core/authentication/linkAccount.js +31 -0
  28. package/dist/cjs/wallets/in-app/core/authentication/linkAccount.js.map +1 -1
  29. package/dist/cjs/wallets/in-app/native/auth/index.js +30 -3
  30. package/dist/cjs/wallets/in-app/native/auth/index.js.map +1 -1
  31. package/dist/cjs/wallets/in-app/native/native-connector.js +8 -0
  32. package/dist/cjs/wallets/in-app/native/native-connector.js.map +1 -1
  33. package/dist/cjs/wallets/in-app/web/lib/auth/index.js +30 -0
  34. package/dist/cjs/wallets/in-app/web/lib/auth/index.js.map +1 -1
  35. package/dist/cjs/wallets/in-app/web/lib/web-connector.js +8 -0
  36. package/dist/cjs/wallets/in-app/web/lib/web-connector.js.map +1 -1
  37. package/dist/esm/exports/react.js +1 -0
  38. package/dist/esm/exports/react.js.map +1 -1
  39. package/dist/esm/exports/react.native.js +1 -0
  40. package/dist/esm/exports/react.native.js.map +1 -1
  41. package/dist/esm/exports/wallets/in-app.js +1 -1
  42. package/dist/esm/exports/wallets/in-app.js.map +1 -1
  43. package/dist/esm/exports/wallets/in-app.native.js +1 -1
  44. package/dist/esm/exports/wallets/in-app.native.js.map +1 -1
  45. package/dist/esm/exports/wallets.js +1 -1
  46. package/dist/esm/exports/wallets.js.map +1 -1
  47. package/dist/esm/exports/wallets.native.js +1 -1
  48. package/dist/esm/exports/wallets.native.js.map +1 -1
  49. package/dist/esm/react/native/hooks/wallets/useUnlinkProfile.js +55 -0
  50. package/dist/esm/react/native/hooks/wallets/useUnlinkProfile.js.map +1 -0
  51. package/dist/esm/react/web/hooks/wallets/useUnlinkProfile.js +55 -0
  52. package/dist/esm/react/web/hooks/wallets/useUnlinkProfile.js.map +1 -0
  53. package/dist/esm/react/web/ui/ConnectWallet/screens/LinkedProfilesScreen.js +22 -6
  54. package/dist/esm/react/web/ui/ConnectWallet/screens/LinkedProfilesScreen.js.map +1 -1
  55. package/dist/esm/react/web/wallets/in-app/CountrySelector.js +10 -10
  56. package/dist/esm/react/web/wallets/in-app/CountrySelector.js.map +1 -1
  57. package/dist/esm/react/web/wallets/in-app/InputSelectionUI.js +4 -2
  58. package/dist/esm/react/web/wallets/in-app/InputSelectionUI.js.map +1 -1
  59. package/dist/esm/react/web/wallets/in-app/supported-sms-countries.js.map +1 -1
  60. package/dist/esm/react/web/wallets/shared/ConnectWalletSocialOptions.js +1 -1
  61. package/dist/esm/react/web/wallets/shared/ConnectWalletSocialOptions.js.map +1 -1
  62. package/dist/esm/version.js +1 -1
  63. package/dist/esm/wallets/in-app/core/authentication/linkAccount.js +30 -0
  64. package/dist/esm/wallets/in-app/core/authentication/linkAccount.js.map +1 -1
  65. package/dist/esm/wallets/in-app/native/auth/index.js +29 -3
  66. package/dist/esm/wallets/in-app/native/auth/index.js.map +1 -1
  67. package/dist/esm/wallets/in-app/native/native-connector.js +9 -1
  68. package/dist/esm/wallets/in-app/native/native-connector.js.map +1 -1
  69. package/dist/esm/wallets/in-app/web/lib/auth/index.js +29 -0
  70. package/dist/esm/wallets/in-app/web/lib/auth/index.js.map +1 -1
  71. package/dist/esm/wallets/in-app/web/lib/web-connector.js +9 -1
  72. package/dist/esm/wallets/in-app/web/lib/web-connector.js.map +1 -1
  73. package/dist/types/exports/react.d.ts +1 -0
  74. package/dist/types/exports/react.d.ts.map +1 -1
  75. package/dist/types/exports/react.native.d.ts +1 -0
  76. package/dist/types/exports/react.native.d.ts.map +1 -1
  77. package/dist/types/exports/wallets/in-app.d.ts +1 -1
  78. package/dist/types/exports/wallets/in-app.d.ts.map +1 -1
  79. package/dist/types/exports/wallets/in-app.native.d.ts +1 -1
  80. package/dist/types/exports/wallets/in-app.native.d.ts.map +1 -1
  81. package/dist/types/exports/wallets.d.ts +1 -1
  82. package/dist/types/exports/wallets.d.ts.map +1 -1
  83. package/dist/types/exports/wallets.native.d.ts +1 -1
  84. package/dist/types/exports/wallets.native.d.ts.map +1 -1
  85. package/dist/types/react/native/hooks/wallets/useUnlinkProfile.d.ts +34 -0
  86. package/dist/types/react/native/hooks/wallets/useUnlinkProfile.d.ts.map +1 -0
  87. package/dist/types/react/web/hooks/wallets/useUnlinkProfile.d.ts +34 -0
  88. package/dist/types/react/web/hooks/wallets/useUnlinkProfile.d.ts.map +1 -0
  89. package/dist/types/react/web/ui/ConnectWallet/screens/LinkedProfilesScreen.d.ts.map +1 -1
  90. package/dist/types/react/web/wallets/in-app/CountrySelector.d.ts +2 -0
  91. package/dist/types/react/web/wallets/in-app/CountrySelector.d.ts.map +1 -1
  92. package/dist/types/react/web/wallets/in-app/InputSelectionUI.d.ts +2 -0
  93. package/dist/types/react/web/wallets/in-app/InputSelectionUI.d.ts.map +1 -1
  94. package/dist/types/react/web/wallets/in-app/supported-sms-countries.d.ts +946 -5
  95. package/dist/types/react/web/wallets/in-app/supported-sms-countries.d.ts.map +1 -1
  96. package/dist/types/react/web/wallets/shared/ConnectWalletSocialOptions.d.ts.map +1 -1
  97. package/dist/types/version.d.ts +1 -1
  98. package/dist/types/wallets/ecosystem/types.d.ts +5 -0
  99. package/dist/types/wallets/ecosystem/types.d.ts.map +1 -1
  100. package/dist/types/wallets/in-app/core/authentication/linkAccount.d.ts +13 -0
  101. package/dist/types/wallets/in-app/core/authentication/linkAccount.d.ts.map +1 -1
  102. package/dist/types/wallets/in-app/core/authentication/types.d.ts +5 -0
  103. package/dist/types/wallets/in-app/core/authentication/types.d.ts.map +1 -1
  104. package/dist/types/wallets/in-app/core/interfaces/connector.d.ts +1 -0
  105. package/dist/types/wallets/in-app/core/interfaces/connector.d.ts.map +1 -1
  106. package/dist/types/wallets/in-app/core/wallet/types.d.ts +5 -0
  107. package/dist/types/wallets/in-app/core/wallet/types.d.ts.map +1 -1
  108. package/dist/types/wallets/in-app/native/auth/index.d.ts +27 -4
  109. package/dist/types/wallets/in-app/native/auth/index.d.ts.map +1 -1
  110. package/dist/types/wallets/in-app/native/native-connector.d.ts +4 -3
  111. package/dist/types/wallets/in-app/native/native-connector.d.ts.map +1 -1
  112. package/dist/types/wallets/in-app/web/lib/auth/index.d.ts +27 -1
  113. package/dist/types/wallets/in-app/web/lib/auth/index.d.ts.map +1 -1
  114. package/dist/types/wallets/in-app/web/lib/web-connector.d.ts +4 -3
  115. package/dist/types/wallets/in-app/web/lib/web-connector.d.ts.map +1 -1
  116. package/package.json +1 -1
  117. package/src/exports/react.native.ts +1 -0
  118. package/src/exports/react.ts +1 -0
  119. package/src/exports/wallets/in-app.native.ts +1 -0
  120. package/src/exports/wallets/in-app.ts +1 -0
  121. package/src/exports/wallets.native.ts +1 -0
  122. package/src/exports/wallets.ts +1 -0
  123. package/src/react/native/hooks/wallets/useUnlinkProfile.test.tsx +75 -0
  124. package/src/react/native/hooks/wallets/useUnlinkProfile.ts +62 -0
  125. package/src/react/web/hooks/wallets/useUnlinkProfile.test.tsx +75 -0
  126. package/src/react/web/hooks/wallets/useUnlinkProfile.ts +62 -0
  127. package/src/react/web/ui/ConnectWallet/screens/LinkedProfilesScreen.test.tsx +25 -0
  128. package/src/react/web/ui/ConnectWallet/screens/LinkedProfilesScreen.tsx +86 -44
  129. package/src/react/web/wallets/in-app/CountrySelector.test.tsx +45 -0
  130. package/src/react/web/wallets/in-app/CountrySelector.tsx +16 -13
  131. package/src/react/web/wallets/in-app/InputSelectionUI.test.tsx +45 -0
  132. package/src/react/web/wallets/in-app/InputSelectionUI.tsx +8 -2
  133. package/src/react/web/wallets/in-app/supported-sms-countries.ts +3 -1
  134. package/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx +3 -0
  135. package/src/version.ts +1 -1
  136. package/src/wallets/ecosystem/types.ts +5 -0
  137. package/src/wallets/in-app/core/authentication/linkAccount.test.ts +160 -0
  138. package/src/wallets/in-app/core/authentication/linkAccount.ts +49 -0
  139. package/src/wallets/in-app/core/authentication/types.ts +6 -0
  140. package/src/wallets/in-app/core/interfaces/connector.ts +1 -0
  141. package/src/wallets/in-app/core/wallet/types.ts +5 -0
  142. package/src/wallets/in-app/native/auth/index.ts +31 -3
  143. package/src/wallets/in-app/native/native-connector.ts +11 -0
  144. package/src/wallets/in-app/web/lib/auth/index.ts +31 -0
  145. package/src/wallets/in-app/web/lib/web-connector.ts +11 -0
@@ -57,6 +57,55 @@ export async function linkAccount({
57
57
  return (linkedAccounts ?? []) satisfies Profile[];
58
58
  }
59
59
 
60
+ /**
61
+ * @description
62
+ * Links a new account to the current one using an auth token.
63
+ * For the public-facing API, use `wallet.linkProfile` instead.
64
+ *
65
+ * @internal
66
+ */
67
+ export async function unlinkAccount({
68
+ client,
69
+ ecosystem,
70
+ profileToUnlink,
71
+ storage,
72
+ }: {
73
+ client: ThirdwebClient;
74
+ ecosystem?: Ecosystem;
75
+ profileToUnlink: Profile;
76
+ storage: ClientScopedStorage;
77
+ }): Promise<Profile[]> {
78
+ const clientFetch = getClientFetch(client, ecosystem);
79
+ const IN_APP_URL = getThirdwebBaseUrl("inAppWallet");
80
+ const currentAccountToken = await storage.getAuthCookie();
81
+
82
+ if (!currentAccountToken) {
83
+ throw new Error("Failed to unlink account, no user logged in");
84
+ }
85
+
86
+ const headers: Record<string, string> = {
87
+ Authorization: `Bearer iaw-auth-token:${currentAccountToken}`,
88
+ "Content-Type": "application/json",
89
+ };
90
+ const linkedDetailsResp = await clientFetch(
91
+ `${IN_APP_URL}/api/2024-05-05/account/disconnect`,
92
+ {
93
+ method: "POST",
94
+ headers,
95
+ body: stringify(profileToUnlink),
96
+ },
97
+ );
98
+
99
+ if (!linkedDetailsResp.ok) {
100
+ const body = await linkedDetailsResp.json();
101
+ throw new Error(body.message || "Failed to unlink account.");
102
+ }
103
+
104
+ const { linkedAccounts } = await linkedDetailsResp.json();
105
+
106
+ return (linkedAccounts ?? []) satisfies Profile[];
107
+ }
108
+
60
109
  /**
61
110
  * @description
62
111
  * Gets the linked accounts for the current user.
@@ -250,3 +250,9 @@ export type GetAuthenticatedUserParams = {
250
250
  client: ThirdwebClient;
251
251
  ecosystem?: Ecosystem;
252
252
  };
253
+
254
+ export type UnlinkParams = {
255
+ client: ThirdwebClient;
256
+ ecosystem?: Ecosystem;
257
+ profileToUnlink: Profile;
258
+ };
@@ -36,5 +36,6 @@ export interface InAppConnector {
36
36
  ): Promise<AuthLoginReturnType>;
37
37
  logout(): Promise<LogoutReturnType>;
38
38
  linkProfile(args: AuthArgsType): Promise<Profile[]>;
39
+ unlinkProfile(args: Profile): Promise<Profile[]>;
39
40
  getProfiles(): Promise<Profile[]>;
40
41
  }
@@ -1,5 +1,6 @@
1
1
  import type { Chain } from "../../../../chains/types.js";
2
2
  import type { ThirdwebClient } from "../../../../client/client.js";
3
+ import type { SupportedSmsCountry } from "../../../../react/web/wallets/in-app/supported-sms-countries.js";
3
4
  import type { SmartWalletOptions } from "../../../smart/types.js";
4
5
  import type {
5
6
  AuthOption,
@@ -59,6 +60,10 @@ export type InAppWalletCreationOptions =
59
60
  * The domain of the passkey to use for authentication
60
61
  */
61
62
  passkeyDomain?: string;
63
+ /**
64
+ * The default country code to use for SMS authentication
65
+ */
66
+ defaultSmsCountryCode?: SupportedSmsCountry;
62
67
  };
63
68
  /**
64
69
  * Metadata to display in the Connect Modal
@@ -3,6 +3,7 @@ import type {
3
3
  AuthArgsType,
4
4
  GetAuthenticatedUserParams,
5
5
  PreAuthArgsType,
6
+ UnlinkParams,
6
7
  } from "../../core/authentication/types.js";
7
8
  import { getOrCreateInAppWalletConnector } from "../../core/wallet/in-app-core.js";
8
9
  import type { Ecosystem } from "../../core/wallet/types.js";
@@ -146,9 +147,6 @@ export async function authenticate(args: AuthArgsType) {
146
147
  *
147
148
  * **When a profile is linked to the account, that profile can then be used to sign into the account.**
148
149
  *
149
- * This method is only available for in-app wallets.
150
- *
151
- * @param wallet - The wallet to link an additional profile to.
152
150
  * @param auth - The authentications options to add the new profile.
153
151
  * @returns A promise that resolves to the currently linked profiles when the connection is successful.
154
152
  * @throws If the connection fails, if the profile is already linked to the account, or if the profile is already associated with another account.
@@ -167,6 +165,36 @@ export async function linkProfile(args: AuthArgsType) {
167
165
  return await connector.linkProfile(args);
168
166
  }
169
167
 
168
+ /**
169
+ * Disconnects an existing profile (authentication method) from the current user. Once disconnected, that profile can no longer be used to sign into the account.
170
+ *
171
+ * @param args - The object containing the profile that we want to unlink.
172
+ * @returns A promise that resolves to the updated linked profiles.
173
+ * @throws If the unlinking fails. This can happen if the account has no other associated profiles or if the profile that is being unlinked doesn't exists for the current logged in user.
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * import { inAppWallet } from "thirdweb/wallets";
178
+ *
179
+ * const wallet = inAppWallet();
180
+ * wallet.connect({ strategy: "google" });
181
+ *
182
+ * const profiles = await getProfiles({
183
+ * client,
184
+ * });
185
+ *
186
+ * const updatedProfiles = await unlinkProfile({
187
+ * client,
188
+ * profileToUnlink: profiles[0],
189
+ * });
190
+ * ```
191
+ * @wallet
192
+ */
193
+ export async function unlinkProfile(args: UnlinkParams) {
194
+ const connector = await getInAppWalletConnector(args.client, args.ecosystem);
195
+ return await connector.unlinkProfile(args.profileToUnlink);
196
+ }
197
+
170
198
  /**
171
199
  * Gets the linked profiles for the connected in-app or ecosystem wallet.
172
200
  *
@@ -10,6 +10,7 @@ import { customJwt } from "../core/authentication/jwt.js";
10
10
  import {
11
11
  getLinkedProfilesInternal,
12
12
  linkAccount,
13
+ unlinkAccount,
13
14
  } from "../core/authentication/linkAccount.js";
14
15
  import {
15
16
  loginWithPasskey,
@@ -24,6 +25,7 @@ import type {
24
25
  LogoutReturnType,
25
26
  MultiStepAuthArgsType,
26
27
  MultiStepAuthProviderType,
28
+ Profile,
27
29
  SingleStepAuthArgsType,
28
30
  } from "../core/authentication/types.js";
29
31
  import type { InAppConnector } from "../core/interfaces/connector.js";
@@ -332,6 +334,15 @@ export class InAppNativeConnector implements InAppConnector {
332
334
  });
333
335
  }
334
336
 
337
+ async unlinkProfile(profile: Profile) {
338
+ return await unlinkAccount({
339
+ client: this.client,
340
+ ecosystem: this.ecosystem,
341
+ storage: this.storage,
342
+ profileToUnlink: profile,
343
+ });
344
+ }
345
+
335
346
  async getProfiles() {
336
347
  return getLinkedProfilesInternal({
337
348
  client: this.client,
@@ -5,6 +5,7 @@ import type {
5
5
  GetAuthenticatedUserParams,
6
6
  PreAuthArgsType,
7
7
  SocialAuthArgsType,
8
+ UnlinkParams,
8
9
  } from "../../../core/authentication/types.js";
9
10
  import { getOrCreateInAppWalletConnector } from "../../../core/wallet/in-app-core.js";
10
11
  import type { Ecosystem } from "../../../core/wallet/types.js";
@@ -204,6 +205,36 @@ export async function linkProfile(args: AuthArgsType) {
204
205
  return await connector.linkProfile(args);
205
206
  }
206
207
 
208
+ /**
209
+ * Disconnects an existing profile (authentication method) from the current user. Once disconnected, that profile can no longer be used to sign into the account.
210
+ *
211
+ * @param args - The object containing the profile that we want to unlink.
212
+ * @returns A promise that resolves to the updated linked profiles.
213
+ * @throws If the unlinking fails. This can happen if the account has no other associated profiles or if the profile that is being unlinked doesn't exists for the current logged in user.
214
+ *
215
+ * @example
216
+ * ```ts
217
+ * import { inAppWallet } from "thirdweb/wallets";
218
+ *
219
+ * const wallet = inAppWallet();
220
+ * wallet.connect({ strategy: "google" });
221
+ *
222
+ * const profiles = await getProfiles({
223
+ * client,
224
+ * });
225
+ *
226
+ * const updatedProfiles = await unlinkProfile({
227
+ * client,
228
+ * profileToUnlink: profiles[0],
229
+ * });
230
+ * ```
231
+ * @wallet
232
+ */
233
+ export async function unlinkProfile(args: UnlinkParams) {
234
+ const connector = await getInAppWalletConnector(args.client, args.ecosystem);
235
+ return await connector.unlinkProfile(args.profileToUnlink);
236
+ }
237
+
207
238
  /**
208
239
  * Gets the linked profiles for the connected in-app or ecosystem wallet.
209
240
  *
@@ -11,6 +11,7 @@ import { customJwt } from "../../core/authentication/jwt.js";
11
11
  import {
12
12
  getLinkedProfilesInternal,
13
13
  linkAccount,
14
+ unlinkAccount,
14
15
  } from "../../core/authentication/linkAccount.js";
15
16
  import {
16
17
  loginWithPasskey,
@@ -25,6 +26,7 @@ import type {
25
26
  LogoutReturnType,
26
27
  MultiStepAuthArgsType,
27
28
  MultiStepAuthProviderType,
29
+ Profile,
28
30
  SingleStepAuthArgsType,
29
31
  } from "../../core/authentication/types.js";
30
32
  import type { InAppConnector } from "../../core/interfaces/connector.js";
@@ -456,6 +458,15 @@ export class InAppWebConnector implements InAppConnector {
456
458
  });
457
459
  }
458
460
 
461
+ async unlinkProfile(profile: Profile) {
462
+ return await unlinkAccount({
463
+ client: this.client,
464
+ storage: this.storage,
465
+ ecosystem: this.ecosystem,
466
+ profileToUnlink: profile,
467
+ });
468
+ }
469
+
459
470
  async getProfiles() {
460
471
  return getLinkedProfilesInternal({
461
472
  client: this.client,