@dynamic-labs-sdk/client 0.1.0-alpha.19 → 0.1.0-alpha.20
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 +4 -0
- package/InvalidParamError.cjs.js +2 -2
- package/InvalidParamError.esm.js +1 -1
- package/NotWaasWalletAccountError.cjs.js +5 -5
- package/NotWaasWalletAccountError.esm.js +1 -1
- package/constants.cjs.js +483 -9
- package/constants.cjs2.js +15 -0
- package/constants.esm.js +458 -7
- package/constants.esm2.js +11 -0
- package/core.cjs.js +31 -27
- package/core.esm.js +5 -5
- package/getNetworkProviderFromNetworkId.cjs.js +109 -22
- package/getNetworkProviderFromNetworkId.esm.js +87 -4
- package/getSignedSessionId.cjs.js +6 -6
- package/getSignedSessionId.esm.js +1 -1
- package/getWalletProviderByKey.cjs.js +28 -25
- package/getWalletProviderByKey.esm.js +4 -2
- package/index.cjs.js +273 -284
- package/index.esm.js +87 -98
- package/isMfaRequiredForAction.cjs.js +8 -8
- package/isMfaRequiredForAction.esm.js +1 -1
- package/package.json +2 -2
- package/src/constants.d.ts +1 -0
- package/src/constants.d.ts.map +1 -1
- package/src/exports/core.d.ts +9 -1
- package/src/exports/core.d.ts.map +1 -1
- package/src/exports/index.d.ts +2 -2
- package/src/exports/index.d.ts.map +1 -1
- package/src/modules/auth/passkeys/getPasskeyAuthenticationOptions/getPasskeyAuthenticationOptions.d.ts +4 -1
- package/src/modules/auth/passkeys/getPasskeyAuthenticationOptions/getPasskeyAuthenticationOptions.d.ts.map +1 -1
- package/src/modules/auth/passkeys/getPasskeyAuthenticationSignInOptions/getPasskeyAuthenticationSignInOptions.d.ts +4 -1
- package/src/modules/auth/passkeys/getPasskeyAuthenticationSignInOptions/getPasskeyAuthenticationSignInOptions.d.ts.map +1 -1
- package/src/modules/auth/passkeys/signInWithPasskey/signInWithPasskey.d.ts +4 -1
- package/src/modules/auth/passkeys/signInWithPasskey/signInWithPasskey.d.ts.map +1 -1
- package/src/modules/mfa/authenticatePasskeyMFA/authenticatePasskeyMFA.d.ts +2 -1
- package/src/modules/mfa/authenticatePasskeyMFA/authenticatePasskeyMFA.d.ts.map +1 -1
- package/src/modules/storageSync/schema.d.ts +5 -0
- package/src/modules/storageSync/schema.d.ts.map +1 -1
- package/src/modules/waas/constants.d.ts.map +1 -1
- package/src/modules/wallets/connectWithWalletProvider/connectWithWalletProvider.d.ts.map +1 -1
- package/src/modules/wallets/proveWalletAccountOwnership/proveWalletAccountOwnership.d.ts +1 -1
- package/src/modules/wallets/proveWalletAccountOwnership/proveWalletAccountOwnership.d.ts.map +1 -1
- package/src/modules/wallets/unverifiedWalletAccounts/removeUnverifiedWalletAccount/removeUnverifiedWalletAccount.d.ts.map +1 -1
- package/src/modules/wallets/unverifiedWalletAccounts/schema.d.ts +5 -0
- package/src/modules/wallets/unverifiedWalletAccounts/schema.d.ts.map +1 -1
- package/src/modules/wallets/utils/convertUnverifiedWalletAccountToWalletAccount/convertUnverifiedWalletAccountToWalletAccount.d.ts.map +1 -1
- package/src/modules/wallets/utils/convertVerifiedCredentialToWalletAccount/convertVerifiedCredentialToWalletAccount.d.ts.map +1 -1
- package/src/modules/wallets/utils/formatSignInMessage/formatSignInMessage.d.ts +9 -7
- package/src/modules/wallets/utils/formatSignInMessage/formatSignInMessage.d.ts.map +1 -1
- package/src/modules/wallets/utils/getAddressesWithTypesFromConnectionResult/getAddressesWithTypesFromConnectionResult.d.ts +4 -0
- package/src/modules/wallets/utils/getAddressesWithTypesFromConnectionResult/getAddressesWithTypesFromConnectionResult.d.ts.map +1 -0
- package/src/modules/wallets/utils/getAddressesWithTypesFromConnectionResult/index.d.ts +2 -0
- package/src/modules/wallets/utils/getAddressesWithTypesFromConnectionResult/index.d.ts.map +1 -0
- package/src/modules/wallets/utils/getChainIdForAccountVerification/getChainIdForAccountVerification.d.ts.map +1 -1
- package/src/modules/wallets/utils/getSignInMessage/createSignInMessageStatement/createSignInMessageStatement.d.ts +3 -0
- package/src/modules/wallets/utils/getSignInMessage/createSignInMessageStatement/createSignInMessageStatement.d.ts.map +1 -0
- package/src/modules/wallets/utils/getSignInMessage/createSignInMessageStatement/index.d.ts +2 -0
- package/src/modules/wallets/utils/getSignInMessage/createSignInMessageStatement/index.d.ts.map +1 -0
- package/src/modules/wallets/utils/getSignInMessage/getSignInMessage.d.ts.map +1 -1
- package/src/modules/wallets/verifySignInMessage/index.d.ts +2 -0
- package/src/modules/wallets/verifySignInMessage/index.d.ts.map +1 -0
- package/src/modules/wallets/verifySignInMessage/verifySignInMessage.d.ts +22 -0
- package/src/modules/wallets/verifySignInMessage/verifySignInMessage.d.ts.map +1 -0
- package/src/modules/wallets/verifyWalletAccount/verifyWalletAccount.d.ts.map +1 -1
- package/src/modules/wallets/walletAccount/index.d.ts +1 -1
- package/src/modules/wallets/walletAccount/index.d.ts.map +1 -1
- package/src/modules/wallets/walletAccount/walletAccount.types.d.ts +8 -0
- package/src/modules/wallets/walletAccount/walletAccount.types.d.ts.map +1 -1
- package/src/modules/wallets/walletProvider/index.d.ts +1 -1
- package/src/modules/wallets/walletProvider/index.d.ts.map +1 -1
- package/src/modules/wallets/walletProvider/walletProvider.types.d.ts +10 -4
- package/src/modules/wallets/walletProvider/walletProvider.types.d.ts.map +1 -1
- package/src/modules/wallets/walletProvider/walletProviderKeyMap/updateWalletProviderKeysForVerifiedCredentials/index.d.ts +2 -0
- package/src/modules/wallets/walletProvider/walletProviderKeyMap/updateWalletProviderKeysForVerifiedCredentials/index.d.ts.map +1 -0
- package/src/modules/wallets/walletProvider/walletProviderKeyMap/updateWalletProviderKeysForVerifiedCredentials/updateWalletProviderKeysForVerifiedCredentials.d.ts +7 -0
- package/src/modules/wallets/walletProvider/walletProviderKeyMap/updateWalletProviderKeysForVerifiedCredentials/updateWalletProviderKeysForVerifiedCredentials.d.ts.map +1 -0
- package/waas.cjs.js +23 -23
- package/waas.esm.js +2 -2
- package/waasCore.cjs.js +9 -9
- package/waasCore.esm.js +2 -2
- package/getChainFromVerifiedCredentialChain.cjs.js +0 -483
- package/getChainFromVerifiedCredentialChain.esm.js +0 -457
package/CHANGELOG.md
CHANGED
package/InvalidParamError.cjs.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var constants = require('./constants.cjs.js');
|
|
4
4
|
|
|
5
|
-
class InvalidParamError extends
|
|
5
|
+
class InvalidParamError extends constants.BaseError {
|
|
6
6
|
constructor(message){
|
|
7
7
|
super({
|
|
8
8
|
cause: null,
|
package/InvalidParamError.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var constants = require('./constants.cjs.js');
|
|
4
4
|
var getWalletProviderByKey = require('./getWalletProviderByKey.cjs.js');
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -11,9 +11,9 @@ var getWalletProviderByKey = require('./getWalletProviderByKey.cjs.js');
|
|
|
11
11
|
*
|
|
12
12
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
13
13
|
* @returns A promise that resolves when the user data is refreshed.
|
|
14
|
-
*/ const refreshUser = async (client =
|
|
15
|
-
const core =
|
|
16
|
-
const apiClient =
|
|
14
|
+
*/ const refreshUser = async (client = constants.getDefaultClient())=>{
|
|
15
|
+
const core = constants.getCore(client);
|
|
16
|
+
const apiClient = constants.createApiClient({}, client);
|
|
17
17
|
const response = await apiClient.refreshAuth({
|
|
18
18
|
environmentId: core.environmentId
|
|
19
19
|
});
|
|
@@ -22,7 +22,7 @@ var getWalletProviderByKey = require('./getWalletProviderByKey.cjs.js');
|
|
|
22
22
|
}, client);
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
class NotWaasWalletAccountError extends
|
|
25
|
+
class NotWaasWalletAccountError extends constants.BaseError {
|
|
26
26
|
constructor({ walletAddress }){
|
|
27
27
|
super({
|
|
28
28
|
cause: null,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as getDefaultClient, a as getCore, c as createApiClient, B as BaseError } from './
|
|
1
|
+
import { g as getDefaultClient, a as getCore, c as createApiClient, B as BaseError } from './constants.esm.js';
|
|
2
2
|
import { u as updateAuthFromVerifyResponse } from './getWalletProviderByKey.esm.js';
|
|
3
3
|
|
|
4
4
|
/**
|
package/constants.cjs.js
CHANGED
|
@@ -1,13 +1,487 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
4
|
+
var buffer = require('buffer');
|
|
5
|
+
|
|
6
|
+
var name = "@dynamic-labs-sdk/client";
|
|
7
|
+
var version = "0.1.0-alpha.20";
|
|
8
|
+
var dependencies = {
|
|
9
|
+
"@dynamic-labs/sdk-api-core": "0.0.805"};
|
|
10
|
+
|
|
11
|
+
const getCore = (client)=>{
|
|
12
|
+
// @ts-expect-error - this was hidden from the public API
|
|
13
|
+
return client.__core;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function _extends() {
|
|
17
|
+
_extends = Object.assign || function assign(target) {
|
|
18
|
+
for(var i = 1; i < arguments.length; i++){
|
|
19
|
+
var source = arguments[i];
|
|
20
|
+
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
21
|
+
}
|
|
22
|
+
return target;
|
|
23
|
+
};
|
|
24
|
+
return _extends.apply(this, arguments);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const getDetails = ({ details, cause })=>{
|
|
28
|
+
if (cause instanceof BaseError) {
|
|
29
|
+
return cause.details;
|
|
30
|
+
}
|
|
31
|
+
if (cause == null ? void 0 : cause.message) {
|
|
32
|
+
return cause.message;
|
|
33
|
+
}
|
|
34
|
+
return details;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Formats the error message with all available information
|
|
38
|
+
*/ const formatMessage = ({ shortMessage, details, docsUrl, metaMessages })=>{
|
|
39
|
+
return [
|
|
40
|
+
shortMessage,
|
|
41
|
+
'',
|
|
42
|
+
...metaMessages ? [
|
|
43
|
+
...metaMessages,
|
|
44
|
+
''
|
|
45
|
+
] : [],
|
|
46
|
+
...docsUrl ? [
|
|
47
|
+
`Docs: ${docsUrl}`
|
|
48
|
+
] : [],
|
|
49
|
+
...details ? [
|
|
50
|
+
`Details: ${details}`
|
|
51
|
+
] : [],
|
|
52
|
+
`Version: ${version}`,
|
|
53
|
+
`Timestamp: ${new Date().toISOString()}`
|
|
54
|
+
].join('\n');
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Base error class that provides structured error handling with detailed information
|
|
58
|
+
*/ class BaseError extends Error {
|
|
59
|
+
/**
|
|
60
|
+
* Walks the cause chain of the error and returns the root error
|
|
61
|
+
*/ walk() {
|
|
62
|
+
const cause = this.cause;
|
|
63
|
+
if (cause instanceof BaseError) {
|
|
64
|
+
return cause.walk();
|
|
65
|
+
}
|
|
66
|
+
return cause;
|
|
67
|
+
}
|
|
68
|
+
toString() {
|
|
69
|
+
return this.formattedMessage;
|
|
70
|
+
}
|
|
71
|
+
constructor(args){
|
|
72
|
+
const details = getDetails(args);
|
|
73
|
+
const formattedMessage = formatMessage(_extends({}, args, {
|
|
74
|
+
details
|
|
75
|
+
}));
|
|
76
|
+
var _args_shortMessage;
|
|
77
|
+
super((_args_shortMessage = args.shortMessage) != null ? _args_shortMessage : formattedMessage, args.cause ? {
|
|
78
|
+
cause: args.cause
|
|
79
|
+
} : undefined);
|
|
80
|
+
this.name = 'BaseError';
|
|
81
|
+
this.formattedMessage = formattedMessage;
|
|
82
|
+
this.details = details;
|
|
83
|
+
var _args_name;
|
|
84
|
+
this.name = (_args_name = args.name) != null ? _args_name : this.name;
|
|
85
|
+
var _args_cause;
|
|
86
|
+
this.cause = (_args_cause = args.cause) != null ? _args_cause : this.cause;
|
|
87
|
+
this.code = args.code;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
class ClientNotFoundError extends BaseError {
|
|
92
|
+
constructor(){
|
|
93
|
+
super({
|
|
94
|
+
cause: null,
|
|
95
|
+
code: 'client_not_found_error',
|
|
96
|
+
docsUrl: null,
|
|
97
|
+
name: 'ClientNotFoundError',
|
|
98
|
+
shortMessage: 'No Dynamic client has been created yet. Make sure you have called createDynamicClient() first.'
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let defaultClient = null;
|
|
104
|
+
let numOfInitializedClients = 0;
|
|
105
|
+
/**
|
|
106
|
+
* Returns the DynamicClient instance that was initialized with createDynamicClient.
|
|
107
|
+
*
|
|
108
|
+
* If more than one instance of DynamicClient was initialized, you should not use this function.
|
|
109
|
+
* Instead, you should pass the client instance you stored to the function that needs it.
|
|
110
|
+
*/ const getDefaultClient = ()=>{
|
|
111
|
+
if (!defaultClient) {
|
|
112
|
+
throw new ClientNotFoundError();
|
|
113
|
+
}
|
|
114
|
+
if (numOfInitializedClients > 1) {
|
|
115
|
+
const core = getCore(defaultClient);
|
|
116
|
+
core.logger.debug('Multiple instances of DynamicClient found. If you are only using one client (recommended), make sure you are not calling ' + '"createDynamicClient" multiple times. If you are using multiple clients, make sure you are passing which client to use as ' + 'the last param of all Dynamic functions.');
|
|
117
|
+
}
|
|
118
|
+
return defaultClient;
|
|
9
119
|
};
|
|
120
|
+
const setDefaultClient = (client)=>{
|
|
121
|
+
defaultClient = client;
|
|
122
|
+
numOfInitializedClients++;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const DYNAMIC_API_VERSION_HEADER = 'x-dyn-api-version';
|
|
126
|
+
const DYNAMIC_REQUEST_ID_HEADER = 'x-dyn-request-id';
|
|
127
|
+
const DYNAMIC_SDK_VERSION_HEADER = 'x-dyn-version';
|
|
128
|
+
const MFA_TOKEN_HEADER = 'x-mfa-auth-token';
|
|
129
|
+
const SESSION_PUBLIC_KEY_HEADER = 'x-dyn-session-public-key';
|
|
130
|
+
const DYNAMIC_SDK_API_VERSION = dependencies['@dynamic-labs/sdk-api-core'];
|
|
131
|
+
const CLIENT_SDK_NAME = 'ClientSDK';
|
|
132
|
+
|
|
133
|
+
const randomString = (length)=>{
|
|
134
|
+
const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
135
|
+
let result = '';
|
|
136
|
+
for(let i = length; i > 0; --i){
|
|
137
|
+
result += CHARS[Math.floor(Math.random() * CHARS.length)];
|
|
138
|
+
}
|
|
139
|
+
return result;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
class ValueMustBeDefinedError extends BaseError {
|
|
143
|
+
constructor(message){
|
|
144
|
+
super({
|
|
145
|
+
cause: null,
|
|
146
|
+
code: 'value_must_be_defined_error',
|
|
147
|
+
docsUrl: null,
|
|
148
|
+
name: 'ValueMustBeDefined',
|
|
149
|
+
shortMessage: message
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Asserts that a value is not null or undefined, throwing an error if it is.
|
|
156
|
+
* This function acts as a type guard, narrowing the type to exclude null and undefined.
|
|
157
|
+
*
|
|
158
|
+
* @template T - The type of the value being checked
|
|
159
|
+
* @param value - The value to check for null or undefined
|
|
160
|
+
* @param message - The error message to throw if the value is null or undefined
|
|
161
|
+
* @throws Throws an error with the provided message if value is null or undefined
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const maybeString: string | null = getValue();
|
|
165
|
+
* assertDefined(maybeString, 'String value is required');
|
|
166
|
+
* // maybeString is now typed as string (null is excluded)
|
|
167
|
+
* ```
|
|
168
|
+
*/ function assertDefined(value, message) {
|
|
169
|
+
if (value === null || value === undefined) {
|
|
170
|
+
throw new ValueMustBeDefinedError(message);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Returns true if the client is using Dynamic cookies or a BYO JWT cookie.
|
|
176
|
+
*/ const isCookieEnabled = (client)=>{
|
|
177
|
+
var _securitySettings_auth, _securitySettings_externalAuth;
|
|
178
|
+
assertDefined(client.projectSettings, 'Project settings are not defined');
|
|
179
|
+
const securitySettings = client.projectSettings.security;
|
|
180
|
+
if (!securitySettings) return false;
|
|
181
|
+
// client uses Dynamic cookies
|
|
182
|
+
const dynamicCookiesEnabled = (((_securitySettings_auth = securitySettings.auth) == null ? void 0 : _securitySettings_auth.storage) || []).includes(sdkApiCore.AuthStorageEnum.Cookie);
|
|
183
|
+
// BYO JWT client puts their non-Dynamic JWT in a cookie
|
|
184
|
+
const byoJwtCookieEnabled = Boolean((_securitySettings_externalAuth = securitySettings.externalAuth) == null ? void 0 : _securitySettings_externalAuth.cookieName);
|
|
185
|
+
// should return true for both of these scenarios
|
|
186
|
+
// because we also need to do `credentials: true` in api.ts when
|
|
187
|
+
// a byo jwt client sets their named cookie for their jwt and
|
|
188
|
+
// needs to send it to our backend
|
|
189
|
+
return dynamicCookiesEnabled || byoJwtCookieEnabled;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const getBuffer = ()=>typeof Buffer !== 'undefined' ? Buffer : buffer.Buffer;
|
|
193
|
+
|
|
194
|
+
const getSessionKeys = (client)=>{
|
|
195
|
+
const core = getCore(client);
|
|
196
|
+
const encodedKeys = core.state.get().sessionKeys;
|
|
197
|
+
if (!encodedKeys) {
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
try {
|
|
201
|
+
const decodedKeys = JSON.parse(getBuffer().from(encodedKeys, 'base64').toString());
|
|
202
|
+
return decodedKeys;
|
|
203
|
+
} catch (error) {
|
|
204
|
+
core.logger.error('Error decoding session keys', error);
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
class APIError extends BaseError {
|
|
210
|
+
static async fromResponse(response) {
|
|
211
|
+
const errorBody = await response.json();
|
|
212
|
+
if ('code' in errorBody && typeof errorBody.code === 'string' && 'error' in errorBody && typeof errorBody.error === 'string') {
|
|
213
|
+
return new APIError(errorBody.error, errorBody.code);
|
|
214
|
+
}
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
constructor(message, code){
|
|
218
|
+
super({
|
|
219
|
+
cause: null,
|
|
220
|
+
code,
|
|
221
|
+
docsUrl: null,
|
|
222
|
+
name: 'APIError',
|
|
223
|
+
shortMessage: message
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
class InvalidExternalAuthError extends BaseError {
|
|
229
|
+
constructor({ cause }){
|
|
230
|
+
super({
|
|
231
|
+
cause,
|
|
232
|
+
code: 'invalid_external_auth_error',
|
|
233
|
+
docsUrl: 'https://www.dynamic.xyz/docs/external-auth/third-party-auth-overview',
|
|
234
|
+
name: 'InvalidExternalAuthError',
|
|
235
|
+
shortMessage: 'Error authenticating with external JWT'
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
class MfaInvalidOtpError extends BaseError {
|
|
241
|
+
constructor({ cause }){
|
|
242
|
+
super({
|
|
243
|
+
cause,
|
|
244
|
+
code: 'mfa_invalid_otp_error',
|
|
245
|
+
docsUrl: null,
|
|
246
|
+
name: 'MfaInvalidOtpError',
|
|
247
|
+
shortMessage: 'Invalid OTP'
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
class MfaRateLimitedError extends BaseError {
|
|
253
|
+
constructor({ cause }){
|
|
254
|
+
super({
|
|
255
|
+
cause,
|
|
256
|
+
code: 'mfa_rate_limited_error',
|
|
257
|
+
docsUrl: null,
|
|
258
|
+
name: 'MfaRateLimitedError',
|
|
259
|
+
shortMessage: 'Rate limited'
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
class SandboxMaximumThresholdReachedError extends BaseError {
|
|
265
|
+
constructor({ cause }){
|
|
266
|
+
super({
|
|
267
|
+
cause,
|
|
268
|
+
code: 'sandbox_maximum_threshold_reached_error',
|
|
269
|
+
docsUrl: 'https://www.dynamic.xyz/docs/developer-dashboard/sandbox-vs-live#sandbox-vs-live',
|
|
270
|
+
name: 'SandboxMaximumThresholdReachedError',
|
|
271
|
+
shortMessage: 'Your sandbox environment has reached the maximum MAU. Please use a live environment for production traffic.'
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Default error mapper for the client that handles common API error codes.
|
|
278
|
+
*
|
|
279
|
+
* This mapper transforms specific API error codes into more specific error types:
|
|
280
|
+
* - `mfa_invalid_code` → `MfaInvalidOtpError`
|
|
281
|
+
* - `mfa_rate_limited` → `MfaRateLimitedError`
|
|
282
|
+
*
|
|
283
|
+
* @param error - The error to be mapped
|
|
284
|
+
* @returns A transformed error if the error code matches a known pattern, or null if no transformation is needed
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```typescript
|
|
288
|
+
* // This will be automatically applied to all API errors
|
|
289
|
+
* const apiClient = createApiClient({}, client);
|
|
290
|
+
*
|
|
291
|
+
* // The clientErrorMapper will automatically convert mfa_invalid_code errors
|
|
292
|
+
* // to MfaInvalidOtpError instances
|
|
293
|
+
* ```
|
|
294
|
+
*/ const clientErrorMapper = (error)=>{
|
|
295
|
+
if (error instanceof APIError) {
|
|
296
|
+
if (error.code === 'mfa_invalid_code') {
|
|
297
|
+
return new MfaInvalidOtpError({
|
|
298
|
+
cause: error
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
if (error.code === 'mfa_rate_limited') {
|
|
302
|
+
return new MfaRateLimitedError({
|
|
303
|
+
cause: error
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
if (error.code === 'invalid_external_auth') {
|
|
307
|
+
return new InvalidExternalAuthError({
|
|
308
|
+
cause: error
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
if (error.code === 'sandbox_maximum_threshold_reached') {
|
|
312
|
+
return new SandboxMaximumThresholdReachedError({
|
|
313
|
+
cause: error
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return null;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Creates middleware that converts HTTP error responses to APIError instances
|
|
322
|
+
* and optionally applies custom error mappers to transform them into specific error types.
|
|
323
|
+
*
|
|
324
|
+
* @param options.errorMappers - Array of error mappers to apply to API errors
|
|
325
|
+
* @returns A middleware function that handles error conversion and mapping
|
|
326
|
+
*/ const createConvertToApiErrorMiddleware = ({ errorMappers = [] })=>({
|
|
327
|
+
post: async (context)=>{
|
|
328
|
+
if (context.response.status >= 400) {
|
|
329
|
+
const apiError = await APIError.fromResponse(context.response);
|
|
330
|
+
if (apiError) {
|
|
331
|
+
let errorToThrow = apiError;
|
|
332
|
+
for (const mapper of errorMappers){
|
|
333
|
+
const newError = mapper(apiError);
|
|
334
|
+
if (newError) {
|
|
335
|
+
errorToThrow = newError;
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
throw errorToThrow;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return context.response;
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Returns a new instance of the SDK API client.
|
|
348
|
+
*
|
|
349
|
+
* This is not meant for storing, as it is very light we can create it whenever needed.
|
|
350
|
+
*/ const createApiClient = (options = {}, client)=>{
|
|
351
|
+
var _getSessionKeys;
|
|
352
|
+
const core = getCore(client);
|
|
353
|
+
const coreState = core.state.get();
|
|
354
|
+
const settings = {
|
|
355
|
+
basePath: core.apiBaseUrl,
|
|
356
|
+
headers: _extends({
|
|
357
|
+
'Content-Type': 'application/json',
|
|
358
|
+
[DYNAMIC_API_VERSION_HEADER]: DYNAMIC_SDK_API_VERSION,
|
|
359
|
+
[DYNAMIC_REQUEST_ID_HEADER]: randomString(50),
|
|
360
|
+
[DYNAMIC_SDK_VERSION_HEADER]: `${CLIENT_SDK_NAME}/${version}`
|
|
361
|
+
}, core.getApiHeaders(), options.headers)
|
|
362
|
+
};
|
|
363
|
+
if (client.token) {
|
|
364
|
+
settings.headers.Authorization = `Bearer ${client.token}`;
|
|
365
|
+
}
|
|
366
|
+
if (client.projectSettings && isCookieEnabled(client)) {
|
|
367
|
+
settings.credentials = 'include';
|
|
368
|
+
}
|
|
369
|
+
if (options.includeMfaToken && coreState.mfaToken) {
|
|
370
|
+
settings.headers[MFA_TOKEN_HEADER] = coreState.mfaToken;
|
|
371
|
+
}
|
|
372
|
+
const sessionPublicKey = (_getSessionKeys = getSessionKeys(client)) == null ? void 0 : _getSessionKeys.publicKey;
|
|
373
|
+
// This check is required to avoid overriding the session public key header
|
|
374
|
+
// that is set by any of our other SDKs using the Dynamic Client SDK.
|
|
375
|
+
const isSessionPublicKeyHeaderPresent = settings.headers[SESSION_PUBLIC_KEY_HEADER] !== undefined;
|
|
376
|
+
if (sessionPublicKey && !isSessionPublicKeyHeaderPresent) {
|
|
377
|
+
settings.headers[SESSION_PUBLIC_KEY_HEADER] = sessionPublicKey;
|
|
378
|
+
}
|
|
379
|
+
return new sdkApiCore.SDKApi(new sdkApiCore.Configuration(_extends({}, settings, {
|
|
380
|
+
fetchApi: core.fetch,
|
|
381
|
+
middleware: [
|
|
382
|
+
createConvertToApiErrorMiddleware({
|
|
383
|
+
errorMappers: [
|
|
384
|
+
...options.errorMappers || [],
|
|
385
|
+
clientErrorMapper
|
|
386
|
+
]
|
|
387
|
+
})
|
|
388
|
+
]
|
|
389
|
+
})));
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
const CHAINS_INFO_MAP = {
|
|
393
|
+
ALGO: {
|
|
394
|
+
apiChainName: 'algo',
|
|
395
|
+
blockchainName: 'Algorand',
|
|
396
|
+
verifiedCredentialChainName: 'algorand'
|
|
397
|
+
},
|
|
398
|
+
APTOS: {
|
|
399
|
+
apiChainName: 'aptos',
|
|
400
|
+
blockchainName: 'Aptos',
|
|
401
|
+
verifiedCredentialChainName: 'aptos'
|
|
402
|
+
},
|
|
403
|
+
BTC: {
|
|
404
|
+
apiChainName: 'bitcoin',
|
|
405
|
+
blockchainName: 'Bitcoin',
|
|
406
|
+
verifiedCredentialChainName: 'bip122'
|
|
407
|
+
},
|
|
408
|
+
COSMOS: {
|
|
409
|
+
apiChainName: 'cosmos',
|
|
410
|
+
blockchainName: 'Cosmos',
|
|
411
|
+
verifiedCredentialChainName: 'cosmos'
|
|
412
|
+
},
|
|
413
|
+
EVM: {
|
|
414
|
+
apiChainName: 'evm',
|
|
415
|
+
// eslint-disable-next-line custom-rules/ban-ethereum-eth-terms
|
|
416
|
+
blockchainName: 'Ethereum',
|
|
417
|
+
verifiedCredentialChainName: 'eip155'
|
|
418
|
+
},
|
|
419
|
+
FLOW: {
|
|
420
|
+
apiChainName: 'flow',
|
|
421
|
+
blockchainName: 'Flow',
|
|
422
|
+
verifiedCredentialChainName: 'flow'
|
|
423
|
+
},
|
|
424
|
+
SOL: {
|
|
425
|
+
apiChainName: 'solana',
|
|
426
|
+
blockchainName: 'Solana',
|
|
427
|
+
verifiedCredentialChainName: 'solana',
|
|
428
|
+
waasChainNameOverride: 'SVM'
|
|
429
|
+
},
|
|
430
|
+
SPARK: {
|
|
431
|
+
apiChainName: 'spark',
|
|
432
|
+
blockchainName: 'Spark',
|
|
433
|
+
verifiedCredentialChainName: 'spark'
|
|
434
|
+
},
|
|
435
|
+
STARK: {
|
|
436
|
+
apiChainName: 'starknet',
|
|
437
|
+
blockchainName: 'Starknet',
|
|
438
|
+
verifiedCredentialChainName: 'starknet'
|
|
439
|
+
},
|
|
440
|
+
SUI: {
|
|
441
|
+
apiChainName: 'sui',
|
|
442
|
+
blockchainName: 'Sui',
|
|
443
|
+
verifiedCredentialChainName: 'sui'
|
|
444
|
+
},
|
|
445
|
+
TRON: {
|
|
446
|
+
apiChainName: 'tron',
|
|
447
|
+
blockchainName: 'Tron',
|
|
448
|
+
verifiedCredentialChainName: 'tron'
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
const getChainFromVerifiedCredentialChain = (verifiedCredentialChain)=>{
|
|
453
|
+
const chains = Object.keys(CHAINS_INFO_MAP);
|
|
454
|
+
const chain = chains.find((chain)=>CHAINS_INFO_MAP[chain].verifiedCredentialChainName === verifiedCredentialChain);
|
|
455
|
+
assertDefined(chain, `Unknown chain: ${verifiedCredentialChain}`);
|
|
456
|
+
return chain;
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
const SDK_API_CORE_VERSION = dependencies['@dynamic-labs/sdk-api-core'];
|
|
460
|
+
const DYNAMIC_ICONIC_SPRITE_URL = 'https://iconic.dynamic-static-assets.com/icons/sprite.svg';
|
|
10
461
|
|
|
11
|
-
exports.
|
|
12
|
-
exports.
|
|
13
|
-
exports.
|
|
462
|
+
exports.APIError = APIError;
|
|
463
|
+
exports.BaseError = BaseError;
|
|
464
|
+
exports.CHAINS_INFO_MAP = CHAINS_INFO_MAP;
|
|
465
|
+
exports.CLIENT_SDK_NAME = CLIENT_SDK_NAME;
|
|
466
|
+
exports.ClientNotFoundError = ClientNotFoundError;
|
|
467
|
+
exports.DYNAMIC_ICONIC_SPRITE_URL = DYNAMIC_ICONIC_SPRITE_URL;
|
|
468
|
+
exports.DYNAMIC_SDK_API_VERSION = DYNAMIC_SDK_API_VERSION;
|
|
469
|
+
exports.InvalidExternalAuthError = InvalidExternalAuthError;
|
|
470
|
+
exports.MfaInvalidOtpError = MfaInvalidOtpError;
|
|
471
|
+
exports.MfaRateLimitedError = MfaRateLimitedError;
|
|
472
|
+
exports.SDK_API_CORE_VERSION = SDK_API_CORE_VERSION;
|
|
473
|
+
exports.SandboxMaximumThresholdReachedError = SandboxMaximumThresholdReachedError;
|
|
474
|
+
exports.ValueMustBeDefinedError = ValueMustBeDefinedError;
|
|
475
|
+
exports._extends = _extends;
|
|
476
|
+
exports.assertDefined = assertDefined;
|
|
477
|
+
exports.createApiClient = createApiClient;
|
|
478
|
+
exports.getBuffer = getBuffer;
|
|
479
|
+
exports.getChainFromVerifiedCredentialChain = getChainFromVerifiedCredentialChain;
|
|
480
|
+
exports.getCore = getCore;
|
|
481
|
+
exports.getDefaultClient = getDefaultClient;
|
|
482
|
+
exports.getSessionKeys = getSessionKeys;
|
|
483
|
+
exports.isCookieEnabled = isCookieEnabled;
|
|
484
|
+
exports.name = name;
|
|
485
|
+
exports.randomString = randomString;
|
|
486
|
+
exports.setDefaultClient = setDefaultClient;
|
|
487
|
+
exports.version = version;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constants = require('./constants.cjs.js');
|
|
4
|
+
|
|
5
|
+
const DEFAULT_WAAS_BASE_API_URL = 'https://app.dynamicauth.com';
|
|
6
|
+
const DEFAULT_WAAS_BASE_MPC_RELAY_API_URL = 'https://relay.dynamicauth.com';
|
|
7
|
+
const DYNAMIC_WAAS_METADATA = {
|
|
8
|
+
displayName: 'Dynamic WaaS',
|
|
9
|
+
icon: `${constants.DYNAMIC_ICONIC_SPRITE_URL}#dynamicwaas`,
|
|
10
|
+
normalizedWalletName: 'dynamicwaas'
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
exports.DEFAULT_WAAS_BASE_API_URL = DEFAULT_WAAS_BASE_API_URL;
|
|
14
|
+
exports.DEFAULT_WAAS_BASE_MPC_RELAY_API_URL = DEFAULT_WAAS_BASE_MPC_RELAY_API_URL;
|
|
15
|
+
exports.DYNAMIC_WAAS_METADATA = DYNAMIC_WAAS_METADATA;
|