@getpara/user-management-client 2.27.0 → 2.29.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.
@@ -84,6 +84,7 @@ __export(client_exports, {
84
84
  module.exports = __toCommonJS(client_exports);
85
85
  var import_axios = __toESM(require("axios"));
86
86
  var import_axios_retry = __toESM(require("axios-retry"));
87
+ var import_shared = require("@getpara/shared");
87
88
  var import_utils = require("./utils.js");
88
89
  var import_consts = require("./consts.js");
89
90
  var import_error = require("./error.js");
@@ -94,16 +95,31 @@ const handleResponseSuccess = (response) => {
94
95
  throw new import_error.ParaApiError("Invalid status code");
95
96
  };
96
97
  const handleResponseError = (error) => {
97
- var _a, _b, _c, _d;
98
+ var _a, _b, _c;
98
99
  if (error === null) throw new import_error.ParaApiError("Error is null");
99
100
  if (import_axios.default.isAxiosError(error)) {
100
- let message = (_b = (_a = error.response) == null ? void 0 : _a.data) != null ? _b : "Unknown error";
101
+ const data = (_a = error.response) == null ? void 0 : _a.data;
102
+ let message = typeof data === "string" ? data : "Unknown error";
103
+ let serverCode;
104
+ let serverData;
105
+ if (data && typeof data === "object") {
106
+ const body = data;
107
+ if (typeof body.message === "string") message = body.message;
108
+ serverCode = body.code;
109
+ serverData = body.data;
110
+ }
101
111
  if (error.code === "ERR_NETWORK") {
102
112
  message = "Connection error";
103
113
  } else if (error.code === "ERR_CANCELED") {
104
114
  message = "Connection canceled";
105
115
  }
106
- throw new import_error.ParaApiError(message, error.code, (_c = error.response) == null ? void 0 : _c.status, (_d = error.request) == null ? void 0 : _d.responseURL);
116
+ throw new import_error.ParaApiError(
117
+ message,
118
+ serverCode != null ? serverCode : error.code,
119
+ (_b = error.response) == null ? void 0 : _b.status,
120
+ (_c = error.request) == null ? void 0 : _c.responseURL,
121
+ serverData
122
+ );
107
123
  }
108
124
  throw new import_error.ParaApiError("Unknown error");
109
125
  };
@@ -601,7 +617,12 @@ class Client {
601
617
  });
602
618
  return { success: res.data.success };
603
619
  });
604
- const headers = __spreadValues(__spreadValues(__spreadValues({}, apiKey && { [import_consts.API_KEY_HEADER_NAME]: apiKey }), partnerId && { [import_consts.PARTNER_ID_HEADER_NAME]: partnerId }), partnerConfigOverride && { [import_consts.PARTNER_CONFIG_OVERRIDE_HEADER_NAME]: JSON.stringify(partnerConfigOverride) });
620
+ const headers = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, apiKey && { [import_consts.API_KEY_HEADER_NAME]: apiKey }), partnerId && { [import_consts.PARTNER_ID_HEADER_NAME]: partnerId }), partnerConfigOverride && { [import_consts.PARTNER_CONFIG_OVERRIDE_HEADER_NAME]: JSON.stringify(partnerConfigOverride) }), {
621
+ // Opts into structured-JSON error responses for OTP error classes (server-side
622
+ // contract added in @getpara/shared 1.16.0). Without it the server falls back to
623
+ // plain-text bodies for backward compat with older SDKs.
624
+ [import_shared.STRUCTURED_ERRORS_HEADER]: "1"
625
+ });
605
626
  const axiosConfig = {
606
627
  baseURL: userManagementHost,
607
628
  withCredentials: true,
@@ -748,7 +769,7 @@ class Client {
748
769
  return __async(this, null, function* () {
749
770
  var _f = _e, { userId } = _f, rest = __objRest(_f, ["userId"]);
750
771
  const res = yield this.baseRequest.post(`/users/${userId}/resend-verification-code`, rest);
751
- return res;
772
+ return res.data;
752
773
  });
753
774
  }
754
775
  // POST '/users/:userId/resend-verification-code-by-phone
package/dist/cjs/error.js CHANGED
@@ -20,7 +20,7 @@ __export(error_exports, {
20
20
  ParaApiError: () => ParaApiError
21
21
  });
22
22
  module.exports = __toCommonJS(error_exports);
23
- function ParaApiError(message, code, status, responseURL) {
23
+ function ParaApiError(message, code, status, responseURL, data) {
24
24
  Error.call(this);
25
25
  if (Error.captureStackTrace) {
26
26
  Error.captureStackTrace(this, this.constructor);
@@ -32,6 +32,7 @@ function ParaApiError(message, code, status, responseURL) {
32
32
  code && (this.code = code);
33
33
  status && (this.status = status);
34
34
  responseURL && (this.responseURL = responseURL);
35
+ data && (this.data = data);
35
36
  }
36
37
  const prototype = ParaApiError.prototype;
37
38
  Object.defineProperty(prototype, "isParaApiError", { value: true });
@@ -6,6 +6,9 @@ import {
6
6
  } from "./chunk-BBZEL7EG.js";
7
7
  import axios from "axios";
8
8
  import axiosRetry from "axios-retry";
9
+ import {
10
+ STRUCTURED_ERRORS_HEADER
11
+ } from "@getpara/shared";
9
12
  import { extractWalletRef, fromAccountMetadata, fromLinkedAccounts } from "./utils.js";
10
13
  import {
11
14
  SESSION_COOKIE_HEADER_NAME,
@@ -22,16 +25,31 @@ const handleResponseSuccess = (response) => {
22
25
  throw new ParaApiError("Invalid status code");
23
26
  };
24
27
  const handleResponseError = (error) => {
25
- var _a, _b, _c, _d;
28
+ var _a, _b, _c;
26
29
  if (error === null) throw new ParaApiError("Error is null");
27
30
  if (axios.isAxiosError(error)) {
28
- let message = (_b = (_a = error.response) == null ? void 0 : _a.data) != null ? _b : "Unknown error";
31
+ const data = (_a = error.response) == null ? void 0 : _a.data;
32
+ let message = typeof data === "string" ? data : "Unknown error";
33
+ let serverCode;
34
+ let serverData;
35
+ if (data && typeof data === "object") {
36
+ const body = data;
37
+ if (typeof body.message === "string") message = body.message;
38
+ serverCode = body.code;
39
+ serverData = body.data;
40
+ }
29
41
  if (error.code === "ERR_NETWORK") {
30
42
  message = "Connection error";
31
43
  } else if (error.code === "ERR_CANCELED") {
32
44
  message = "Connection canceled";
33
45
  }
34
- throw new ParaApiError(message, error.code, (_c = error.response) == null ? void 0 : _c.status, (_d = error.request) == null ? void 0 : _d.responseURL);
46
+ throw new ParaApiError(
47
+ message,
48
+ serverCode != null ? serverCode : error.code,
49
+ (_b = error.response) == null ? void 0 : _b.status,
50
+ (_c = error.request) == null ? void 0 : _c.responseURL,
51
+ serverData
52
+ );
35
53
  }
36
54
  throw new ParaApiError("Unknown error");
37
55
  };
@@ -529,7 +547,12 @@ class Client {
529
547
  });
530
548
  return { success: res.data.success };
531
549
  });
532
- const headers = __spreadValues(__spreadValues(__spreadValues({}, apiKey && { [API_KEY_HEADER_NAME]: apiKey }), partnerId && { [PARTNER_ID_HEADER_NAME]: partnerId }), partnerConfigOverride && { [PARTNER_CONFIG_OVERRIDE_HEADER_NAME]: JSON.stringify(partnerConfigOverride) });
550
+ const headers = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, apiKey && { [API_KEY_HEADER_NAME]: apiKey }), partnerId && { [PARTNER_ID_HEADER_NAME]: partnerId }), partnerConfigOverride && { [PARTNER_CONFIG_OVERRIDE_HEADER_NAME]: JSON.stringify(partnerConfigOverride) }), {
551
+ // Opts into structured-JSON error responses for OTP error classes (server-side
552
+ // contract added in @getpara/shared 1.16.0). Without it the server falls back to
553
+ // plain-text bodies for backward compat with older SDKs.
554
+ [STRUCTURED_ERRORS_HEADER]: "1"
555
+ });
533
556
  const axiosConfig = {
534
557
  baseURL: userManagementHost,
535
558
  withCredentials: true,
@@ -676,7 +699,7 @@ class Client {
676
699
  return __async(this, null, function* () {
677
700
  var _f = _e, { userId } = _f, rest = __objRest(_f, ["userId"]);
678
701
  const res = yield this.baseRequest.post(`/users/${userId}/resend-verification-code`, rest);
679
- return res;
702
+ return res.data;
680
703
  });
681
704
  }
682
705
  // POST '/users/:userId/resend-verification-code-by-phone
package/dist/esm/error.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./chunk-BBZEL7EG.js";
2
- function ParaApiError(message, code, status, responseURL) {
2
+ function ParaApiError(message, code, status, responseURL, data) {
3
3
  Error.call(this);
4
4
  if (Error.captureStackTrace) {
5
5
  Error.captureStackTrace(this, this.constructor);
@@ -11,6 +11,7 @@ function ParaApiError(message, code, status, responseURL) {
11
11
  code && (this.code = code);
12
12
  status && (this.status = status);
13
13
  responseURL && (this.responseURL = responseURL);
14
+ data && (this.data = data);
14
15
  }
15
16
  const prototype = ParaApiError.prototype;
16
17
  Object.defineProperty(prototype, "isParaApiError", { value: true });
@@ -1,5 +1,5 @@
1
1
  import { AxiosError, AxiosResponse } from 'axios';
2
- import { AccountMetadata, Auth, AuthIdentifier, AuthMethod, BackupKitEmailProps, BiometricLocationHint, Chain, CurrentWalletIds, EncryptedKeyShare, EncryptorType, ExternalWalletInfo, LoginExternalWalletResponse, KeyShareType, Network, OnRampAsset, OnRampConfig, OnRampProvider, OnRampPurchase, OnRampPurchaseCreateParams, OnRampPurchaseUpdateParams, AuthMethodStatus, PregenIds, PrimaryAuth, PublicKeyType, ServerAuthStateSignup, SessionInfo, Setup2faResponse, SignUpOrLogInResponse, TelegramAuthResponse, TPregenIdentifierType, VerificationEmailProps, VerifiedAuth, VerifyFarcasterResponse, VerifyTelegramResponse, VerifyThirdPartyAuth, WalletEntity, WalletParams, TWalletScheme, TWalletType, VerifyExternalWalletParams, IssueJwtParams, IssueJwtResponse, LinkAccountParams, LinkedAccounts, ResendVerificationCodeParams, AssetMetadataIndexed, GetProfileBalanceParams, ProfileBalance, LegacyAuthMethod, PrimaryAuthInfo, ServerAuthStateLogin, ServerAuthStateDone, UserPreferences, EstimateTransactionOpts, EstimateTransactionResult, BroadcastTransactionOpts, BroadcastTransactionResult, TExternalWalletType, GetPendingTransactionResponse } from '@getpara/shared';
2
+ import { AccountMetadata, Auth, AuthIdentifier, AuthMethod, BackupKitEmailProps, BiometricLocationHint, Chain, CurrentWalletIds, EncryptedKeyShare, EncryptorType, ExternalWalletInfo, LoginExternalWalletResponse, KeyShareType, Network, OnRampAsset, OnRampConfig, OnRampProvider, OnRampPurchase, OnRampPurchaseCreateParams, OnRampPurchaseUpdateParams, AuthMethodStatus, PregenIds, PrimaryAuth, PublicKeyType, ServerAuthStateSignup, SessionInfo, Setup2faResponse, SignUpOrLogInResponse, TelegramAuthResponse, TPregenIdentifierType, VerificationEmailProps, VerifiedAuth, VerifyFarcasterResponse, VerifyTelegramResponse, VerifyThirdPartyAuth, WalletEntity, WalletParams, TWalletScheme, TWalletType, VerifyExternalWalletParams, IssueJwtParams, IssueJwtResponse, LinkAccountParams, LinkedAccounts, ResendVerificationCodeParams, AssetMetadataIndexed, GetProfileBalanceParams, ProfileBalance, DeliveryChannel, LegacyAuthMethod, PrimaryAuthInfo, ServerAuthStateLogin, ServerAuthStateDone, UserPreferences, EstimateTransactionOpts, EstimateTransactionResult, BroadcastTransactionOpts, BroadcastTransactionResult, TExternalWalletType, GetPendingTransactionResponse } from '@getpara/shared';
3
3
  interface ConfigOpts {
4
4
  useFetchAdapter?: boolean;
5
5
  }
@@ -179,6 +179,10 @@ declare class Client {
179
179
  verifyAccount: (userId: string, body: verifyBody) => Promise<ServerAuthStateSignup | ServerAuthStateLogin | ServerAuthStateDone>;
180
180
  sendLoginVerificationCode: (auth: PrimaryAuthInfo, isRecovery?: boolean) => Promise<{
181
181
  userId: string;
182
+ deliveryChannel?: DeliveryChannel;
183
+ fallbackUsed?: boolean;
184
+ fallbackChannel?: DeliveryChannel;
185
+ isSmsAllowed?: boolean;
182
186
  }>;
183
187
  getLinkedAccounts: ({ userId, withMetadata, }: {
184
188
  userId: string;
@@ -296,7 +300,12 @@ declare class Client {
296
300
  getTransmissionKeyshares(userId: string, sessionLookupId: string): Promise<any>;
297
301
  getParaShare: (userId: string, walletId: string) => Promise<string>;
298
302
  getBackupKit: (userId: string, walletId: string) => Promise<any>;
299
- resendVerificationCode({ userId, ...rest }: ResendVerificationCodeParams): Promise<AxiosResponse<any, any>>;
303
+ resendVerificationCode({ userId, ...rest }: ResendVerificationCodeParams): Promise<{
304
+ deliveryChannel?: DeliveryChannel;
305
+ fallbackUsed?: boolean;
306
+ fallbackChannel?: DeliveryChannel;
307
+ isSmsAllowed?: boolean;
308
+ }>;
300
309
  resendVerificationCodeByPhone({ userId, ...rest }: {
301
310
  userId: string;
302
311
  } & VerificationEmailProps): Promise<AxiosResponse<any, any>>;
@@ -1 +1 @@
1
- export declare function ParaApiError(message: string, code?: string, status?: number, responseURL?: string): void;
1
+ export declare function ParaApiError(message: string, code?: string, status?: number, responseURL?: string, data?: Record<string, unknown>): void;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@getpara/user-management-client",
3
- "version": "2.27.0",
3
+ "version": "2.29.0",
4
4
  "dependencies": {
5
- "@getpara/shared": "^1.14.0",
5
+ "@getpara/shared": "^1.17.0",
6
6
  "axios": "^1.8.4",
7
7
  "axios-retry": "^4.5.0",
8
8
  "libphonenumber-js": "^1.11.7"
@@ -21,7 +21,7 @@
21
21
  "dist",
22
22
  "package.json"
23
23
  ],
24
- "gitHead": "9f3045c8e2b0b372c792a7a35a997d5955f910b1",
24
+ "gitHead": "3fe797a65534cf466471441317763b1cef00b5b5",
25
25
  "main": "dist/cjs/index.js",
26
26
  "module": "dist/esm/index.js",
27
27
  "scripts": {