@dynamic-labs-sdk/client 0.0.1-alpha.7 → 0.0.1-alpha.8

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 (129) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/core.cjs.js +4 -0
  3. package/core.esm.js +2 -1
  4. package/getWalletProviderFromWalletAccount.cjs.js +110 -17
  5. package/getWalletProviderFromWalletAccount.esm.js +107 -18
  6. package/index.cjs.js +158 -154
  7. package/index.esm.js +151 -155
  8. package/package.json +1 -1
  9. package/src/client/core/createCore/getInitialState.d.ts.map +1 -1
  10. package/src/errors/APIError/APIError.d.ts +0 -1
  11. package/src/errors/APIError/APIError.d.ts.map +1 -1
  12. package/src/errors/CannotTrackError.d.ts +5 -0
  13. package/src/errors/CannotTrackError.d.ts.map +1 -0
  14. package/src/errors/ClientAlreadyInitializedError.d.ts +5 -0
  15. package/src/errors/ClientAlreadyInitializedError.d.ts.map +1 -0
  16. package/src/errors/ClientNotPresentError.d.ts +5 -0
  17. package/src/errors/ClientNotPresentError.d.ts.map +1 -0
  18. package/src/errors/ClientsDoNotMatchError.d.ts +5 -0
  19. package/src/errors/ClientsDoNotMatchError.d.ts.map +1 -0
  20. package/src/errors/InvalidRedirectStorageStateError.d.ts +5 -0
  21. package/src/errors/InvalidRedirectStorageStateError.d.ts.map +1 -0
  22. package/src/{services/storage/createWebStorage/errors → errors}/InvalidStorageSet.d.ts +1 -1
  23. package/src/errors/InvalidStorageSet.d.ts.map +1 -0
  24. package/src/errors/MethodNotImplementedError.d.ts +1 -1
  25. package/src/errors/MethodNotImplementedError.d.ts.map +1 -1
  26. package/src/errors/MfaInvalidOtpError.d.ts +5 -0
  27. package/src/errors/MfaInvalidOtpError.d.ts.map +1 -0
  28. package/src/errors/MfaRateLimitedError.d.ts +5 -0
  29. package/src/errors/MfaRateLimitedError.d.ts.map +1 -0
  30. package/src/errors/MissingRedirectStorageStateError.d.ts +5 -0
  31. package/src/errors/MissingRedirectStorageStateError.d.ts.map +1 -0
  32. package/src/errors/MissingSocialUrlParamError.d.ts +5 -0
  33. package/src/errors/MissingSocialUrlParamError.d.ts.map +1 -0
  34. package/src/errors/NoAddressFoundError.d.ts +5 -0
  35. package/src/errors/NoAddressFoundError.d.ts.map +1 -0
  36. package/src/errors/NoPasskeyCredentialsFoundError.d.ts +5 -0
  37. package/src/errors/NoPasskeyCredentialsFoundError.d.ts.map +1 -0
  38. package/src/errors/NoWebAuthNSupportError.d.ts +5 -0
  39. package/src/errors/NoWebAuthNSupportError.d.ts.map +1 -0
  40. package/src/errors/UnavailableInServerSideError.d.ts +1 -1
  41. package/src/errors/UnavailableInServerSideError.d.ts.map +1 -1
  42. package/src/errors/UserNotAuthenticatedError.d.ts +5 -0
  43. package/src/errors/UserNotAuthenticatedError.d.ts.map +1 -0
  44. package/src/errors/ValueMustBeDefinedError.d.ts +5 -0
  45. package/src/errors/ValueMustBeDefinedError.d.ts.map +1 -0
  46. package/src/errors/WalletAccountAlreadyVerifiedError.d.ts +5 -0
  47. package/src/errors/WalletAccountAlreadyVerifiedError.d.ts.map +1 -0
  48. package/src/{modules/wallets/assertWalletAccountSigningAvailability/errors → errors}/WalletAccountNotSelectedError.d.ts +1 -1
  49. package/src/errors/WalletAccountNotSelectedError.d.ts.map +1 -0
  50. package/src/{modules/wallets/verifyWalletAccount/errors → errors}/WalletAlreadyLinkedToAnotherUserError.d.ts +1 -2
  51. package/src/errors/WalletAlreadyLinkedToAnotherUserError.d.ts.map +1 -0
  52. package/src/errors/base/BaseError.d.ts +6 -0
  53. package/src/errors/base/BaseError.d.ts.map +1 -1
  54. package/src/exports/core.d.ts +6 -3
  55. package/src/exports/core.d.ts.map +1 -1
  56. package/src/exports/index.d.ts +17 -8
  57. package/src/exports/index.d.ts.map +1 -1
  58. package/src/modules/apiClient/createApiClient.d.ts +2 -1
  59. package/src/modules/apiClient/createApiClient.d.ts.map +1 -1
  60. package/src/modules/apiClient/types.d.ts +35 -0
  61. package/src/modules/apiClient/types.d.ts.map +1 -0
  62. package/src/modules/apiClient/utils/clientErrorMapper/clientErrorMapper.d.ts +22 -0
  63. package/src/modules/apiClient/utils/clientErrorMapper/clientErrorMapper.d.ts.map +1 -0
  64. package/src/modules/apiClient/utils/clientErrorMapper/index.d.ts +2 -0
  65. package/src/modules/apiClient/utils/clientErrorMapper/index.d.ts.map +1 -0
  66. package/src/modules/apiClient/utils/convertToApiErrorMiddleware/convertToApiErrorMiddleware.d.ts +15 -0
  67. package/src/modules/apiClient/utils/convertToApiErrorMiddleware/convertToApiErrorMiddleware.d.ts.map +1 -0
  68. package/src/modules/apiClient/utils/convertToApiErrorMiddleware/index.d.ts +2 -0
  69. package/src/modules/apiClient/utils/convertToApiErrorMiddleware/index.d.ts.map +1 -0
  70. package/src/modules/auth/social/oauth/completeSocialRedirectSignIn/completeSocialRedirectSignIn.d.ts.map +1 -1
  71. package/src/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.d.ts.map +1 -1
  72. package/src/modules/mfa/consumeMfaToken/consumeMfaToken.d.ts +3 -0
  73. package/src/modules/mfa/consumeMfaToken/consumeMfaToken.d.ts.map +1 -0
  74. package/src/modules/mfa/consumeMfaToken/index.d.ts +2 -0
  75. package/src/modules/mfa/consumeMfaToken/index.d.ts.map +1 -0
  76. package/src/modules/mfa/registerTotpMfaDevice/registerTotpMfaDevice.d.ts.map +1 -1
  77. package/src/modules/mfa/state.d.ts +13 -0
  78. package/src/modules/mfa/state.d.ts.map +1 -0
  79. package/src/modules/storageSync/hydrateStateWithStorage/hydrateStateWithStorage.d.ts.map +1 -1
  80. package/src/modules/storageSync/schema.d.ts +1 -0
  81. package/src/modules/storageSync/schema.d.ts.map +1 -1
  82. package/src/modules/storageSync/syncStateWithStorage/syncStateWithStorage.d.ts.map +1 -1
  83. package/src/modules/wallets/verifyWalletAccount/verifyWalletAccount.d.ts.map +1 -1
  84. package/src/utils/retryOnFail/InvalidRetryOnFailCallError.d.ts.map +1 -1
  85. package/src/modules/apiClient/middleware/convertToApiErrorMiddleware.d.ts +0 -3
  86. package/src/modules/apiClient/middleware/convertToApiErrorMiddleware.d.ts.map +0 -1
  87. package/src/modules/auth/errors/UserNotAuthenticatedError.d.ts +0 -6
  88. package/src/modules/auth/errors/UserNotAuthenticatedError.d.ts.map +0 -1
  89. package/src/modules/auth/passkeys/errors/NoPasskeyCredentialsFoundError.d.ts +0 -5
  90. package/src/modules/auth/passkeys/errors/NoPasskeyCredentialsFoundError.d.ts.map +0 -1
  91. package/src/modules/auth/passkeys/errors/NoWebAuthNSupportError.d.ts +0 -5
  92. package/src/modules/auth/passkeys/errors/NoWebAuthNSupportError.d.ts.map +0 -1
  93. package/src/modules/auth/social/oauth/errors/InvalidRedirectStorageStateError/InvalidRedirectStorageStateError.d.ts +0 -5
  94. package/src/modules/auth/social/oauth/errors/InvalidRedirectStorageStateError/InvalidRedirectStorageStateError.d.ts.map +0 -1
  95. package/src/modules/auth/social/oauth/errors/InvalidRedirectStorageStateError/index.d.ts +0 -2
  96. package/src/modules/auth/social/oauth/errors/InvalidRedirectStorageStateError/index.d.ts.map +0 -1
  97. package/src/modules/auth/social/oauth/errors/MissingRedirectStorageStateError/MissingRedirectStorageStateError.d.ts +0 -5
  98. package/src/modules/auth/social/oauth/errors/MissingRedirectStorageStateError/MissingRedirectStorageStateError.d.ts.map +0 -1
  99. package/src/modules/auth/social/oauth/errors/MissingRedirectStorageStateError/index.d.ts +0 -2
  100. package/src/modules/auth/social/oauth/errors/MissingRedirectStorageStateError/index.d.ts.map +0 -1
  101. package/src/modules/auth/social/oauth/errors/MissingSocialUrlParamError/MissingSocialUrlParamError.d.ts +0 -5
  102. package/src/modules/auth/social/oauth/errors/MissingSocialUrlParamError/MissingSocialUrlParamError.d.ts.map +0 -1
  103. package/src/modules/auth/social/oauth/errors/MissingSocialUrlParamError/index.d.ts +0 -2
  104. package/src/modules/auth/social/oauth/errors/MissingSocialUrlParamError/index.d.ts.map +0 -1
  105. package/src/modules/initializeClient/errors/ClientAlreadyInitializedError.d.ts +0 -5
  106. package/src/modules/initializeClient/errors/ClientAlreadyInitializedError.d.ts.map +0 -1
  107. package/src/modules/mfa/errors/MfaInvalidOtpError.d.ts +0 -6
  108. package/src/modules/mfa/errors/MfaInvalidOtpError.d.ts.map +0 -1
  109. package/src/modules/mfa/errors/MfaRateLimitedError.d.ts +0 -6
  110. package/src/modules/mfa/errors/MfaRateLimitedError.d.ts.map +0 -1
  111. package/src/modules/mfa/utils/mapMfaErrorsAndThrow/index.d.ts +0 -2
  112. package/src/modules/mfa/utils/mapMfaErrorsAndThrow/index.d.ts.map +0 -1
  113. package/src/modules/mfa/utils/mapMfaErrorsAndThrow/mapMfaErrorsAndThrow.d.ts +0 -2
  114. package/src/modules/mfa/utils/mapMfaErrorsAndThrow/mapMfaErrorsAndThrow.d.ts.map +0 -1
  115. package/src/modules/wallets/assertWalletAccountSigningAvailability/errors/WalletAccountNotSelectedError.d.ts.map +0 -1
  116. package/src/modules/wallets/connectWithWalletProvider/errors/NoAddressFoundError.d.ts +0 -5
  117. package/src/modules/wallets/connectWithWalletProvider/errors/NoAddressFoundError.d.ts.map +0 -1
  118. package/src/modules/wallets/verifyWalletAccount/errors/WalletAccountAlreadyVerifiedError.d.ts +0 -5
  119. package/src/modules/wallets/verifyWalletAccount/errors/WalletAccountAlreadyVerifiedError.d.ts.map +0 -1
  120. package/src/modules/wallets/verifyWalletAccount/errors/WalletAlreadyLinkedToAnotherUserError.d.ts.map +0 -1
  121. package/src/services/asyncTrack/errors/CannotTrackError.d.ts +0 -5
  122. package/src/services/asyncTrack/errors/CannotTrackError.d.ts.map +0 -1
  123. package/src/services/storage/createWebStorage/errors/InvalidStorageSet.d.ts.map +0 -1
  124. package/src/utils/assertClientAreEqual/errors/ClientDoNotMatchError.d.ts +0 -5
  125. package/src/utils/assertClientAreEqual/errors/ClientDoNotMatchError.d.ts.map +0 -1
  126. package/src/utils/assertDefined/errors/ValueMustBeDefinedError.d.ts +0 -5
  127. package/src/utils/assertDefined/errors/ValueMustBeDefinedError.d.ts.map +0 -1
  128. package/src/utils/getClient/errors/ClientNotPresentError.d.ts +0 -5
  129. package/src/utils/getClient/errors/ClientNotPresentError.d.ts.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.0.1-alpha.8 (2025-07-03)
2
+
3
+ This was a version bump only, there were no code changes.
4
+
1
5
  ## 0.0.1-alpha.7 (2025-07-02)
2
6
 
3
7
  ### 🩹 Fixes
package/core.cjs.js CHANGED
@@ -8,6 +8,7 @@ class MethodNotImplementedError extends getWalletProviderFromWalletAccount.BaseE
8
8
  constructor(methodName){
9
9
  super({
10
10
  cause: null,
11
+ code: 'method_not_implemented_error',
11
12
  docsUrl: null,
12
13
  name: 'MethodNotImplementedError',
13
14
  shortMessage: `This method is not implemented: ${methodName}`
@@ -86,9 +87,12 @@ const bufferToBase64 = (buf)=>{
86
87
  return getBuffer().from(binstr, 'binary').toString('base64');
87
88
  };
88
89
 
90
+ exports.APIError = getWalletProviderFromWalletAccount.APIError;
89
91
  exports.CannotTrackError = getWalletProviderFromWalletAccount.CannotTrackError;
90
92
  exports.ClientNotPresentError = getWalletProviderFromWalletAccount.ClientNotPresentError;
93
+ exports.ClientsDoNotMatchError = getWalletProviderFromWalletAccount.ClientsDoNotMatchError;
91
94
  exports.InvalidStorageSet = getWalletProviderFromWalletAccount.InvalidStorageSet;
95
+ exports.ValueMustBeDefinedError = getWalletProviderFromWalletAccount.ValueMustBeDefinedError;
92
96
  Object.defineProperty(exports, "WalletProviderPriority", {
93
97
  enumerable: true,
94
98
  get: function () { return getWalletProviderFromWalletAccount.WalletProviderPriority; }
package/core.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { B as BaseError, g as getCore } from './getWalletProviderFromWalletAccount.esm.js';
2
- export { C as CannotTrackError, n as ClientNotPresentError, I as InvalidStorageSet, W as WalletProviderPriority, a as assertDefined, b as assignClient, c as createApiClient, e as emitEvent, f as getClient, h as getWalletProviderFromWalletAccount, j as getWalletProviderRegistry, m as hasExtension, s as subscribeWithSelector } from './getWalletProviderFromWalletAccount.esm.js';
2
+ export { A as APIError, C as CannotTrackError, p as ClientNotPresentError, q as ClientsDoNotMatchError, I as InvalidStorageSet, V as ValueMustBeDefinedError, W as WalletProviderPriority, a as assertDefined, b as assignClient, c as createApiClient, e as emitEvent, f as getClient, h as getWalletProviderFromWalletAccount, j as getWalletProviderRegistry, n as hasExtension, s as subscribeWithSelector } from './getWalletProviderFromWalletAccount.esm.js';
3
3
  import { Buffer as Buffer$1 } from 'buffer';
4
4
  import '@dynamic-labs/sdk-api-core';
5
5
 
@@ -7,6 +7,7 @@ class MethodNotImplementedError extends BaseError {
7
7
  constructor(methodName){
8
8
  super({
9
9
  cause: null,
10
+ code: 'method_not_implemented_error',
10
11
  docsUrl: null,
11
12
  name: 'MethodNotImplementedError',
12
13
  shortMessage: `This method is not implemented: ${methodName}`
@@ -70,7 +70,7 @@ function _extends() {
70
70
  return _extends.apply(this, arguments);
71
71
  }
72
72
 
73
- var version = "0.0.1-alpha.7";
73
+ var version = "0.0.1-alpha.8";
74
74
  var dependencies = {
75
75
  "@dynamic-labs/sdk-api-core": "0.0.702"};
76
76
 
@@ -115,19 +115,26 @@ const getDetails = ({ details, cause })=>{
115
115
  }
116
116
  return cause;
117
117
  }
118
+ toString() {
119
+ return this.formattedMessage;
120
+ }
118
121
  constructor(args){
119
122
  const details = getDetails(args);
120
- super(formatMessage(_extends({}, args, {
123
+ const formattedMessage = formatMessage(_extends({}, args, {
121
124
  details
122
- })), args.cause ? {
125
+ }));
126
+ var _args_shortMessage;
127
+ super((_args_shortMessage = args.shortMessage) != null ? _args_shortMessage : formattedMessage, args.cause ? {
123
128
  cause: args.cause
124
129
  } : undefined);
125
130
  this.name = 'BaseError';
131
+ this.formattedMessage = formattedMessage;
126
132
  this.details = details;
127
133
  var _args_name;
128
134
  this.name = (_args_name = args.name) != null ? _args_name : this.name;
129
135
  var _args_cause;
130
136
  this.cause = (_args_cause = args.cause) != null ? _args_cause : this.cause;
137
+ this.code = args.code;
131
138
  }
132
139
  }
133
140
 
@@ -142,31 +149,103 @@ class APIError extends BaseError {
142
149
  constructor(message, code){
143
150
  super({
144
151
  cause: null,
152
+ code,
145
153
  docsUrl: null,
146
154
  name: 'APIError',
147
155
  shortMessage: message
148
156
  });
149
- this.code = code;
150
157
  }
151
158
  }
152
159
 
153
- const convertToApiErrorMiddleware = {
154
- post: async (context)=>{
155
- if (context.response.status >= 400) {
156
- const apiError = await APIError.fromResponse(context.response);
157
- if (apiError) {
158
- throw apiError;
159
- }
160
+ class MfaInvalidOtpError extends BaseError {
161
+ constructor({ cause }){
162
+ super({
163
+ cause,
164
+ code: 'mfa_invalid_otp_error',
165
+ docsUrl: null,
166
+ name: 'MfaInvalidOtpError',
167
+ shortMessage: 'Invalid OTP'
168
+ });
169
+ }
170
+ }
171
+
172
+ class MfaRateLimitedError extends BaseError {
173
+ constructor({ cause }){
174
+ super({
175
+ cause,
176
+ code: 'mfa_rate_limited_error',
177
+ docsUrl: null,
178
+ name: 'MfaRateLimitedError',
179
+ shortMessage: 'Rate limited'
180
+ });
181
+ }
182
+ }
183
+
184
+ /**
185
+ * Default error mapper for the client that handles common API error codes.
186
+ *
187
+ * This mapper transforms specific API error codes into more specific error types:
188
+ * - `mfa_invalid_code` → `MfaInvalidOtpError`
189
+ * - `mfa_rate_limited` → `MfaRateLimitedError`
190
+ *
191
+ * @param error - The error to be mapped
192
+ * @returns A transformed error if the error code matches a known pattern, or null if no transformation is needed
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * // This will be automatically applied to all API errors
197
+ * const apiClient = createApiClient(client);
198
+ *
199
+ * // The clientErrorMapper will automatically convert mfa_invalid_code errors
200
+ * // to MfaInvalidOtpError instances
201
+ * ```
202
+ */ const clientErrorMapper = (error)=>{
203
+ if (error instanceof APIError) {
204
+ if (error.code === 'mfa_invalid_code') {
205
+ return new MfaInvalidOtpError({
206
+ cause: error
207
+ });
208
+ }
209
+ if (error.code === 'mfa_rate_limited') {
210
+ return new MfaRateLimitedError({
211
+ cause: error
212
+ });
160
213
  }
161
- return context.response;
162
214
  }
215
+ return null;
163
216
  };
164
217
 
218
+ /**
219
+ * Creates middleware that converts HTTP error responses to APIError instances
220
+ * and optionally applies custom error mappers to transform them into specific error types.
221
+ *
222
+ * @param options.errorMappers - Array of error mappers to apply to API errors
223
+ * @returns A middleware function that handles error conversion and mapping
224
+ */ const createConvertToApiErrorMiddleware = ({ errorMappers = [] })=>({
225
+ post: async (context)=>{
226
+ if (context.response.status >= 400) {
227
+ const apiError = await APIError.fromResponse(context.response);
228
+ if (apiError) {
229
+ let errorToThrow = apiError;
230
+ for (const mapper of errorMappers){
231
+ const newError = mapper(apiError);
232
+ if (newError) {
233
+ errorToThrow = newError;
234
+ break;
235
+ }
236
+ }
237
+ throw errorToThrow;
238
+ }
239
+ }
240
+ return context.response;
241
+ }
242
+ });
243
+
165
244
  /**
166
245
  * Returns a new instance of the SDK API client.
167
246
  *
168
247
  * This is not meant for storing, as it is very light we can create it whenever needed.
169
- */ const createApiClient = (client)=>{
248
+ */ const createApiClient = (client, options = {})=>{
170
249
  const core = getCore(client);
171
250
  const settings = {
172
251
  basePath: core.apiBaseUrl,
@@ -182,7 +261,12 @@ const convertToApiErrorMiddleware = {
182
261
  return new sdkApiCore.SDKApi(new sdkApiCore.Configuration(_extends({}, settings, {
183
262
  fetchApi: core.fetch,
184
263
  middleware: [
185
- convertToApiErrorMiddleware
264
+ createConvertToApiErrorMiddleware({
265
+ errorMappers: [
266
+ ...options.errorMappers || [],
267
+ clientErrorMapper
268
+ ]
269
+ })
186
270
  ]
187
271
  })));
188
272
  };
@@ -226,6 +310,7 @@ class ValueMustBeDefinedError extends BaseError {
226
310
  constructor(message){
227
311
  super({
228
312
  cause: null,
313
+ code: 'value_must_be_defined_error',
229
314
  docsUrl: null,
230
315
  name: 'ValueMustBeDefined',
231
316
  shortMessage: message
@@ -267,6 +352,7 @@ class ClientNotPresentError extends BaseError {
267
352
  constructor(){
268
353
  super({
269
354
  cause: null,
355
+ code: 'client_not_present_error',
270
356
  docsUrl: null,
271
357
  name: 'ClientNotPresentError',
272
358
  shortMessage: 'The client is not present in the target object.'
@@ -286,6 +372,7 @@ class InvalidStorageSet extends BaseError {
286
372
  constructor({ key, value }){
287
373
  super({
288
374
  cause: null,
375
+ code: 'invalid_storage_set',
289
376
  docsUrl: null,
290
377
  metaMessages: [
291
378
  `key: ${key}`,
@@ -301,6 +388,7 @@ class CannotTrackError extends BaseError {
301
388
  constructor(){
302
389
  super({
303
390
  cause: null,
391
+ code: 'cannot_track_error',
304
392
  docsUrl: null,
305
393
  name: 'CannotTrackError',
306
394
  shortMessage: 'All track calls must be performed in the same node tick'
@@ -334,12 +422,13 @@ class CannotTrackError extends BaseError {
334
422
  return core.extensions.has(extensionKey);
335
423
  };
336
424
 
337
- class ClientDoNotMatchError extends BaseError {
425
+ class ClientsDoNotMatchError extends BaseError {
338
426
  constructor(){
339
427
  super({
340
428
  cause: null,
429
+ code: 'clients_do_not_match_error',
341
430
  docsUrl: null,
342
- name: 'ClientDoNotMatchError',
431
+ name: 'ClientsDoNotMatchError',
343
432
  shortMessage: 'Clients do not match'
344
433
  });
345
434
  }
@@ -347,7 +436,7 @@ class ClientDoNotMatchError extends BaseError {
347
436
 
348
437
  const assertClientAreEqual = (client1, client2)=>{
349
438
  if (client1 !== client2) {
350
- throw new ClientDoNotMatchError();
439
+ throw new ClientsDoNotMatchError();
351
440
  }
352
441
  };
353
442
 
@@ -452,7 +541,11 @@ exports.APIError = APIError;
452
541
  exports.BaseError = BaseError;
453
542
  exports.CannotTrackError = CannotTrackError;
454
543
  exports.ClientNotPresentError = ClientNotPresentError;
544
+ exports.ClientsDoNotMatchError = ClientsDoNotMatchError;
455
545
  exports.InvalidStorageSet = InvalidStorageSet;
546
+ exports.MfaInvalidOtpError = MfaInvalidOtpError;
547
+ exports.MfaRateLimitedError = MfaRateLimitedError;
548
+ exports.ValueMustBeDefinedError = ValueMustBeDefinedError;
456
549
  exports._extends = _extends;
457
550
  exports.assertDefined = assertDefined;
458
551
  exports.assignClient = assignClient;
@@ -68,7 +68,7 @@ function _extends() {
68
68
  return _extends.apply(this, arguments);
69
69
  }
70
70
 
71
- var version = "0.0.1-alpha.7";
71
+ var version = "0.0.1-alpha.8";
72
72
  var dependencies = {
73
73
  "@dynamic-labs/sdk-api-core": "0.0.702"};
74
74
 
@@ -113,19 +113,26 @@ const getDetails = ({ details, cause })=>{
113
113
  }
114
114
  return cause;
115
115
  }
116
+ toString() {
117
+ return this.formattedMessage;
118
+ }
116
119
  constructor(args){
117
120
  const details = getDetails(args);
118
- super(formatMessage(_extends({}, args, {
121
+ const formattedMessage = formatMessage(_extends({}, args, {
119
122
  details
120
- })), args.cause ? {
123
+ }));
124
+ var _args_shortMessage;
125
+ super((_args_shortMessage = args.shortMessage) != null ? _args_shortMessage : formattedMessage, args.cause ? {
121
126
  cause: args.cause
122
127
  } : undefined);
123
128
  this.name = 'BaseError';
129
+ this.formattedMessage = formattedMessage;
124
130
  this.details = details;
125
131
  var _args_name;
126
132
  this.name = (_args_name = args.name) != null ? _args_name : this.name;
127
133
  var _args_cause;
128
134
  this.cause = (_args_cause = args.cause) != null ? _args_cause : this.cause;
135
+ this.code = args.code;
129
136
  }
130
137
  }
131
138
 
@@ -140,31 +147,103 @@ class APIError extends BaseError {
140
147
  constructor(message, code){
141
148
  super({
142
149
  cause: null,
150
+ code,
143
151
  docsUrl: null,
144
152
  name: 'APIError',
145
153
  shortMessage: message
146
154
  });
147
- this.code = code;
148
155
  }
149
156
  }
150
157
 
151
- const convertToApiErrorMiddleware = {
152
- post: async (context)=>{
153
- if (context.response.status >= 400) {
154
- const apiError = await APIError.fromResponse(context.response);
155
- if (apiError) {
156
- throw apiError;
157
- }
158
+ class MfaInvalidOtpError extends BaseError {
159
+ constructor({ cause }){
160
+ super({
161
+ cause,
162
+ code: 'mfa_invalid_otp_error',
163
+ docsUrl: null,
164
+ name: 'MfaInvalidOtpError',
165
+ shortMessage: 'Invalid OTP'
166
+ });
167
+ }
168
+ }
169
+
170
+ class MfaRateLimitedError extends BaseError {
171
+ constructor({ cause }){
172
+ super({
173
+ cause,
174
+ code: 'mfa_rate_limited_error',
175
+ docsUrl: null,
176
+ name: 'MfaRateLimitedError',
177
+ shortMessage: 'Rate limited'
178
+ });
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Default error mapper for the client that handles common API error codes.
184
+ *
185
+ * This mapper transforms specific API error codes into more specific error types:
186
+ * - `mfa_invalid_code` → `MfaInvalidOtpError`
187
+ * - `mfa_rate_limited` → `MfaRateLimitedError`
188
+ *
189
+ * @param error - The error to be mapped
190
+ * @returns A transformed error if the error code matches a known pattern, or null if no transformation is needed
191
+ *
192
+ * @example
193
+ * ```typescript
194
+ * // This will be automatically applied to all API errors
195
+ * const apiClient = createApiClient(client);
196
+ *
197
+ * // The clientErrorMapper will automatically convert mfa_invalid_code errors
198
+ * // to MfaInvalidOtpError instances
199
+ * ```
200
+ */ const clientErrorMapper = (error)=>{
201
+ if (error instanceof APIError) {
202
+ if (error.code === 'mfa_invalid_code') {
203
+ return new MfaInvalidOtpError({
204
+ cause: error
205
+ });
206
+ }
207
+ if (error.code === 'mfa_rate_limited') {
208
+ return new MfaRateLimitedError({
209
+ cause: error
210
+ });
158
211
  }
159
- return context.response;
160
212
  }
213
+ return null;
161
214
  };
162
215
 
216
+ /**
217
+ * Creates middleware that converts HTTP error responses to APIError instances
218
+ * and optionally applies custom error mappers to transform them into specific error types.
219
+ *
220
+ * @param options.errorMappers - Array of error mappers to apply to API errors
221
+ * @returns A middleware function that handles error conversion and mapping
222
+ */ const createConvertToApiErrorMiddleware = ({ errorMappers = [] })=>({
223
+ post: async (context)=>{
224
+ if (context.response.status >= 400) {
225
+ const apiError = await APIError.fromResponse(context.response);
226
+ if (apiError) {
227
+ let errorToThrow = apiError;
228
+ for (const mapper of errorMappers){
229
+ const newError = mapper(apiError);
230
+ if (newError) {
231
+ errorToThrow = newError;
232
+ break;
233
+ }
234
+ }
235
+ throw errorToThrow;
236
+ }
237
+ }
238
+ return context.response;
239
+ }
240
+ });
241
+
163
242
  /**
164
243
  * Returns a new instance of the SDK API client.
165
244
  *
166
245
  * This is not meant for storing, as it is very light we can create it whenever needed.
167
- */ const createApiClient = (client)=>{
246
+ */ const createApiClient = (client, options = {})=>{
168
247
  const core = getCore(client);
169
248
  const settings = {
170
249
  basePath: core.apiBaseUrl,
@@ -180,7 +259,12 @@ const convertToApiErrorMiddleware = {
180
259
  return new SDKApi(new Configuration(_extends({}, settings, {
181
260
  fetchApi: core.fetch,
182
261
  middleware: [
183
- convertToApiErrorMiddleware
262
+ createConvertToApiErrorMiddleware({
263
+ errorMappers: [
264
+ ...options.errorMappers || [],
265
+ clientErrorMapper
266
+ ]
267
+ })
184
268
  ]
185
269
  })));
186
270
  };
@@ -224,6 +308,7 @@ class ValueMustBeDefinedError extends BaseError {
224
308
  constructor(message){
225
309
  super({
226
310
  cause: null,
311
+ code: 'value_must_be_defined_error',
227
312
  docsUrl: null,
228
313
  name: 'ValueMustBeDefined',
229
314
  shortMessage: message
@@ -265,6 +350,7 @@ class ClientNotPresentError extends BaseError {
265
350
  constructor(){
266
351
  super({
267
352
  cause: null,
353
+ code: 'client_not_present_error',
268
354
  docsUrl: null,
269
355
  name: 'ClientNotPresentError',
270
356
  shortMessage: 'The client is not present in the target object.'
@@ -284,6 +370,7 @@ class InvalidStorageSet extends BaseError {
284
370
  constructor({ key, value }){
285
371
  super({
286
372
  cause: null,
373
+ code: 'invalid_storage_set',
287
374
  docsUrl: null,
288
375
  metaMessages: [
289
376
  `key: ${key}`,
@@ -299,6 +386,7 @@ class CannotTrackError extends BaseError {
299
386
  constructor(){
300
387
  super({
301
388
  cause: null,
389
+ code: 'cannot_track_error',
302
390
  docsUrl: null,
303
391
  name: 'CannotTrackError',
304
392
  shortMessage: 'All track calls must be performed in the same node tick'
@@ -332,12 +420,13 @@ class CannotTrackError extends BaseError {
332
420
  return core.extensions.has(extensionKey);
333
421
  };
334
422
 
335
- class ClientDoNotMatchError extends BaseError {
423
+ class ClientsDoNotMatchError extends BaseError {
336
424
  constructor(){
337
425
  super({
338
426
  cause: null,
427
+ code: 'clients_do_not_match_error',
339
428
  docsUrl: null,
340
- name: 'ClientDoNotMatchError',
429
+ name: 'ClientsDoNotMatchError',
341
430
  shortMessage: 'Clients do not match'
342
431
  });
343
432
  }
@@ -345,7 +434,7 @@ class ClientDoNotMatchError extends BaseError {
345
434
 
346
435
  const assertClientAreEqual = (client1, client2)=>{
347
436
  if (client1 !== client2) {
348
- throw new ClientDoNotMatchError();
437
+ throw new ClientsDoNotMatchError();
349
438
  }
350
439
  };
351
440
 
@@ -446,4 +535,4 @@ const getWalletProviderFromWalletAccount = (walletAccount)=>{
446
535
  return walletProvider;
447
536
  };
448
537
 
449
- export { APIError as A, BaseError as B, CannotTrackError as C, InvalidStorageSet as I, WalletProviderPriority as W, _extends as _, assertDefined as a, assignClient as b, createApiClient as c, dependencies as d, emitEvent as e, getClient as f, getCore as g, getWalletProviderFromWalletAccount as h, isEqualShallow as i, getWalletProviderRegistry as j, onceEvent as k, onEvent as l, hasExtension as m, ClientNotPresentError as n, offEvent as o, subscribeWithSelector as s, version as v };
538
+ export { APIError as A, BaseError as B, CannotTrackError as C, InvalidStorageSet as I, MfaInvalidOtpError as M, ValueMustBeDefinedError as V, WalletProviderPriority as W, _extends as _, assertDefined as a, assignClient as b, createApiClient as c, dependencies as d, emitEvent as e, getClient as f, getCore as g, getWalletProviderFromWalletAccount as h, isEqualShallow as i, getWalletProviderRegistry as j, MfaRateLimitedError as k, onceEvent as l, onEvent as m, hasExtension as n, offEvent as o, ClientNotPresentError as p, ClientsDoNotMatchError as q, subscribeWithSelector as s, version as v };