@dynamic-labs-sdk/client 0.0.1-alpha.11 → 0.0.1-alpha.13
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 +12 -0
- package/getWalletProviderFromWalletAccount.cjs.js +70 -36
- package/getWalletProviderFromWalletAccount.esm.js +71 -38
- package/index.cjs.js +12 -15
- package/index.esm.js +11 -14
- package/package.json +1 -1
- package/src/client/core/createCore/createCore.d.ts.map +1 -1
- package/src/client/core/types/DynamicCore.d.ts +4 -0
- package/src/client/core/types/DynamicCore.d.ts.map +1 -1
- package/src/client/core/types/DynamicCoreConfig.d.ts +1 -1
- package/src/client/core/types/DynamicCoreConfig.d.ts.map +1 -1
- package/src/modules/apiClient/createApiClient.d.ts.map +1 -1
- package/src/modules/auth/logout/logout.d.ts.map +1 -1
- package/src/modules/projectSettings/isCookieEnabled/index.d.ts +2 -0
- package/src/modules/projectSettings/isCookieEnabled/index.d.ts.map +1 -0
- package/src/modules/projectSettings/isCookieEnabled/isCookieEnabled.d.ts +6 -0
- package/src/modules/projectSettings/isCookieEnabled/isCookieEnabled.d.ts.map +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## 0.0.1-alpha.13 (2025-07-09)
|
|
2
|
+
|
|
3
|
+
### 🩹 Fixes
|
|
4
|
+
|
|
5
|
+
- convert api headers to get api headers ([#211](https://github.com/dynamic-labs/dynamic-sdk/pull/211))
|
|
6
|
+
|
|
7
|
+
## 0.0.1-alpha.12 (2025-07-09)
|
|
8
|
+
|
|
9
|
+
### 🩹 Fixes
|
|
10
|
+
|
|
11
|
+
- allow the api call to include cookie credentials ([#209](https://github.com/dynamic-labs/dynamic-sdk/pull/209))
|
|
12
|
+
|
|
1
13
|
## 0.0.1-alpha.11 (2025-07-08)
|
|
2
14
|
|
|
3
15
|
This was a version bump only, there were no code changes.
|
|
@@ -70,10 +70,19 @@ 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.13";
|
|
74
74
|
var dependencies = {
|
|
75
75
|
"@dynamic-labs/sdk-api-core": "0.0.702"};
|
|
76
76
|
|
|
77
|
+
const randomString = (length)=>{
|
|
78
|
+
const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
79
|
+
let result = '';
|
|
80
|
+
for(let i = length; i > 0; --i){
|
|
81
|
+
result += CHARS[Math.floor(Math.random() * CHARS.length)];
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
};
|
|
85
|
+
|
|
77
86
|
const getDetails = ({ details, cause })=>{
|
|
78
87
|
if (cause instanceof BaseError) {
|
|
79
88
|
return cause.details;
|
|
@@ -138,6 +147,56 @@ const getDetails = ({ details, cause })=>{
|
|
|
138
147
|
}
|
|
139
148
|
}
|
|
140
149
|
|
|
150
|
+
class ValueMustBeDefinedError extends BaseError {
|
|
151
|
+
constructor(message){
|
|
152
|
+
super({
|
|
153
|
+
cause: null,
|
|
154
|
+
code: 'value_must_be_defined_error',
|
|
155
|
+
docsUrl: null,
|
|
156
|
+
name: 'ValueMustBeDefined',
|
|
157
|
+
shortMessage: message
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Asserts that a value is not null or undefined, throwing an error if it is.
|
|
164
|
+
* This function acts as a type guard, narrowing the type to exclude null and undefined.
|
|
165
|
+
*
|
|
166
|
+
* @template T - The type of the value being checked
|
|
167
|
+
* @param value - The value to check for null or undefined
|
|
168
|
+
* @param message - The error message to throw if the value is null or undefined
|
|
169
|
+
* @throws Throws an error with the provided message if value is null or undefined
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* const maybeString: string | null = getValue();
|
|
173
|
+
* assertDefined(maybeString, 'String value is required');
|
|
174
|
+
* // maybeString is now typed as string (null is excluded)
|
|
175
|
+
* ```
|
|
176
|
+
*/ function assertDefined(value, message) {
|
|
177
|
+
if (value === null || value === undefined) {
|
|
178
|
+
throw new ValueMustBeDefinedError(message);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Returns true if the client is using Dynamic cookies or a BYO JWT cookie.
|
|
184
|
+
*/ const isCookieEnabled = (client)=>{
|
|
185
|
+
var _securitySettings_auth, _securitySettings_externalAuth;
|
|
186
|
+
assertDefined(client.projectSettings, 'Project settings are not defined');
|
|
187
|
+
const securitySettings = client.projectSettings.security;
|
|
188
|
+
if (!securitySettings) return false;
|
|
189
|
+
// client uses Dynamic cookies
|
|
190
|
+
const dynamicCookiesEnabled = (((_securitySettings_auth = securitySettings.auth) == null ? void 0 : _securitySettings_auth.storage) || []).includes(sdkApiCore.AuthStorageEnum.Cookie);
|
|
191
|
+
// BYO JWT client puts their non-Dynamic JWT in a cookie
|
|
192
|
+
const byoJwtCookieEnabled = Boolean((_securitySettings_externalAuth = securitySettings.externalAuth) == null ? void 0 : _securitySettings_externalAuth.cookieName);
|
|
193
|
+
// should return true for both of these scenarios
|
|
194
|
+
// because we also need to do `credentials: true` in api.ts when
|
|
195
|
+
// a byo jwt client sets their named cookie for their jwt and
|
|
196
|
+
// needs to send it to our backend
|
|
197
|
+
return dynamicCookiesEnabled || byoJwtCookieEnabled;
|
|
198
|
+
};
|
|
199
|
+
|
|
141
200
|
class APIError extends BaseError {
|
|
142
201
|
static async fromResponse(response) {
|
|
143
202
|
const errorBody = await response.json();
|
|
@@ -249,15 +308,21 @@ class MfaRateLimitedError extends BaseError {
|
|
|
249
308
|
const core = getCore(client);
|
|
250
309
|
const settings = {
|
|
251
310
|
basePath: core.apiBaseUrl,
|
|
252
|
-
headers: {
|
|
311
|
+
headers: _extends({
|
|
253
312
|
'Content-Type': 'application/json',
|
|
254
313
|
'x-dyn-api-version': dependencies['@dynamic-labs/sdk-api-core'],
|
|
255
|
-
'x-dyn-
|
|
256
|
-
|
|
314
|
+
'x-dyn-request-id': randomString(50),
|
|
315
|
+
/**
|
|
316
|
+
* Ticket revise API version
|
|
317
|
+
*/ 'x-dyn-version': 'WalletKit/4.22.5'
|
|
318
|
+
}, core.getApiHeaders())
|
|
257
319
|
};
|
|
258
320
|
if (client.token) {
|
|
259
321
|
settings.headers.Authorization = `Bearer ${client.token}`;
|
|
260
322
|
}
|
|
323
|
+
if (client.projectSettings && isCookieEnabled(client)) {
|
|
324
|
+
settings.credentials = 'include';
|
|
325
|
+
}
|
|
261
326
|
return new sdkApiCore.SDKApi(new sdkApiCore.Configuration(_extends({}, settings, {
|
|
262
327
|
fetchApi: core.fetch,
|
|
263
328
|
middleware: [
|
|
@@ -306,38 +371,6 @@ class MfaRateLimitedError extends BaseError {
|
|
|
306
371
|
eventEmitter.emit(event, ...args);
|
|
307
372
|
};
|
|
308
373
|
|
|
309
|
-
class ValueMustBeDefinedError extends BaseError {
|
|
310
|
-
constructor(message){
|
|
311
|
-
super({
|
|
312
|
-
cause: null,
|
|
313
|
-
code: 'value_must_be_defined_error',
|
|
314
|
-
docsUrl: null,
|
|
315
|
-
name: 'ValueMustBeDefined',
|
|
316
|
-
shortMessage: message
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* Asserts that a value is not null or undefined, throwing an error if it is.
|
|
323
|
-
* This function acts as a type guard, narrowing the type to exclude null and undefined.
|
|
324
|
-
*
|
|
325
|
-
* @template T - The type of the value being checked
|
|
326
|
-
* @param value - The value to check for null or undefined
|
|
327
|
-
* @param message - The error message to throw if the value is null or undefined
|
|
328
|
-
* @throws Throws an error with the provided message if value is null or undefined
|
|
329
|
-
* @example
|
|
330
|
-
* ```typescript
|
|
331
|
-
* const maybeString: string | null = getValue();
|
|
332
|
-
* assertDefined(maybeString, 'String value is required');
|
|
333
|
-
* // maybeString is now typed as string (null is excluded)
|
|
334
|
-
* ```
|
|
335
|
-
*/ function assertDefined(value, message) {
|
|
336
|
-
if (value === null || value === undefined) {
|
|
337
|
-
throw new ValueMustBeDefinedError(message);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
374
|
const assignClient = (target, client)=>{
|
|
342
375
|
Object.defineProperty(target, '__client', {
|
|
343
376
|
// hide from enumeration
|
|
@@ -561,5 +594,6 @@ exports.isEqualShallow = isEqualShallow;
|
|
|
561
594
|
exports.offEvent = offEvent;
|
|
562
595
|
exports.onEvent = onEvent;
|
|
563
596
|
exports.onceEvent = onceEvent;
|
|
597
|
+
exports.randomString = randomString;
|
|
564
598
|
exports.subscribeWithSelector = subscribeWithSelector;
|
|
565
599
|
exports.version = version;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SDKApi, Configuration } from '@dynamic-labs/sdk-api-core';
|
|
1
|
+
import { AuthStorageEnum, SDKApi, Configuration } from '@dynamic-labs/sdk-api-core';
|
|
2
2
|
|
|
3
3
|
const getCore = (client)=>{
|
|
4
4
|
// @ts-expect-error - this was hidden from the public API
|
|
@@ -68,10 +68,19 @@ function _extends() {
|
|
|
68
68
|
return _extends.apply(this, arguments);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
var version = "0.0.1-alpha.
|
|
71
|
+
var version = "0.0.1-alpha.13";
|
|
72
72
|
var dependencies = {
|
|
73
73
|
"@dynamic-labs/sdk-api-core": "0.0.702"};
|
|
74
74
|
|
|
75
|
+
const randomString = (length)=>{
|
|
76
|
+
const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
77
|
+
let result = '';
|
|
78
|
+
for(let i = length; i > 0; --i){
|
|
79
|
+
result += CHARS[Math.floor(Math.random() * CHARS.length)];
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
};
|
|
83
|
+
|
|
75
84
|
const getDetails = ({ details, cause })=>{
|
|
76
85
|
if (cause instanceof BaseError) {
|
|
77
86
|
return cause.details;
|
|
@@ -136,6 +145,56 @@ const getDetails = ({ details, cause })=>{
|
|
|
136
145
|
}
|
|
137
146
|
}
|
|
138
147
|
|
|
148
|
+
class ValueMustBeDefinedError extends BaseError {
|
|
149
|
+
constructor(message){
|
|
150
|
+
super({
|
|
151
|
+
cause: null,
|
|
152
|
+
code: 'value_must_be_defined_error',
|
|
153
|
+
docsUrl: null,
|
|
154
|
+
name: 'ValueMustBeDefined',
|
|
155
|
+
shortMessage: message
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Asserts that a value is not null or undefined, throwing an error if it is.
|
|
162
|
+
* This function acts as a type guard, narrowing the type to exclude null and undefined.
|
|
163
|
+
*
|
|
164
|
+
* @template T - The type of the value being checked
|
|
165
|
+
* @param value - The value to check for null or undefined
|
|
166
|
+
* @param message - The error message to throw if the value is null or undefined
|
|
167
|
+
* @throws Throws an error with the provided message if value is null or undefined
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const maybeString: string | null = getValue();
|
|
171
|
+
* assertDefined(maybeString, 'String value is required');
|
|
172
|
+
* // maybeString is now typed as string (null is excluded)
|
|
173
|
+
* ```
|
|
174
|
+
*/ function assertDefined(value, message) {
|
|
175
|
+
if (value === null || value === undefined) {
|
|
176
|
+
throw new ValueMustBeDefinedError(message);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Returns true if the client is using Dynamic cookies or a BYO JWT cookie.
|
|
182
|
+
*/ const isCookieEnabled = (client)=>{
|
|
183
|
+
var _securitySettings_auth, _securitySettings_externalAuth;
|
|
184
|
+
assertDefined(client.projectSettings, 'Project settings are not defined');
|
|
185
|
+
const securitySettings = client.projectSettings.security;
|
|
186
|
+
if (!securitySettings) return false;
|
|
187
|
+
// client uses Dynamic cookies
|
|
188
|
+
const dynamicCookiesEnabled = (((_securitySettings_auth = securitySettings.auth) == null ? void 0 : _securitySettings_auth.storage) || []).includes(AuthStorageEnum.Cookie);
|
|
189
|
+
// BYO JWT client puts their non-Dynamic JWT in a cookie
|
|
190
|
+
const byoJwtCookieEnabled = Boolean((_securitySettings_externalAuth = securitySettings.externalAuth) == null ? void 0 : _securitySettings_externalAuth.cookieName);
|
|
191
|
+
// should return true for both of these scenarios
|
|
192
|
+
// because we also need to do `credentials: true` in api.ts when
|
|
193
|
+
// a byo jwt client sets their named cookie for their jwt and
|
|
194
|
+
// needs to send it to our backend
|
|
195
|
+
return dynamicCookiesEnabled || byoJwtCookieEnabled;
|
|
196
|
+
};
|
|
197
|
+
|
|
139
198
|
class APIError extends BaseError {
|
|
140
199
|
static async fromResponse(response) {
|
|
141
200
|
const errorBody = await response.json();
|
|
@@ -247,15 +306,21 @@ class MfaRateLimitedError extends BaseError {
|
|
|
247
306
|
const core = getCore(client);
|
|
248
307
|
const settings = {
|
|
249
308
|
basePath: core.apiBaseUrl,
|
|
250
|
-
headers: {
|
|
309
|
+
headers: _extends({
|
|
251
310
|
'Content-Type': 'application/json',
|
|
252
311
|
'x-dyn-api-version': dependencies['@dynamic-labs/sdk-api-core'],
|
|
253
|
-
'x-dyn-
|
|
254
|
-
|
|
312
|
+
'x-dyn-request-id': randomString(50),
|
|
313
|
+
/**
|
|
314
|
+
* Ticket revise API version
|
|
315
|
+
*/ 'x-dyn-version': 'WalletKit/4.22.5'
|
|
316
|
+
}, core.getApiHeaders())
|
|
255
317
|
};
|
|
256
318
|
if (client.token) {
|
|
257
319
|
settings.headers.Authorization = `Bearer ${client.token}`;
|
|
258
320
|
}
|
|
321
|
+
if (client.projectSettings && isCookieEnabled(client)) {
|
|
322
|
+
settings.credentials = 'include';
|
|
323
|
+
}
|
|
259
324
|
return new SDKApi(new Configuration(_extends({}, settings, {
|
|
260
325
|
fetchApi: core.fetch,
|
|
261
326
|
middleware: [
|
|
@@ -304,38 +369,6 @@ class MfaRateLimitedError extends BaseError {
|
|
|
304
369
|
eventEmitter.emit(event, ...args);
|
|
305
370
|
};
|
|
306
371
|
|
|
307
|
-
class ValueMustBeDefinedError extends BaseError {
|
|
308
|
-
constructor(message){
|
|
309
|
-
super({
|
|
310
|
-
cause: null,
|
|
311
|
-
code: 'value_must_be_defined_error',
|
|
312
|
-
docsUrl: null,
|
|
313
|
-
name: 'ValueMustBeDefined',
|
|
314
|
-
shortMessage: message
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* Asserts that a value is not null or undefined, throwing an error if it is.
|
|
321
|
-
* This function acts as a type guard, narrowing the type to exclude null and undefined.
|
|
322
|
-
*
|
|
323
|
-
* @template T - The type of the value being checked
|
|
324
|
-
* @param value - The value to check for null or undefined
|
|
325
|
-
* @param message - The error message to throw if the value is null or undefined
|
|
326
|
-
* @throws Throws an error with the provided message if value is null or undefined
|
|
327
|
-
* @example
|
|
328
|
-
* ```typescript
|
|
329
|
-
* const maybeString: string | null = getValue();
|
|
330
|
-
* assertDefined(maybeString, 'String value is required');
|
|
331
|
-
* // maybeString is now typed as string (null is excluded)
|
|
332
|
-
* ```
|
|
333
|
-
*/ function assertDefined(value, message) {
|
|
334
|
-
if (value === null || value === undefined) {
|
|
335
|
-
throw new ValueMustBeDefinedError(message);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
|
|
339
372
|
const assignClient = (target, client)=>{
|
|
340
373
|
Object.defineProperty(target, '__client', {
|
|
341
374
|
// hide from enumeration
|
|
@@ -535,4 +568,4 @@ const getWalletProviderFromWalletAccount = (walletAccount)=>{
|
|
|
535
568
|
return walletProvider;
|
|
536
569
|
};
|
|
537
570
|
|
|
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 };
|
|
571
|
+
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, randomString as r, subscribeWithSelector as s, version as v };
|
package/index.cjs.js
CHANGED
|
@@ -263,9 +263,13 @@ const parseFromStorage = (value)=>{
|
|
|
263
263
|
const logout = async (client)=>{
|
|
264
264
|
const core = getWalletProviderFromWalletAccount.getCore(client);
|
|
265
265
|
const apiClient = getWalletProviderFromWalletAccount.createApiClient(client);
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
266
|
+
try {
|
|
267
|
+
await apiClient.revokeSession({
|
|
268
|
+
environmentId: core.environmentId
|
|
269
|
+
});
|
|
270
|
+
} catch (error) {
|
|
271
|
+
core.logger.error('Failed to revoke session', error);
|
|
272
|
+
}
|
|
269
273
|
core.state.set({
|
|
270
274
|
sessionExpiresAt: null,
|
|
271
275
|
token: null,
|
|
@@ -748,7 +752,7 @@ class InvalidStorageValue extends getWalletProviderFromWalletAccount.BaseError {
|
|
|
748
752
|
/**
|
|
749
753
|
* Creates a core instance that contains all the services and state of the Dynamic SDK client.
|
|
750
754
|
*/ const createCore = (config)=>{
|
|
751
|
-
var _config_coreConfig, _config_coreConfig1, _config_coreConfig2, _config_coreConfig3, _config_coreConfig4, _config_coreConfig5, _config_coreConfig6;
|
|
755
|
+
var _config_coreConfig, _config_coreConfig1, _config_coreConfig2, _config_coreConfig3, _config_coreConfig4, _config_coreConfig5, _config_coreConfig6, _config_coreConfig7;
|
|
752
756
|
var _config_coreConfig_apiBaseUrl;
|
|
753
757
|
const apiBaseUrl = (_config_coreConfig_apiBaseUrl = (_config_coreConfig = config.coreConfig) == null ? void 0 : _config_coreConfig.apiBaseUrl) != null ? _config_coreConfig_apiBaseUrl : DEFAULT_API_BASE_URL;
|
|
754
758
|
var _config_coreConfig_logger;
|
|
@@ -769,12 +773,14 @@ class InvalidStorageValue extends getWalletProviderFromWalletAccount.BaseError {
|
|
|
769
773
|
const runtimeServices = createRuntimeServices();
|
|
770
774
|
var _config_coreConfig_passkey;
|
|
771
775
|
const passkey = (_config_coreConfig_passkey = (_config_coreConfig6 = config.coreConfig) == null ? void 0 : _config_coreConfig6.passkey) != null ? _config_coreConfig_passkey : createWebPasskeyService();
|
|
776
|
+
var _config_coreConfig_getApiHeaders;
|
|
772
777
|
return {
|
|
773
778
|
apiBaseUrl,
|
|
774
779
|
environmentId: config.environmentId,
|
|
775
780
|
eventEmitter,
|
|
776
781
|
extensions: new Set(),
|
|
777
782
|
fetch,
|
|
783
|
+
getApiHeaders: (_config_coreConfig_getApiHeaders = (_config_coreConfig7 = config.coreConfig) == null ? void 0 : _config_coreConfig7.getApiHeaders) != null ? _config_coreConfig_getApiHeaders : ()=>({}),
|
|
778
784
|
initTrack,
|
|
779
785
|
logger,
|
|
780
786
|
metadata: config.metadata,
|
|
@@ -1091,15 +1097,6 @@ const digestSHA256 = (str)=>{
|
|
|
1091
1097
|
return btoa(String.fromCharCode.apply(null, numberArray)).replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
|
|
1092
1098
|
};
|
|
1093
1099
|
|
|
1094
|
-
const randomString = (length)=>{
|
|
1095
|
-
const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
1096
|
-
let result = '';
|
|
1097
|
-
for(let i = length; i > 0; --i){
|
|
1098
|
-
result += CHARS[Math.floor(Math.random() * CHARS.length)];
|
|
1099
|
-
}
|
|
1100
|
-
return result;
|
|
1101
|
-
};
|
|
1102
|
-
|
|
1103
1100
|
const APPLE_RESPONSE_MODE = 'form_post';
|
|
1104
1101
|
const APPLE_RESPONSE_TYPE = 'code id_token';
|
|
1105
1102
|
/** Helper function to add OAuth URL parameters to a given base URL. */ const addOAuthUrlParams = (provider, baseUrl)=>{
|
|
@@ -1160,8 +1157,8 @@ const providersRequiringPkce = [
|
|
|
1160
1157
|
const socialProviderUrl = addOAuthUrlParams(socialProvider, loginBaseUrl);
|
|
1161
1158
|
// Add PKCE and state parameters
|
|
1162
1159
|
const usingPkce = providersRequiringPkce.includes(provider);
|
|
1163
|
-
const state = randomString(32);
|
|
1164
|
-
const codeVerifier = randomString(43);
|
|
1160
|
+
const state = getWalletProviderFromWalletAccount.randomString(32);
|
|
1161
|
+
const codeVerifier = getWalletProviderFromWalletAccount.randomString(43);
|
|
1165
1162
|
socialProviderUrl.searchParams.set('state', state);
|
|
1166
1163
|
socialProviderUrl.searchParams.set('response_type', 'code');
|
|
1167
1164
|
if (usingPkce) {
|
package/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BaseError, a as assertDefined, g as getCore, b as assignClient, I as InvalidStorageSet, c as createApiClient, e as emitEvent, s as subscribeWithSelector, i as isEqualShallow, d as dependencies, C as CannotTrackError, v as version, _ as _extends, f as getClient, h as getWalletProviderFromWalletAccount, j as getWalletProviderRegistry } from './getWalletProviderFromWalletAccount.esm.js';
|
|
1
|
+
import { B as BaseError, a as assertDefined, g as getCore, b as assignClient, I as InvalidStorageSet, c as createApiClient, e as emitEvent, s as subscribeWithSelector, i as isEqualShallow, d as dependencies, C as CannotTrackError, v as version, _ as _extends, r as randomString, f as getClient, h as getWalletProviderFromWalletAccount, j as getWalletProviderRegistry } from './getWalletProviderFromWalletAccount.esm.js';
|
|
2
2
|
export { M as MfaInvalidOtpError, k as MfaRateLimitedError, n as hasExtension, o as offEvent, m as onEvent, l as onceEvent } from './getWalletProviderFromWalletAccount.esm.js';
|
|
3
3
|
import { JwtVerifiedCredentialFormatEnum, ProviderEnum, MfaBackupCodeAcknowledgement } from '@dynamic-labs/sdk-api-core';
|
|
4
4
|
import { z } from '@zod/mini';
|
|
@@ -262,9 +262,13 @@ const parseFromStorage = (value)=>{
|
|
|
262
262
|
const logout = async (client)=>{
|
|
263
263
|
const core = getCore(client);
|
|
264
264
|
const apiClient = createApiClient(client);
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
265
|
+
try {
|
|
266
|
+
await apiClient.revokeSession({
|
|
267
|
+
environmentId: core.environmentId
|
|
268
|
+
});
|
|
269
|
+
} catch (error) {
|
|
270
|
+
core.logger.error('Failed to revoke session', error);
|
|
271
|
+
}
|
|
268
272
|
core.state.set({
|
|
269
273
|
sessionExpiresAt: null,
|
|
270
274
|
token: null,
|
|
@@ -747,7 +751,7 @@ class InvalidStorageValue extends BaseError {
|
|
|
747
751
|
/**
|
|
748
752
|
* Creates a core instance that contains all the services and state of the Dynamic SDK client.
|
|
749
753
|
*/ const createCore = (config)=>{
|
|
750
|
-
var _config_coreConfig, _config_coreConfig1, _config_coreConfig2, _config_coreConfig3, _config_coreConfig4, _config_coreConfig5, _config_coreConfig6;
|
|
754
|
+
var _config_coreConfig, _config_coreConfig1, _config_coreConfig2, _config_coreConfig3, _config_coreConfig4, _config_coreConfig5, _config_coreConfig6, _config_coreConfig7;
|
|
751
755
|
var _config_coreConfig_apiBaseUrl;
|
|
752
756
|
const apiBaseUrl = (_config_coreConfig_apiBaseUrl = (_config_coreConfig = config.coreConfig) == null ? void 0 : _config_coreConfig.apiBaseUrl) != null ? _config_coreConfig_apiBaseUrl : DEFAULT_API_BASE_URL;
|
|
753
757
|
var _config_coreConfig_logger;
|
|
@@ -768,12 +772,14 @@ class InvalidStorageValue extends BaseError {
|
|
|
768
772
|
const runtimeServices = createRuntimeServices();
|
|
769
773
|
var _config_coreConfig_passkey;
|
|
770
774
|
const passkey = (_config_coreConfig_passkey = (_config_coreConfig6 = config.coreConfig) == null ? void 0 : _config_coreConfig6.passkey) != null ? _config_coreConfig_passkey : createWebPasskeyService();
|
|
775
|
+
var _config_coreConfig_getApiHeaders;
|
|
771
776
|
return {
|
|
772
777
|
apiBaseUrl,
|
|
773
778
|
environmentId: config.environmentId,
|
|
774
779
|
eventEmitter,
|
|
775
780
|
extensions: new Set(),
|
|
776
781
|
fetch,
|
|
782
|
+
getApiHeaders: (_config_coreConfig_getApiHeaders = (_config_coreConfig7 = config.coreConfig) == null ? void 0 : _config_coreConfig7.getApiHeaders) != null ? _config_coreConfig_getApiHeaders : ()=>({}),
|
|
777
783
|
initTrack,
|
|
778
784
|
logger,
|
|
779
785
|
metadata: config.metadata,
|
|
@@ -1090,15 +1096,6 @@ const digestSHA256 = (str)=>{
|
|
|
1090
1096
|
return btoa(String.fromCharCode.apply(null, numberArray)).replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
|
|
1091
1097
|
};
|
|
1092
1098
|
|
|
1093
|
-
const randomString = (length)=>{
|
|
1094
|
-
const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
1095
|
-
let result = '';
|
|
1096
|
-
for(let i = length; i > 0; --i){
|
|
1097
|
-
result += CHARS[Math.floor(Math.random() * CHARS.length)];
|
|
1098
|
-
}
|
|
1099
|
-
return result;
|
|
1100
|
-
};
|
|
1101
|
-
|
|
1102
1099
|
const APPLE_RESPONSE_MODE = 'form_post';
|
|
1103
1100
|
const APPLE_RESPONSE_TYPE = 'code id_token';
|
|
1104
1101
|
/** Helper function to add OAuth URL parameters to a given base URL. */ const addOAuthUrlParams = (provider, baseUrl)=>{
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCore.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/client/core/createCore/createCore.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAoB,MAAM,UAAU,CAAC;AAG9D;;GAEG;AACH,eAAO,MAAM,UAAU,WAAY,mBAAmB,KAAG,
|
|
1
|
+
{"version":3,"file":"createCore.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/client/core/createCore/createCore.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAoB,MAAM,UAAU,CAAC;AAG9D;;GAEG;AACH,eAAO,MAAM,UAAU,WAAY,mBAAmB,KAAG,WA8CxD,CAAC"}
|
|
@@ -36,6 +36,10 @@ export type DynamicCore = {
|
|
|
36
36
|
* Instance of the fetch service, used for making any HTTP requests.
|
|
37
37
|
*/
|
|
38
38
|
fetch: Fetch;
|
|
39
|
+
/**
|
|
40
|
+
* Custom headers to be sent with API requests.
|
|
41
|
+
*/
|
|
42
|
+
getApiHeaders: () => Record<string, string>;
|
|
39
43
|
/**
|
|
40
44
|
* Instance of the async track service, used for tracking status of SDK initialization promises.
|
|
41
45
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynamicCore.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/client/core/types/DynamicCore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,eAAe,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,YAAY,EAAE,YAAY,CAAC;IAE3B;;OAEG;IACH,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAExB;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC;IAEb;;OAEG;IACH,SAAS,EAAE,UAAU,CAAC;IAEtB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,QAAQ,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAE1C;;OAEG;IACH,QAAQ,EAAE,iBAAiB,CAAC;IAE5B;;OAEG;IACH,YAAY,EAAE,YAAY,CAAC;IAE3B;;OAEG;IACH,OAAO,EAAE,cAAc,CAAC;IAExB;;OAEG;IACH,eAAe,EAAE,eAAe,CAAC;IAEjC;;OAEG;IACH,KAAK,EAAE,eAAe,CAAC,gBAAgB,CAAC,CAAC;IAEzC;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC"}
|
|
1
|
+
{"version":3,"file":"DynamicCore.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/client/core/types/DynamicCore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,eAAe,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,YAAY,EAAE,YAAY,CAAC;IAE3B;;OAEG;IACH,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAExB;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC;IAEb;;OAEG;IACH,aAAa,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE5C;;OAEG;IACH,SAAS,EAAE,UAAU,CAAC;IAEtB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,QAAQ,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAE1C;;OAEG;IACH,QAAQ,EAAE,iBAAiB,CAAC;IAE5B;;OAEG;IACH,YAAY,EAAE,YAAY,CAAC;IAE3B;;OAEG;IACH,OAAO,EAAE,cAAc,CAAC;IAExB;;OAEG;IACH,eAAe,EAAE,eAAe,CAAC;IAEjC;;OAEG;IACH,KAAK,EAAE,eAAe,CAAC,gBAAgB,CAAC,CAAC;IAEzC;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC"}
|
|
@@ -2,5 +2,5 @@ import type { DynamicCore } from './DynamicCore';
|
|
|
2
2
|
/**
|
|
3
3
|
* Available options for internal configuration of the Dynamic SDK client.
|
|
4
4
|
*/
|
|
5
|
-
export type DynamicCoreConfig = Partial<Pick<DynamicCore, 'apiBaseUrl' | 'fetch' | 'logger' | 'navigate' | 'openDeeplink' | 'passkey' | 'storage'>>;
|
|
5
|
+
export type DynamicCoreConfig = Partial<Pick<DynamicCore, 'apiBaseUrl' | 'fetch' | 'logger' | 'navigate' | 'openDeeplink' | 'passkey' | 'storage' | 'getApiHeaders'>>;
|
|
6
6
|
//# sourceMappingURL=DynamicCoreConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynamicCoreConfig.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/client/core/types/DynamicCoreConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,CACrC,IAAI,CACF,WAAW,EACT,YAAY,GACZ,OAAO,GACP,QAAQ,GACR,UAAU,GACV,cAAc,GACd,SAAS,GACT,SAAS,
|
|
1
|
+
{"version":3,"file":"DynamicCoreConfig.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/client/core/types/DynamicCoreConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,CACrC,IAAI,CACF,WAAW,EACT,YAAY,GACZ,OAAO,GACP,QAAQ,GACR,UAAU,GACV,cAAc,GACd,SAAS,GACT,SAAS,GACT,eAAe,CAClB,CACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createApiClient.d.ts","sourceRoot":"","sources":["../../../../../../packages/client/src/modules/apiClient/createApiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAInE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"createApiClient.d.ts","sourceRoot":"","sources":["../../../../../../packages/client/src/modules/apiClient/createApiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAInE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAgBtD;;;;GAIG;AACH,eAAO,MAAM,eAAe,WAClB,aAAa,YACZ,sBAAsB,WAqChC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/modules/auth/logout/logout.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAK3D,eAAO,MAAM,MAAM,WAAkB,aAAa,
|
|
1
|
+
{"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/modules/auth/logout/logout.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAK3D,eAAO,MAAM,MAAM,WAAkB,aAAa,kBAuBjD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/modules/projectSettings/isCookieEnabled/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DynamicClient } from '../../../client/types';
|
|
2
|
+
/**
|
|
3
|
+
* Returns true if the client is using Dynamic cookies or a BYO JWT cookie.
|
|
4
|
+
*/
|
|
5
|
+
export declare const isCookieEnabled: (client: DynamicClient) => boolean;
|
|
6
|
+
//# sourceMappingURL=isCookieEnabled.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isCookieEnabled.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/modules/projectSettings/isCookieEnabled/isCookieEnabled.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAG3D;;GAEG;AACH,eAAO,MAAM,eAAe,WAAY,aAAa,KAAG,OAsBvD,CAAC"}
|