@dynamic-labs-sdk/client 0.0.1-alpha.6 → 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.
- package/CHANGELOG.md +11 -0
- package/core.cjs.js +4 -0
- package/core.esm.js +2 -1
- package/getWalletProviderFromWalletAccount.cjs.js +192 -64
- package/getWalletProviderFromWalletAccount.esm.js +188 -65
- package/index.cjs.js +243 -104
- package/index.esm.js +232 -107
- package/package.json +2 -2
- package/src/client/core/createCore/getInitialState.d.ts.map +1 -1
- package/src/errors/APIError/APIError.d.ts +6 -0
- package/src/errors/APIError/APIError.d.ts.map +1 -0
- package/src/errors/APIError/index.d.ts +2 -0
- package/src/errors/APIError/index.d.ts.map +1 -0
- package/src/errors/CannotTrackError.d.ts +5 -0
- package/src/errors/CannotTrackError.d.ts.map +1 -0
- package/src/errors/ClientAlreadyInitializedError.d.ts +5 -0
- package/src/errors/ClientAlreadyInitializedError.d.ts.map +1 -0
- package/src/errors/ClientNotPresentError.d.ts +5 -0
- package/src/errors/ClientNotPresentError.d.ts.map +1 -0
- package/src/errors/ClientsDoNotMatchError.d.ts +5 -0
- package/src/errors/ClientsDoNotMatchError.d.ts.map +1 -0
- package/src/errors/InvalidRedirectStorageStateError.d.ts +5 -0
- package/src/errors/InvalidRedirectStorageStateError.d.ts.map +1 -0
- package/src/{services/storage/createWebStorage/errors → errors}/InvalidStorageSet.d.ts +1 -1
- package/src/errors/InvalidStorageSet.d.ts.map +1 -0
- package/src/errors/MethodNotImplementedError.d.ts +1 -1
- package/src/errors/MethodNotImplementedError.d.ts.map +1 -1
- package/src/errors/MfaInvalidOtpError.d.ts +5 -0
- package/src/errors/MfaInvalidOtpError.d.ts.map +1 -0
- package/src/errors/MfaRateLimitedError.d.ts +5 -0
- package/src/errors/MfaRateLimitedError.d.ts.map +1 -0
- package/src/errors/MissingRedirectStorageStateError.d.ts +5 -0
- package/src/errors/MissingRedirectStorageStateError.d.ts.map +1 -0
- package/src/errors/MissingSocialUrlParamError.d.ts +5 -0
- package/src/errors/MissingSocialUrlParamError.d.ts.map +1 -0
- package/src/errors/NoAddressFoundError.d.ts +5 -0
- package/src/errors/NoAddressFoundError.d.ts.map +1 -0
- package/src/errors/NoPasskeyCredentialsFoundError.d.ts +5 -0
- package/src/errors/NoPasskeyCredentialsFoundError.d.ts.map +1 -0
- package/src/errors/NoWebAuthNSupportError.d.ts +5 -0
- package/src/errors/NoWebAuthNSupportError.d.ts.map +1 -0
- package/src/errors/UnavailableInServerSideError.d.ts +1 -1
- package/src/errors/UnavailableInServerSideError.d.ts.map +1 -1
- package/src/errors/UserNotAuthenticatedError.d.ts +5 -0
- package/src/errors/UserNotAuthenticatedError.d.ts.map +1 -0
- package/src/errors/ValueMustBeDefinedError.d.ts +5 -0
- package/src/errors/ValueMustBeDefinedError.d.ts.map +1 -0
- package/src/errors/WalletAccountAlreadyVerifiedError.d.ts +5 -0
- package/src/errors/WalletAccountAlreadyVerifiedError.d.ts.map +1 -0
- package/src/{modules/wallets/assertWalletAccountSigningAvailability/errors → errors}/WalletAccountNotSelectedError.d.ts +1 -1
- package/src/errors/WalletAccountNotSelectedError.d.ts.map +1 -0
- package/src/{modules/wallets/verifyWalletAccount/errors → errors}/WalletAlreadyLinkedToAnotherUserError.d.ts +1 -2
- package/src/errors/WalletAlreadyLinkedToAnotherUserError.d.ts.map +1 -0
- package/src/errors/base/BaseError.d.ts +6 -0
- package/src/errors/base/BaseError.d.ts.map +1 -1
- package/src/exports/core.d.ts +6 -3
- package/src/exports/core.d.ts.map +1 -1
- package/src/exports/index.d.ts +23 -6
- package/src/exports/index.d.ts.map +1 -1
- package/src/modules/apiClient/createApiClient.d.ts +2 -1
- package/src/modules/apiClient/createApiClient.d.ts.map +1 -1
- package/src/modules/apiClient/types.d.ts +35 -0
- package/src/modules/apiClient/types.d.ts.map +1 -0
- package/src/modules/apiClient/utils/clientErrorMapper/clientErrorMapper.d.ts +22 -0
- package/src/modules/apiClient/utils/clientErrorMapper/clientErrorMapper.d.ts.map +1 -0
- package/src/modules/apiClient/utils/clientErrorMapper/index.d.ts +2 -0
- package/src/modules/apiClient/utils/clientErrorMapper/index.d.ts.map +1 -0
- package/src/modules/apiClient/utils/convertToApiErrorMiddleware/convertToApiErrorMiddleware.d.ts +15 -0
- package/src/modules/apiClient/utils/convertToApiErrorMiddleware/convertToApiErrorMiddleware.d.ts.map +1 -0
- package/src/modules/apiClient/utils/convertToApiErrorMiddleware/index.d.ts +2 -0
- package/src/modules/apiClient/utils/convertToApiErrorMiddleware/index.d.ts.map +1 -0
- package/src/modules/auth/passkeys/getPasskeyAuthenticationOptions/getPasskeyAuthenticationOptions.d.ts +4 -0
- package/src/modules/auth/passkeys/getPasskeyAuthenticationOptions/getPasskeyAuthenticationOptions.d.ts.map +1 -0
- package/src/modules/auth/passkeys/getPasskeyAuthenticationOptions/index.d.ts +4 -0
- package/src/modules/auth/passkeys/getPasskeyAuthenticationOptions/index.d.ts.map +1 -0
- package/src/modules/auth/passkeys/serverAuthenticatePasskey/index.d.ts +2 -0
- package/src/modules/auth/passkeys/serverAuthenticatePasskey/index.d.ts.map +1 -0
- package/src/modules/auth/passkeys/serverAuthenticatePasskey/serverAuthenticatePasskey.d.ts +5 -0
- package/src/modules/auth/passkeys/serverAuthenticatePasskey/serverAuthenticatePasskey.d.ts.map +1 -0
- package/src/modules/auth/social/oauth/completeSocialRedirectSignIn/completeSocialRedirectSignIn.d.ts.map +1 -1
- package/src/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.d.ts.map +1 -1
- package/src/modules/mfa/authMfaRecoveryCode/authMfaRecoveryCode.d.ts +4 -1
- package/src/modules/mfa/authMfaRecoveryCode/authMfaRecoveryCode.d.ts.map +1 -1
- package/src/modules/mfa/authTotpMfaDevice/authTotpMfaDevice.d.ts +7 -2
- package/src/modules/mfa/authTotpMfaDevice/authTotpMfaDevice.d.ts.map +1 -1
- package/src/modules/mfa/authenticatePasskeyMFA/authenticatePasskeyMFA.d.ts +6 -0
- package/src/modules/mfa/authenticatePasskeyMFA/authenticatePasskeyMFA.d.ts.map +1 -0
- package/src/modules/mfa/authenticatePasskeyMFA/index.d.ts +2 -0
- package/src/modules/mfa/authenticatePasskeyMFA/index.d.ts.map +1 -0
- package/src/modules/mfa/consumeMfaToken/consumeMfaToken.d.ts +3 -0
- package/src/modules/mfa/consumeMfaToken/consumeMfaToken.d.ts.map +1 -0
- package/src/modules/mfa/consumeMfaToken/index.d.ts +2 -0
- package/src/modules/mfa/consumeMfaToken/index.d.ts.map +1 -0
- package/src/modules/mfa/createNewMfaRecoveryCodes/createNewMfaRecoveryCodes.d.ts +4 -1
- package/src/modules/mfa/createNewMfaRecoveryCodes/createNewMfaRecoveryCodes.d.ts.map +1 -1
- package/src/modules/mfa/getMfaRecoveryCodes/getMfaRecoveryCodes.d.ts +4 -1
- package/src/modules/mfa/getMfaRecoveryCodes/getMfaRecoveryCodes.d.ts.map +1 -1
- package/src/modules/mfa/isPendingRecoveryCodesAcknowledgment/index.d.ts +2 -0
- package/src/modules/mfa/isPendingRecoveryCodesAcknowledgment/index.d.ts.map +1 -0
- package/src/modules/mfa/isPendingRecoveryCodesAcknowledgment/isPendingRecoveryCodesAcknowledgment.d.ts +3 -0
- package/src/modules/mfa/isPendingRecoveryCodesAcknowledgment/isPendingRecoveryCodesAcknowledgment.d.ts.map +1 -0
- package/src/modules/mfa/isUserMissingMfaAuth/index.d.ts +2 -0
- package/src/modules/mfa/isUserMissingMfaAuth/index.d.ts.map +1 -0
- package/src/modules/mfa/isUserMissingMfaAuth/isUserMissingMfaAuth.d.ts +3 -0
- package/src/modules/mfa/isUserMissingMfaAuth/isUserMissingMfaAuth.d.ts.map +1 -0
- package/src/modules/mfa/registerTotpMfaDevice/registerTotpMfaDevice.d.ts.map +1 -1
- package/src/modules/mfa/state.d.ts +13 -0
- package/src/modules/mfa/state.d.ts.map +1 -0
- package/src/modules/storageSync/hydrateStateWithStorage/hydrateStateWithStorage.d.ts.map +1 -1
- package/src/modules/storageSync/schema.d.ts +1 -0
- package/src/modules/storageSync/schema.d.ts.map +1 -1
- package/src/modules/storageSync/syncStateWithStorage/syncStateWithStorage.d.ts.map +1 -1
- package/src/modules/wallets/verifyWalletAccount/verifyWalletAccount.d.ts.map +1 -1
- package/src/utils/retryOnFail/InvalidRetryOnFailCallError.d.ts.map +1 -1
- package/src/modules/auth/errors/UserNotAuthenticatedError.d.ts +0 -6
- package/src/modules/auth/errors/UserNotAuthenticatedError.d.ts.map +0 -1
- package/src/modules/auth/passkeys/errors/NoWebAuthNSupportError.d.ts +0 -5
- package/src/modules/auth/passkeys/errors/NoWebAuthNSupportError.d.ts.map +0 -1
- package/src/modules/auth/social/oauth/errors/InvalidRedirectStorageStateError/InvalidRedirectStorageStateError.d.ts +0 -5
- package/src/modules/auth/social/oauth/errors/InvalidRedirectStorageStateError/InvalidRedirectStorageStateError.d.ts.map +0 -1
- package/src/modules/auth/social/oauth/errors/InvalidRedirectStorageStateError/index.d.ts +0 -2
- package/src/modules/auth/social/oauth/errors/InvalidRedirectStorageStateError/index.d.ts.map +0 -1
- package/src/modules/auth/social/oauth/errors/MissingRedirectStorageStateError/MissingRedirectStorageStateError.d.ts +0 -5
- package/src/modules/auth/social/oauth/errors/MissingRedirectStorageStateError/MissingRedirectStorageStateError.d.ts.map +0 -1
- package/src/modules/auth/social/oauth/errors/MissingRedirectStorageStateError/index.d.ts +0 -2
- package/src/modules/auth/social/oauth/errors/MissingRedirectStorageStateError/index.d.ts.map +0 -1
- package/src/modules/auth/social/oauth/errors/MissingSocialUrlParamError/MissingSocialUrlParamError.d.ts +0 -5
- package/src/modules/auth/social/oauth/errors/MissingSocialUrlParamError/MissingSocialUrlParamError.d.ts.map +0 -1
- package/src/modules/auth/social/oauth/errors/MissingSocialUrlParamError/index.d.ts +0 -2
- package/src/modules/auth/social/oauth/errors/MissingSocialUrlParamError/index.d.ts.map +0 -1
- package/src/modules/initializeClient/errors/ClientAlreadyInitializedError.d.ts +0 -5
- package/src/modules/initializeClient/errors/ClientAlreadyInitializedError.d.ts.map +0 -1
- package/src/modules/wallets/assertWalletAccountSigningAvailability/errors/WalletAccountNotSelectedError.d.ts.map +0 -1
- package/src/modules/wallets/connectWithWalletProvider/errors/NoAddressFoundError.d.ts +0 -5
- package/src/modules/wallets/connectWithWalletProvider/errors/NoAddressFoundError.d.ts.map +0 -1
- package/src/modules/wallets/verifyWalletAccount/errors/WalletAccountAlreadyVerifiedError.d.ts +0 -5
- package/src/modules/wallets/verifyWalletAccount/errors/WalletAccountAlreadyVerifiedError.d.ts.map +0 -1
- package/src/modules/wallets/verifyWalletAccount/errors/WalletAlreadyLinkedToAnotherUserError.d.ts.map +0 -1
- package/src/services/asyncTrack/errors/CannotTrackError.d.ts +0 -5
- package/src/services/asyncTrack/errors/CannotTrackError.d.ts.map +0 -1
- package/src/services/storage/createWebStorage/errors/InvalidStorageSet.d.ts.map +0 -1
- package/src/utils/assertClientAreEqual/errors/ClientDoNotMatchError.d.ts +0 -5
- package/src/utils/assertClientAreEqual/errors/ClientDoNotMatchError.d.ts.map +0 -1
- package/src/utils/assertDefined/errors/ValueMustBeDefinedError.d.ts +0 -5
- package/src/utils/assertDefined/errors/ValueMustBeDefinedError.d.ts.map +0 -1
- package/src/utils/getClient/errors/ClientNotPresentError.d.ts +0 -5
- package/src/utils/getClient/errors/ClientNotPresentError.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
## 0.0.1-alpha.8 (2025-07-03)
|
|
2
|
+
|
|
3
|
+
This was a version bump only, there were no code changes.
|
|
4
|
+
|
|
5
|
+
## 0.0.1-alpha.7 (2025-07-02)
|
|
6
|
+
|
|
7
|
+
### 🩹 Fixes
|
|
8
|
+
|
|
9
|
+
- **mfa:** make device id optional ([#175](https://github.com/dynamic-labs/dynamic-sdk/pull/175))
|
|
10
|
+
- **mfa:** allow create mfa options to authTotpMfaDevice ([#178](https://github.com/dynamic-labs/dynamic-sdk/pull/178))
|
|
11
|
+
|
|
1
12
|
## 0.0.1-alpha.6 (2025-06-30)
|
|
2
13
|
|
|
3
14
|
### 🚀 Features
|
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,
|
|
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,66 +70,9 @@ function _extends() {
|
|
|
70
70
|
return _extends.apply(this, arguments);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
var version = "0.0.1-alpha.
|
|
73
|
+
var version = "0.0.1-alpha.8";
|
|
74
74
|
var dependencies = {
|
|
75
|
-
"@dynamic-labs/sdk-api-core": "0.0.
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Returns a new instance of the SDK API client.
|
|
79
|
-
*
|
|
80
|
-
* This is not meant for storing, as it is very light we can create it whenever needed.
|
|
81
|
-
*/ const createApiClient = (client)=>{
|
|
82
|
-
const core = getCore(client);
|
|
83
|
-
const settings = {
|
|
84
|
-
basePath: core.apiBaseUrl,
|
|
85
|
-
headers: {
|
|
86
|
-
'Content-Type': 'application/json',
|
|
87
|
-
'x-dyn-api-version': dependencies['@dynamic-labs/sdk-api-core'],
|
|
88
|
-
'x-dyn-version': core.version
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
if (client.token) {
|
|
92
|
-
settings.headers.Authorization = `Bearer ${client.token}`;
|
|
93
|
-
}
|
|
94
|
-
return new sdkApiCore.SDKApi(new sdkApiCore.Configuration(_extends({}, settings, {
|
|
95
|
-
fetchApi: core.fetch
|
|
96
|
-
})));
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Listen to an event from the client.
|
|
101
|
-
*
|
|
102
|
-
* @returns A function that can be called to remove the listener.
|
|
103
|
-
*/ const onEvent = (client, event, listener)=>{
|
|
104
|
-
const { eventEmitter } = getCore(client);
|
|
105
|
-
eventEmitter.on(event, listener);
|
|
106
|
-
return ()=>{
|
|
107
|
-
eventEmitter.off(event, listener);
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
|
-
/**
|
|
111
|
-
* Remove a listener from an event.
|
|
112
|
-
*/ const offEvent = (client, event, listener)=>{
|
|
113
|
-
const { eventEmitter } = getCore(client);
|
|
114
|
-
eventEmitter.off(event, listener);
|
|
115
|
-
};
|
|
116
|
-
/**
|
|
117
|
-
* Listen to an event that will only fire once.
|
|
118
|
-
*
|
|
119
|
-
* @returns A function that can be called to remove the listener.
|
|
120
|
-
*/ const onceEvent = (client, event, listener)=>{
|
|
121
|
-
const { eventEmitter } = getCore(client);
|
|
122
|
-
eventEmitter.once(event, listener);
|
|
123
|
-
return ()=>{
|
|
124
|
-
eventEmitter.off(event, listener);
|
|
125
|
-
};
|
|
126
|
-
};
|
|
127
|
-
/**
|
|
128
|
-
* Emit an event.
|
|
129
|
-
*/ const emitEvent = (client, event, ...args)=>{
|
|
130
|
-
const { eventEmitter } = getCore(client);
|
|
131
|
-
eventEmitter.emit(event, ...args);
|
|
132
|
-
};
|
|
75
|
+
"@dynamic-labs/sdk-api-core": "0.0.702"};
|
|
133
76
|
|
|
134
77
|
const getDetails = ({ details, cause })=>{
|
|
135
78
|
if (cause instanceof BaseError) {
|
|
@@ -172,26 +115,202 @@ const getDetails = ({ details, cause })=>{
|
|
|
172
115
|
}
|
|
173
116
|
return cause;
|
|
174
117
|
}
|
|
118
|
+
toString() {
|
|
119
|
+
return this.formattedMessage;
|
|
120
|
+
}
|
|
175
121
|
constructor(args){
|
|
176
122
|
const details = getDetails(args);
|
|
177
|
-
|
|
123
|
+
const formattedMessage = formatMessage(_extends({}, args, {
|
|
178
124
|
details
|
|
179
|
-
}))
|
|
125
|
+
}));
|
|
126
|
+
var _args_shortMessage;
|
|
127
|
+
super((_args_shortMessage = args.shortMessage) != null ? _args_shortMessage : formattedMessage, args.cause ? {
|
|
180
128
|
cause: args.cause
|
|
181
129
|
} : undefined);
|
|
182
130
|
this.name = 'BaseError';
|
|
131
|
+
this.formattedMessage = formattedMessage;
|
|
183
132
|
this.details = details;
|
|
184
133
|
var _args_name;
|
|
185
134
|
this.name = (_args_name = args.name) != null ? _args_name : this.name;
|
|
186
135
|
var _args_cause;
|
|
187
136
|
this.cause = (_args_cause = args.cause) != null ? _args_cause : this.cause;
|
|
137
|
+
this.code = args.code;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
class APIError extends BaseError {
|
|
142
|
+
static async fromResponse(response) {
|
|
143
|
+
const errorBody = await response.json();
|
|
144
|
+
if ('code' in errorBody && typeof errorBody.code === 'string' && 'error' in errorBody && typeof errorBody.error === 'string') {
|
|
145
|
+
return new APIError(errorBody.error, errorBody.code);
|
|
146
|
+
}
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
constructor(message, code){
|
|
150
|
+
super({
|
|
151
|
+
cause: null,
|
|
152
|
+
code,
|
|
153
|
+
docsUrl: null,
|
|
154
|
+
name: 'APIError',
|
|
155
|
+
shortMessage: message
|
|
156
|
+
});
|
|
188
157
|
}
|
|
189
158
|
}
|
|
190
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
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return null;
|
|
216
|
+
};
|
|
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
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Returns a new instance of the SDK API client.
|
|
246
|
+
*
|
|
247
|
+
* This is not meant for storing, as it is very light we can create it whenever needed.
|
|
248
|
+
*/ const createApiClient = (client, options = {})=>{
|
|
249
|
+
const core = getCore(client);
|
|
250
|
+
const settings = {
|
|
251
|
+
basePath: core.apiBaseUrl,
|
|
252
|
+
headers: {
|
|
253
|
+
'Content-Type': 'application/json',
|
|
254
|
+
'x-dyn-api-version': dependencies['@dynamic-labs/sdk-api-core'],
|
|
255
|
+
'x-dyn-version': core.version
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
if (client.token) {
|
|
259
|
+
settings.headers.Authorization = `Bearer ${client.token}`;
|
|
260
|
+
}
|
|
261
|
+
return new sdkApiCore.SDKApi(new sdkApiCore.Configuration(_extends({}, settings, {
|
|
262
|
+
fetchApi: core.fetch,
|
|
263
|
+
middleware: [
|
|
264
|
+
createConvertToApiErrorMiddleware({
|
|
265
|
+
errorMappers: [
|
|
266
|
+
...options.errorMappers || [],
|
|
267
|
+
clientErrorMapper
|
|
268
|
+
]
|
|
269
|
+
})
|
|
270
|
+
]
|
|
271
|
+
})));
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Listen to an event from the client.
|
|
276
|
+
*
|
|
277
|
+
* @returns A function that can be called to remove the listener.
|
|
278
|
+
*/ const onEvent = (client, event, listener)=>{
|
|
279
|
+
const { eventEmitter } = getCore(client);
|
|
280
|
+
eventEmitter.on(event, listener);
|
|
281
|
+
return ()=>{
|
|
282
|
+
eventEmitter.off(event, listener);
|
|
283
|
+
};
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* Remove a listener from an event.
|
|
287
|
+
*/ const offEvent = (client, event, listener)=>{
|
|
288
|
+
const { eventEmitter } = getCore(client);
|
|
289
|
+
eventEmitter.off(event, listener);
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* Listen to an event that will only fire once.
|
|
293
|
+
*
|
|
294
|
+
* @returns A function that can be called to remove the listener.
|
|
295
|
+
*/ const onceEvent = (client, event, listener)=>{
|
|
296
|
+
const { eventEmitter } = getCore(client);
|
|
297
|
+
eventEmitter.once(event, listener);
|
|
298
|
+
return ()=>{
|
|
299
|
+
eventEmitter.off(event, listener);
|
|
300
|
+
};
|
|
301
|
+
};
|
|
302
|
+
/**
|
|
303
|
+
* Emit an event.
|
|
304
|
+
*/ const emitEvent = (client, event, ...args)=>{
|
|
305
|
+
const { eventEmitter } = getCore(client);
|
|
306
|
+
eventEmitter.emit(event, ...args);
|
|
307
|
+
};
|
|
308
|
+
|
|
191
309
|
class ValueMustBeDefinedError extends BaseError {
|
|
192
310
|
constructor(message){
|
|
193
311
|
super({
|
|
194
312
|
cause: null,
|
|
313
|
+
code: 'value_must_be_defined_error',
|
|
195
314
|
docsUrl: null,
|
|
196
315
|
name: 'ValueMustBeDefined',
|
|
197
316
|
shortMessage: message
|
|
@@ -233,6 +352,7 @@ class ClientNotPresentError extends BaseError {
|
|
|
233
352
|
constructor(){
|
|
234
353
|
super({
|
|
235
354
|
cause: null,
|
|
355
|
+
code: 'client_not_present_error',
|
|
236
356
|
docsUrl: null,
|
|
237
357
|
name: 'ClientNotPresentError',
|
|
238
358
|
shortMessage: 'The client is not present in the target object.'
|
|
@@ -252,6 +372,7 @@ class InvalidStorageSet extends BaseError {
|
|
|
252
372
|
constructor({ key, value }){
|
|
253
373
|
super({
|
|
254
374
|
cause: null,
|
|
375
|
+
code: 'invalid_storage_set',
|
|
255
376
|
docsUrl: null,
|
|
256
377
|
metaMessages: [
|
|
257
378
|
`key: ${key}`,
|
|
@@ -267,6 +388,7 @@ class CannotTrackError extends BaseError {
|
|
|
267
388
|
constructor(){
|
|
268
389
|
super({
|
|
269
390
|
cause: null,
|
|
391
|
+
code: 'cannot_track_error',
|
|
270
392
|
docsUrl: null,
|
|
271
393
|
name: 'CannotTrackError',
|
|
272
394
|
shortMessage: 'All track calls must be performed in the same node tick'
|
|
@@ -300,12 +422,13 @@ class CannotTrackError extends BaseError {
|
|
|
300
422
|
return core.extensions.has(extensionKey);
|
|
301
423
|
};
|
|
302
424
|
|
|
303
|
-
class
|
|
425
|
+
class ClientsDoNotMatchError extends BaseError {
|
|
304
426
|
constructor(){
|
|
305
427
|
super({
|
|
306
428
|
cause: null,
|
|
429
|
+
code: 'clients_do_not_match_error',
|
|
307
430
|
docsUrl: null,
|
|
308
|
-
name: '
|
|
431
|
+
name: 'ClientsDoNotMatchError',
|
|
309
432
|
shortMessage: 'Clients do not match'
|
|
310
433
|
});
|
|
311
434
|
}
|
|
@@ -313,7 +436,7 @@ class ClientDoNotMatchError extends BaseError {
|
|
|
313
436
|
|
|
314
437
|
const assertClientAreEqual = (client1, client2)=>{
|
|
315
438
|
if (client1 !== client2) {
|
|
316
|
-
throw new
|
|
439
|
+
throw new ClientsDoNotMatchError();
|
|
317
440
|
}
|
|
318
441
|
};
|
|
319
442
|
|
|
@@ -414,10 +537,15 @@ const getWalletProviderFromWalletAccount = (walletAccount)=>{
|
|
|
414
537
|
return walletProvider;
|
|
415
538
|
};
|
|
416
539
|
|
|
540
|
+
exports.APIError = APIError;
|
|
417
541
|
exports.BaseError = BaseError;
|
|
418
542
|
exports.CannotTrackError = CannotTrackError;
|
|
419
543
|
exports.ClientNotPresentError = ClientNotPresentError;
|
|
544
|
+
exports.ClientsDoNotMatchError = ClientsDoNotMatchError;
|
|
420
545
|
exports.InvalidStorageSet = InvalidStorageSet;
|
|
546
|
+
exports.MfaInvalidOtpError = MfaInvalidOtpError;
|
|
547
|
+
exports.MfaRateLimitedError = MfaRateLimitedError;
|
|
548
|
+
exports.ValueMustBeDefinedError = ValueMustBeDefinedError;
|
|
421
549
|
exports._extends = _extends;
|
|
422
550
|
exports.assertDefined = assertDefined;
|
|
423
551
|
exports.assignClient = assignClient;
|