@getpara/user-management-client 1.11.0 → 2.0.0-alpha.10
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/cjs/client.js +55 -38
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/types/auth.js +18 -0
- package/dist/cjs/types/wallet.js +9 -2
- package/dist/cjs/utils.js +175 -25
- package/dist/esm/client.js +56 -39
- package/dist/esm/index.js +1 -0
- package/dist/esm/types/auth.js +16 -0
- package/dist/esm/types/wallet.js +7 -2
- package/dist/esm/utils.js +140 -25
- package/dist/types/client.d.ts +56 -55
- package/dist/types/index.d.ts +1 -0
- package/dist/types/types/auth.d.ts +132 -11
- package/dist/types/types/onRamp.d.ts +3 -3
- package/dist/types/types/partner.d.ts +7 -0
- package/dist/types/types/wallet.d.ts +16 -4
- package/dist/types/utils.d.ts +44 -9
- package/package.json +2 -2
package/dist/esm/client.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
__spreadValues
|
|
6
6
|
} from "./chunk-BBZEL7EG.js";
|
|
7
7
|
import axios from "axios";
|
|
8
|
-
import { extractWalletRef } from "./utils.js";
|
|
8
|
+
import { extractWalletRef, fromAccountMetadata } from "./utils.js";
|
|
9
9
|
import { SESSION_COOKIE_HEADER_NAME, VERSION_HEADER_NAME, PARTNER_ID_HEADER_NAME, API_KEY_HEADER_NAME } from "./consts.js";
|
|
10
10
|
import { ParaApiError } from "./error.js";
|
|
11
11
|
const handleResponseSuccess = (response) => {
|
|
@@ -38,6 +38,13 @@ class Client {
|
|
|
38
38
|
retrieveSessionCookie,
|
|
39
39
|
persistSessionCookie
|
|
40
40
|
}) {
|
|
41
|
+
this.signUpOrLogIn = (body) => __async(this, null, function* () {
|
|
42
|
+
const res = yield this.baseRequest.post(`/users/init`, body);
|
|
43
|
+
return res.data;
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated
|
|
47
|
+
*/
|
|
41
48
|
this.createUser = (body) => __async(this, null, function* () {
|
|
42
49
|
const res = yield this.baseRequest.post(`/users`, body);
|
|
43
50
|
return res.data;
|
|
@@ -49,26 +56,46 @@ class Client {
|
|
|
49
56
|
return res;
|
|
50
57
|
});
|
|
51
58
|
this.verifyTelegram = (authObject) => __async(this, null, function* () {
|
|
52
|
-
return (yield this.baseRequest.post("/users/telegram", {
|
|
59
|
+
return (yield this.baseRequest.post("/users/telegram/v2", {
|
|
53
60
|
authObject
|
|
54
61
|
})).data;
|
|
55
62
|
});
|
|
56
|
-
this.
|
|
57
|
-
const res = yield this.baseRequest.post(
|
|
63
|
+
this.verifyOAuth = () => __async(this, null, function* () {
|
|
64
|
+
const res = yield this.baseRequest.post("/users/verify-oauth");
|
|
65
|
+
return res.data;
|
|
66
|
+
});
|
|
67
|
+
this.loginExternalWallet = (_0) => __async(this, [_0], function* ({
|
|
68
|
+
externalWallet,
|
|
69
|
+
shouldTrackUser
|
|
70
|
+
}) {
|
|
71
|
+
const res = yield this.baseRequest.post(`/users/external-wallets/login/v2`, {
|
|
72
|
+
externalWallet,
|
|
73
|
+
shouldTrackUser
|
|
74
|
+
});
|
|
75
|
+
return res.data;
|
|
76
|
+
});
|
|
77
|
+
this.verifyNewAccount = (userId, body) => __async(this, null, function* () {
|
|
78
|
+
const res = yield this.baseRequest.post(`/users/${userId}/verify`, body);
|
|
58
79
|
return res.data;
|
|
59
80
|
});
|
|
60
81
|
// POST /users/:userId/verify-email
|
|
82
|
+
/**
|
|
83
|
+
* @deprecated
|
|
84
|
+
*/
|
|
61
85
|
this.verifyEmail = (userId, body) => __async(this, null, function* () {
|
|
62
86
|
const res = yield this.baseRequest.post(`/users/${userId}/verify-email`, body);
|
|
63
87
|
return res;
|
|
64
88
|
});
|
|
89
|
+
/**
|
|
90
|
+
* @deprecated
|
|
91
|
+
*/
|
|
65
92
|
this.verifyPhone = (userId, body) => __async(this, null, function* () {
|
|
66
93
|
const res = yield this.baseRequest.post(`/users/${userId}/verify-identifier`, body);
|
|
67
94
|
return res;
|
|
68
95
|
});
|
|
69
96
|
this.verifyExternalWallet = (userId, body) => __async(this, null, function* () {
|
|
70
|
-
const res = yield this.baseRequest.post(`/users/${userId}/external-wallets/verify`, body);
|
|
71
|
-
return res;
|
|
97
|
+
const res = yield this.baseRequest.post(`/users/${userId}/external-wallets/verify/v2`, body);
|
|
98
|
+
return res.data;
|
|
72
99
|
});
|
|
73
100
|
// POST /users/:userId/biometrics/key
|
|
74
101
|
this.addSessionPublicKey = (userId, body) => __async(this, null, function* () {
|
|
@@ -81,8 +108,10 @@ class Client {
|
|
|
81
108
|
return res;
|
|
82
109
|
});
|
|
83
110
|
// GET /biometrics/location-hints
|
|
84
|
-
this.getBiometricLocationHints = (
|
|
85
|
-
const res = yield this.baseRequest.get(`/biometrics/location-hints`, {
|
|
111
|
+
this.getBiometricLocationHints = (auth) => __async(this, null, function* () {
|
|
112
|
+
const res = yield this.baseRequest.get(`/biometrics/location-hints`, {
|
|
113
|
+
params: auth
|
|
114
|
+
});
|
|
86
115
|
return res.data.hints;
|
|
87
116
|
});
|
|
88
117
|
// GET /users/:userId/biometrics/:biometricId
|
|
@@ -108,10 +137,8 @@ class Client {
|
|
|
108
137
|
});
|
|
109
138
|
// POST /touch
|
|
110
139
|
this.touchSession = (regenerate) => __async(this, null, function* () {
|
|
111
|
-
const res = yield this.baseRequest.post(
|
|
112
|
-
|
|
113
|
-
);
|
|
114
|
-
return res;
|
|
140
|
+
const res = yield this.baseRequest.post(`/touch?regenerate=${!!regenerate}`);
|
|
141
|
+
return res.data;
|
|
115
142
|
});
|
|
116
143
|
// GET /session/origin
|
|
117
144
|
this.sessionOrigin = (sessionLookupId) => __async(this, null, function* () {
|
|
@@ -147,14 +174,12 @@ class Client {
|
|
|
147
174
|
const res = yield this.baseRequest.post(`/wallets/pregen`, body);
|
|
148
175
|
return res.data;
|
|
149
176
|
});
|
|
150
|
-
// GET /wallets/pregen?pregenIdentifier={pregenIdentifier}&pregenIdentifierType={pregenIdentifierType}
|
|
151
177
|
this.getPregenWallets = (pregenIds, isPortal = false, userId) => __async(this, null, function* () {
|
|
152
178
|
const res = yield this.baseRequest.get("/wallets/pregen", {
|
|
153
179
|
params: { ids: pregenIds, expand: isPortal, userId }
|
|
154
180
|
});
|
|
155
181
|
return res.data;
|
|
156
182
|
});
|
|
157
|
-
// POST /wallets/pregen/claim
|
|
158
183
|
this.claimPregenWallets = (body) => __async(this, null, function* () {
|
|
159
184
|
const res = yield this.baseRequest.post(`/wallets/pregen/claim`, body);
|
|
160
185
|
return res.data;
|
|
@@ -264,18 +289,17 @@ class Client {
|
|
|
264
289
|
return res;
|
|
265
290
|
});
|
|
266
291
|
// GET /users/:userId/wallets/:walletId/balance
|
|
267
|
-
this.getWalletBalance = (_0) => __async(this, [_0], function* ({
|
|
268
|
-
|
|
269
|
-
walletId,
|
|
270
|
-
rpcUrl
|
|
271
|
-
}) {
|
|
272
|
-
const res = yield this.baseRequest.get(`/users/${userId}/wallets/${walletId}/balance`, {
|
|
292
|
+
this.getWalletBalance = (_0) => __async(this, [_0], function* ({ walletId, rpcUrl }) {
|
|
293
|
+
const res = yield this.baseRequest.get(`/wallets/${walletId}/balance`, {
|
|
273
294
|
params: {
|
|
274
295
|
rpcUrl
|
|
275
296
|
}
|
|
276
297
|
});
|
|
277
298
|
return res.data;
|
|
278
299
|
});
|
|
300
|
+
this.trackError = (opts) => __async(this, null, function* () {
|
|
301
|
+
yield this.baseRequest.post("/errors/sdk", opts);
|
|
302
|
+
});
|
|
279
303
|
const headers = __spreadValues(__spreadValues({}, apiKey && { [API_KEY_HEADER_NAME]: apiKey }), partnerId && { [PARTNER_ID_HEADER_NAME]: partnerId });
|
|
280
304
|
const axiosConfig = {
|
|
281
305
|
baseURL: userManagementHost,
|
|
@@ -430,11 +454,10 @@ class Client {
|
|
|
430
454
|
return res;
|
|
431
455
|
});
|
|
432
456
|
}
|
|
433
|
-
// POST '/2fa/users/:userId/setup'
|
|
434
457
|
setup2FA(userId) {
|
|
435
458
|
return __async(this, null, function* () {
|
|
436
459
|
const res = yield this.baseRequest.post(`/2fa/users/${userId}/setup`);
|
|
437
|
-
return res;
|
|
460
|
+
return res.data;
|
|
438
461
|
});
|
|
439
462
|
}
|
|
440
463
|
// POST /recovery/init
|
|
@@ -451,11 +474,10 @@ class Client {
|
|
|
451
474
|
return res;
|
|
452
475
|
});
|
|
453
476
|
}
|
|
454
|
-
// POST /auth/farcaster/status
|
|
455
477
|
getFarcasterAuthStatus() {
|
|
456
478
|
return __async(this, null, function* () {
|
|
457
|
-
const res = yield this.baseRequest.post(`/auth/farcaster/status`);
|
|
458
|
-
return res;
|
|
479
|
+
const res = yield this.baseRequest.post(`/auth/farcaster/status/v2`);
|
|
480
|
+
return res.data;
|
|
459
481
|
});
|
|
460
482
|
}
|
|
461
483
|
// POST /recovery/init
|
|
@@ -495,18 +517,20 @@ class Client {
|
|
|
495
517
|
return res;
|
|
496
518
|
});
|
|
497
519
|
}
|
|
498
|
-
|
|
499
|
-
verify2FA(email, verificationCode) {
|
|
520
|
+
verify2FA(auth, verificationCode) {
|
|
500
521
|
return __async(this, null, function* () {
|
|
501
|
-
const body = {
|
|
522
|
+
const body = __spreadProps(__spreadValues({}, auth), { verificationCode });
|
|
502
523
|
const res = yield this.baseRequest.post("/2fa/verify", body);
|
|
503
|
-
return res;
|
|
524
|
+
return res.data;
|
|
504
525
|
});
|
|
505
526
|
}
|
|
506
527
|
// POST /2fa/phone/verify
|
|
507
|
-
|
|
528
|
+
/**
|
|
529
|
+
* @deprecated
|
|
530
|
+
*/
|
|
531
|
+
verify2FAForPhone(phone, verificationCode) {
|
|
508
532
|
return __async(this, null, function* () {
|
|
509
|
-
const body = { phone,
|
|
533
|
+
const body = { phone, verificationCode };
|
|
510
534
|
const res = yield this.baseRequest.post("/2fa/verify", body);
|
|
511
535
|
return res;
|
|
512
536
|
});
|
|
@@ -802,14 +826,7 @@ class Client {
|
|
|
802
826
|
params: { partnerId }
|
|
803
827
|
});
|
|
804
828
|
return {
|
|
805
|
-
accountMetadata:
|
|
806
|
-
(acc, [method, obj]) => __spreadProps(__spreadValues({}, acc), {
|
|
807
|
-
[method]: __spreadProps(__spreadValues({}, obj), {
|
|
808
|
-
date: new Date(obj.date)
|
|
809
|
-
})
|
|
810
|
-
}),
|
|
811
|
-
{}
|
|
812
|
-
)
|
|
829
|
+
accountMetadata: fromAccountMetadata(res.data.accountMetadata)
|
|
813
830
|
};
|
|
814
831
|
});
|
|
815
832
|
}
|
package/dist/esm/index.js
CHANGED
package/dist/esm/types/auth.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import "../chunk-BBZEL7EG.js";
|
|
2
|
+
const AUTH_TYPES = [
|
|
3
|
+
"email",
|
|
4
|
+
"phone",
|
|
5
|
+
"phoneLegacy",
|
|
6
|
+
"farcaster",
|
|
7
|
+
"telegram",
|
|
8
|
+
"userId",
|
|
9
|
+
"externalWallet",
|
|
10
|
+
"discord",
|
|
11
|
+
"x",
|
|
12
|
+
"customId",
|
|
13
|
+
"guestId"
|
|
14
|
+
];
|
|
2
15
|
var EncryptorType = /* @__PURE__ */ ((EncryptorType2) => {
|
|
3
16
|
EncryptorType2["USER"] = "USER";
|
|
4
17
|
EncryptorType2["RECOVERY"] = "RECOVERY";
|
|
@@ -36,15 +49,18 @@ var OAuthMethod = /* @__PURE__ */ ((OAuthMethod2) => {
|
|
|
36
49
|
OAuthMethod2["TELEGRAM"] = "TELEGRAM";
|
|
37
50
|
return OAuthMethod2;
|
|
38
51
|
})(OAuthMethod || {});
|
|
52
|
+
const OAUTH_METHODS = ["GOOGLE", "TWITTER", "APPLE", "DISCORD", "FACEBOOK", "FARCASTER", "TELEGRAM"];
|
|
39
53
|
var AuthMethod = /* @__PURE__ */ ((AuthMethod2) => {
|
|
40
54
|
AuthMethod2["PASSWORD"] = "PASSWORD";
|
|
41
55
|
AuthMethod2["PASSKEY"] = "PASSKEY";
|
|
42
56
|
return AuthMethod2;
|
|
43
57
|
})(AuthMethod || {});
|
|
44
58
|
export {
|
|
59
|
+
AUTH_TYPES,
|
|
45
60
|
AuthMethod,
|
|
46
61
|
EncryptorType,
|
|
47
62
|
KeyShareType,
|
|
63
|
+
OAUTH_METHODS,
|
|
48
64
|
OAuthMethod,
|
|
49
65
|
PasswordStatus,
|
|
50
66
|
PublicKeyStatus,
|
package/dist/esm/types/wallet.js
CHANGED
|
@@ -5,12 +5,14 @@ var WalletScheme = /* @__PURE__ */ ((WalletScheme2) => {
|
|
|
5
5
|
WalletScheme2["ED25519"] = "ED25519";
|
|
6
6
|
return WalletScheme2;
|
|
7
7
|
})(WalletScheme || {});
|
|
8
|
+
const WALLET_SCHEMES = ["DKLS", "CGGMP", "ED25519"];
|
|
8
9
|
var WalletType = /* @__PURE__ */ ((WalletType2) => {
|
|
9
10
|
WalletType2["EVM"] = "EVM";
|
|
10
11
|
WalletType2["SOLANA"] = "SOLANA";
|
|
11
12
|
WalletType2["COSMOS"] = "COSMOS";
|
|
12
13
|
return WalletType2;
|
|
13
14
|
})(WalletType || {});
|
|
15
|
+
const WALLET_TYPES = ["EVM", "SOLANA", "COSMOS"];
|
|
14
16
|
var Chain = /* @__PURE__ */ ((Chain2) => {
|
|
15
17
|
Chain2["ETH"] = "ETH";
|
|
16
18
|
Chain2["CELO"] = "CELO";
|
|
@@ -38,14 +40,17 @@ const PREGEN_IDENTIFIER_TYPES = [
|
|
|
38
40
|
"GUEST_ID",
|
|
39
41
|
"DISCORD",
|
|
40
42
|
"TWITTER",
|
|
41
|
-
"TELEGRAM"
|
|
43
|
+
"TELEGRAM",
|
|
44
|
+
"FARCASTER"
|
|
42
45
|
];
|
|
43
|
-
const NON_ED25519 = ["DKLS"
|
|
46
|
+
const NON_ED25519 = ["DKLS", "CGGMP"];
|
|
44
47
|
export {
|
|
45
48
|
Chain,
|
|
46
49
|
NON_ED25519,
|
|
47
50
|
Network,
|
|
48
51
|
PREGEN_IDENTIFIER_TYPES,
|
|
52
|
+
WALLET_SCHEMES,
|
|
53
|
+
WALLET_TYPES,
|
|
49
54
|
WalletScheme,
|
|
50
55
|
WalletType
|
|
51
56
|
};
|
package/dist/esm/utils.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
__spreadProps,
|
|
3
|
+
__spreadValues
|
|
4
|
+
} from "./chunk-BBZEL7EG.js";
|
|
5
|
+
import parsePhoneNumberFromString from "libphonenumber-js";
|
|
2
6
|
function isWalletId(params) {
|
|
3
7
|
return !!params.walletId && !params.externalWalletAddress;
|
|
4
8
|
}
|
|
@@ -17,73 +21,184 @@ function isValid(s) {
|
|
|
17
21
|
return !!s && s !== "null" && s !== "undefined" && s !== "";
|
|
18
22
|
}
|
|
19
23
|
function isEmail(params) {
|
|
20
|
-
return isValid(params.email) && !isValid(params.phone) && !isValid(params.countryCode) && !isValid(params.farcasterUsername) && !isValid(params.telegramUserId) && !isValid(params.
|
|
24
|
+
return !!params && isValid(params.email) && !isValid(params.phone) && !isValid(params.countryCode) && !isValid(params.farcasterUsername) && !isValid(params.telegramUserId) && !isValid(params.xUsername) && !isValid(params.discordUsername) && !isValid(params.customId) && !isValid(params.externalWalletAddress);
|
|
21
25
|
}
|
|
22
26
|
function isPhone(params) {
|
|
23
|
-
return isValid(params.phone) && isValid(params.countryCode) && !isValid(params.email) && !isValid(params.farcasterUsername) && !isValid(params.telegramUserId) && !isValid(params.
|
|
27
|
+
return !!params && isValid(params.phone) && /^\+\d+$/.test(params.phone) && !isValid(params.countryCode) && !isValid(params.email) && !isValid(params.farcasterUsername) && !isValid(params.telegramUserId) && !isValid(params.xUsername) && !isValid(params.discordUsername) && !isValid(params.customId) && !isValid(params.userId) && !isValid(params.externalWalletAddress);
|
|
28
|
+
}
|
|
29
|
+
function isPhoneLegacy(params) {
|
|
30
|
+
return !!params && isValid(params.phone) && isValid(params.countryCode) && !isValid(params.email) && !isValid(params.farcasterUsername) && !isValid(params.telegramUserId) && !isValid(params.xUsername) && !isValid(params.discordUsername) && !isValid(params.customId) && !isValid(params.externalWalletAddress);
|
|
24
31
|
}
|
|
25
32
|
function isFarcaster(params) {
|
|
26
|
-
return isValid(params.farcasterUsername) && !isValid(params.email) && !isValid(params.phone) && !isValid(params.countryCode) && !isValid(params.telegramUserId) && !isValid(params.
|
|
33
|
+
return !!params && isValid(params.farcasterUsername) && !isValid(params.email) && !isValid(params.phone) && !isValid(params.countryCode) && !isValid(params.telegramUserId) && !isValid(params.xUsername) && !isValid(params.discordUsername) && !isValid(params.customId) && !isValid(params.externalWalletAddress);
|
|
27
34
|
}
|
|
28
35
|
function isTelegram(params) {
|
|
29
|
-
return isValid(params.telegramUserId) && !isValid(params.email) && !isValid(params.phone) && !isValid(params.countryCode) && !isValid(params.farcasterUsername) && !isValid(params.
|
|
36
|
+
return !!params && isValid(params.telegramUserId) && !isValid(params.email) && !isValid(params.phone) && !isValid(params.countryCode) && !isValid(params.farcasterUsername) && !isValid(params.xUsername) && !isValid(params.discordUsername) && !isValid(params.customId) && !isValid(params.externalWalletAddress);
|
|
37
|
+
}
|
|
38
|
+
function isExternalWallet(params) {
|
|
39
|
+
return !!params && isValid(params.externalWalletAddress) && !isValid(params.email) && !isValid(params.phone) && !isValid(params.countryCode) && !isValid(params.farcasterUsername) && !isValid(params.telegramUserId) && !isValid(params.xUsername) && !isValid(params.discordUsername) && !isValid(params.customId);
|
|
40
|
+
}
|
|
41
|
+
function isX(params) {
|
|
42
|
+
return !!params && isValid(params.xUsername) && !isValid(params.email) && !isValid(params.phone) && !isValid(params.countryCode) && !isValid(params.farcasterUsername) && !isValid(params.telegramUserId) && !isValid(params.discordUsername) && !isValid(params.customId) && !isValid(params.externalWalletAddress);
|
|
43
|
+
}
|
|
44
|
+
function isDiscord(params) {
|
|
45
|
+
return !!params && isValid(params.discordUsername) && !isValid(params.email) && !isValid(params.phone) && !isValid(params.countryCode) && !isValid(params.farcasterUsername) && !isValid(params.telegramUserId) && !isValid(params.xUsername) && !isValid(params.customId) && !isValid(params.externalWalletAddress);
|
|
46
|
+
}
|
|
47
|
+
function isCustomId(params) {
|
|
48
|
+
return !!params && isValid(params.customId) && !isValid(params.email) && !isValid(params.phone) && !isValid(params.email) && !isValid(params.phone) && !isValid(params.countryCode) && !isValid(params.farcasterUsername) && !isValid(params.telegramUserId) && !isValid(params.xUsername) && !isValid(params.discordUsername) && !isValid(params.externalWalletAddress);
|
|
49
|
+
}
|
|
50
|
+
function isGuestId(params) {
|
|
51
|
+
return !!params && isValid(params.guestId) && !isValid(params.email) && !isValid(params.phone) && !isValid(params.countryCode) && !isValid(params.farcasterUsername) && !isValid(params.xUsername) && !isValid(params.discordUsername) && !isValid(params.customId) && !isValid(params.externalWalletAddress);
|
|
30
52
|
}
|
|
31
53
|
function isUserId(params) {
|
|
32
|
-
return isValid(params.userId) && !isValid(params.email) && !isValid(params.phone) && !isValid(params.countryCode) && !isValid(params.farcasterUsername) && !isValid(params.telegramUserId) && !isValid(params.
|
|
54
|
+
return !!params && isValid(params.userId) && !isValid(params.email) && !isValid(params.phone) && !isValid(params.countryCode) && !isValid(params.farcasterUsername) && !isValid(params.xUsername) && !isValid(params.discordUsername) && !isValid(params.customId) && !isValid(params.telegramUserId) && !isValid(params.externalWalletAddress);
|
|
33
55
|
}
|
|
34
|
-
function
|
|
35
|
-
return
|
|
56
|
+
function isPrimary(params) {
|
|
57
|
+
return isEmail(params) || isPhone(params) || isFarcaster(params) || isTelegram(params) || isExternalWallet(params);
|
|
36
58
|
}
|
|
37
|
-
function
|
|
59
|
+
function isVerifiedAuth(params) {
|
|
60
|
+
return isEmail(params) || isPhone(params);
|
|
61
|
+
}
|
|
62
|
+
function isPregenAuth(params) {
|
|
63
|
+
return isPrimary(params) && !isExternalWallet(params) || isX(params) || isDiscord(params) || isCustomId(params);
|
|
64
|
+
}
|
|
65
|
+
function extractAuthInfo(obj, { allowUserId = false, allowPregen = false, isRequired = false } = {}) {
|
|
66
|
+
obj = Object.entries(obj || {}).reduce((acc, [k, v]) => {
|
|
67
|
+
return __spreadValues(__spreadValues({}, acc), !!v && v !== "null" && v !== "undefined" && v !== "" ? { [k]: v } : {});
|
|
68
|
+
}, {});
|
|
69
|
+
let error;
|
|
38
70
|
switch (true) {
|
|
39
71
|
case isEmail(obj):
|
|
40
|
-
return {
|
|
72
|
+
return {
|
|
73
|
+
auth: { email: obj.email },
|
|
74
|
+
authType: "email",
|
|
75
|
+
identifier: obj.email
|
|
76
|
+
};
|
|
41
77
|
case isPhone(obj):
|
|
78
|
+
if (!parsePhoneNumberFromString(obj.phone)) {
|
|
79
|
+
error = "invalid phone number";
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
auth: { phone: obj.phone },
|
|
84
|
+
authType: "phone",
|
|
85
|
+
identifier: obj.phone
|
|
86
|
+
};
|
|
87
|
+
case isPhoneLegacy(obj):
|
|
88
|
+
const identifier = `${obj.countryCode.startsWith("+") ? "" : "+"}${obj.countryCode}${obj.phone}`;
|
|
89
|
+
if (!parsePhoneNumberFromString(identifier)) {
|
|
90
|
+
error = "invalid phone number";
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
42
93
|
return {
|
|
43
|
-
auth: { phone:
|
|
94
|
+
auth: { phone: identifier },
|
|
44
95
|
authType: "phone",
|
|
45
|
-
identifier
|
|
46
|
-
publicKeyIdentifier: `${obj.countryCode}${obj.phone}`
|
|
96
|
+
identifier
|
|
47
97
|
};
|
|
48
98
|
case isFarcaster(obj):
|
|
49
99
|
return {
|
|
50
100
|
auth: { farcasterUsername: obj.farcasterUsername },
|
|
51
101
|
authType: "farcaster",
|
|
52
|
-
identifier: obj.farcasterUsername
|
|
53
|
-
publicKeyIdentifier: `${obj.farcasterUsername}-farcaster`
|
|
102
|
+
identifier: obj.farcasterUsername
|
|
54
103
|
};
|
|
55
104
|
case isTelegram(obj):
|
|
56
105
|
return {
|
|
57
106
|
auth: { telegramUserId: obj.telegramUserId },
|
|
58
107
|
authType: "telegram",
|
|
59
|
-
identifier: obj.telegramUserId
|
|
60
|
-
publicKeyIdentifier: `${obj.telegramUserId}-telegram`
|
|
108
|
+
identifier: obj.telegramUserId
|
|
61
109
|
};
|
|
62
110
|
case isExternalWallet(obj):
|
|
63
111
|
return {
|
|
64
112
|
auth: { externalWalletAddress: obj.externalWalletAddress },
|
|
65
113
|
authType: "externalWallet",
|
|
66
|
-
identifier: obj.externalWalletAddress
|
|
67
|
-
|
|
114
|
+
identifier: obj.externalWalletAddress
|
|
115
|
+
};
|
|
116
|
+
case (allowPregen && isX(obj)):
|
|
117
|
+
return {
|
|
118
|
+
auth: { xUsername: obj.xUsername },
|
|
119
|
+
authType: "x",
|
|
120
|
+
identifier: obj.xUsername
|
|
121
|
+
};
|
|
122
|
+
case (allowPregen && isDiscord(obj)):
|
|
123
|
+
return {
|
|
124
|
+
auth: { discordUsername: obj.discordUsername },
|
|
125
|
+
authType: "discord",
|
|
126
|
+
identifier: obj.discordUsername
|
|
127
|
+
};
|
|
128
|
+
case (allowPregen && isCustomId(obj)):
|
|
129
|
+
return {
|
|
130
|
+
auth: { customId: obj.customId },
|
|
131
|
+
authType: "customId",
|
|
132
|
+
identifier: obj.customId
|
|
133
|
+
};
|
|
134
|
+
case (allowPregen && isGuestId(obj)):
|
|
135
|
+
return {
|
|
136
|
+
auth: { guestId: obj.guestId },
|
|
137
|
+
authType: "guestId",
|
|
138
|
+
identifier: obj.guestId
|
|
68
139
|
};
|
|
69
140
|
case (isUserId(obj) && allowUserId):
|
|
70
|
-
return {
|
|
141
|
+
return {
|
|
142
|
+
auth: { userId: obj.userId },
|
|
143
|
+
authType: "userId",
|
|
144
|
+
identifier: obj.userId
|
|
145
|
+
};
|
|
71
146
|
default:
|
|
72
|
-
|
|
73
|
-
throw new Error("invalid auth object");
|
|
74
|
-
}
|
|
75
|
-
return void 0;
|
|
147
|
+
break;
|
|
76
148
|
}
|
|
149
|
+
if (isRequired) {
|
|
150
|
+
throw new Error(error != null ? error : "invalid auth object");
|
|
151
|
+
}
|
|
152
|
+
return void 0;
|
|
153
|
+
}
|
|
154
|
+
function toPregenTypeAndId(auth) {
|
|
155
|
+
const { authType, identifier: pregenIdentifier } = extractAuthInfo(auth, { isRequired: true, allowPregen: true });
|
|
156
|
+
const pregenIdentifierType = {
|
|
157
|
+
email: "EMAIL",
|
|
158
|
+
phone: "PHONE",
|
|
159
|
+
farcaster: "FARCASTER",
|
|
160
|
+
telegram: "TELEGRAM",
|
|
161
|
+
discord: "DISCORD",
|
|
162
|
+
x: "TWITTER",
|
|
163
|
+
customId: "CUSTOM_ID",
|
|
164
|
+
guestId: "GUEST_ID"
|
|
165
|
+
}[authType];
|
|
166
|
+
return [pregenIdentifierType, pregenIdentifier];
|
|
167
|
+
}
|
|
168
|
+
function toPregenIds(auth) {
|
|
169
|
+
const [pregenIdentifierType, pregenIdentifier] = toPregenTypeAndId(auth);
|
|
170
|
+
return { [pregenIdentifierType]: [pregenIdentifier] };
|
|
171
|
+
}
|
|
172
|
+
function fromAccountMetadata(obj) {
|
|
173
|
+
return Object.entries(obj || {}).reduce(
|
|
174
|
+
(acc, [method, obj2]) => __spreadProps(__spreadValues({}, acc), {
|
|
175
|
+
[method]: __spreadProps(__spreadValues({}, obj2), {
|
|
176
|
+
date: new Date(obj2.date)
|
|
177
|
+
})
|
|
178
|
+
}),
|
|
179
|
+
{}
|
|
180
|
+
);
|
|
77
181
|
}
|
|
78
182
|
export {
|
|
79
183
|
extractAuthInfo,
|
|
80
184
|
extractWalletRef,
|
|
185
|
+
fromAccountMetadata,
|
|
186
|
+
isCustomId,
|
|
187
|
+
isDiscord,
|
|
81
188
|
isEmail,
|
|
82
189
|
isExternalWallet,
|
|
83
190
|
isExternalWalletAddress,
|
|
84
191
|
isFarcaster,
|
|
192
|
+
isGuestId,
|
|
85
193
|
isPhone,
|
|
194
|
+
isPhoneLegacy,
|
|
195
|
+
isPregenAuth,
|
|
196
|
+
isPrimary,
|
|
86
197
|
isTelegram,
|
|
87
198
|
isUserId,
|
|
88
|
-
|
|
199
|
+
isVerifiedAuth,
|
|
200
|
+
isWalletId,
|
|
201
|
+
isX,
|
|
202
|
+
toPregenIds,
|
|
203
|
+
toPregenTypeAndId
|
|
89
204
|
};
|