@dynamic-labs/message-transport 2.1.0-alpha.15 → 2.1.0-alpha.16
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 +9 -0
- package/_virtual/_tslib.cjs +13 -0
- package/_virtual/_tslib.js +13 -1
- package/package.json +2 -2
- package/src/index.cjs +4 -0
- package/src/index.d.ts +4 -2
- package/src/index.js +2 -0
- package/src/messageTypes/ConsoleMessages.d.ts +4 -0
- package/src/messageTypes/EthMessages.d.ts +13 -0
- package/src/messageTypes/UserInterfaceModuleMessages.d.ts +4 -0
- package/src/messageTypes/WebViewVisibilityMessages.d.ts +3 -0
- package/src/messageTypes/index.d.ts +4 -0
- package/src/requestChannel/requestChannel.cjs +10 -2
- package/src/requestChannel/requestChannel.js +10 -2
- package/src/utils/isSerializedError/index.d.ts +1 -0
- package/src/utils/isSerializedError/isSerializedError.cjs +14 -0
- package/src/utils/isSerializedError/isSerializedError.d.ts +2 -0
- package/src/utils/isSerializedError/isSerializedError.js +10 -0
- package/src/utils/parseErrorFromTransport/index.d.ts +1 -0
- package/src/utils/parseErrorFromTransport/parseErrorFromTransport.cjs +54 -0
- package/src/utils/parseErrorFromTransport/parseErrorFromTransport.d.ts +11 -0
- package/src/utils/parseErrorFromTransport/parseErrorFromTransport.js +50 -0
- package/src/utils/serializeErrorForTransport/index.d.ts +1 -0
- package/src/utils/serializeErrorForTransport/serializeErrorForTransport.cjs +33 -0
- package/src/utils/serializeErrorForTransport/serializeErrorForTransport.d.ts +19 -0
- package/src/utils/serializeErrorForTransport/serializeErrorForTransport.js +29 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
|
|
2
|
+
## [2.1.0-alpha.16](https://github.com/dynamic-labs/DynamicAuth/compare/v2.1.0-alpha.15...v2.1.0-alpha.16) (2024-05-14)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add client.sdk.error with errors from the webview ([#5520](https://github.com/dynamic-labs/DynamicAuth/issues/5520)) ([a886927](https://github.com/dynamic-labs/DynamicAuth/commit/a8869273bf361c870d6e3cb82a28d9ccec65905b))
|
|
8
|
+
* add setDefaultTabIndex to default the selected wallets tab ([#5593](https://github.com/dynamic-labs/DynamicAuth/issues/5593)) ([6e8ce05](https://github.com/dynamic-labs/DynamicAuth/commit/6e8ce053c4f6f009acc57dac55a8e9c74fbcc73b))
|
|
9
|
+
* add visibility/auth-flow/user-profile to react-native ([#5564](https://github.com/dynamic-labs/DynamicAuth/issues/5564)) ([d93cea8](https://github.com/dynamic-labs/DynamicAuth/commit/d93cea82a123c6ec4d3d594a7dc064f4db2981c2))
|
|
10
|
+
|
|
2
11
|
## [2.1.0-alpha.15](https://github.com/dynamic-labs/DynamicAuth/compare/v2.1.0-alpha.14...v2.1.0-alpha.15) (2024-05-13)
|
|
3
12
|
|
|
4
13
|
|
package/_virtual/_tslib.cjs
CHANGED
|
@@ -18,6 +18,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
18
18
|
PERFORMANCE OF THIS SOFTWARE.
|
|
19
19
|
***************************************************************************** */
|
|
20
20
|
|
|
21
|
+
function __rest(s, e) {
|
|
22
|
+
var t = {};
|
|
23
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
24
|
+
t[p] = s[p];
|
|
25
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
26
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
27
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
28
|
+
t[p[i]] = s[p[i]];
|
|
29
|
+
}
|
|
30
|
+
return t;
|
|
31
|
+
}
|
|
32
|
+
|
|
21
33
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
22
34
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
35
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -34,3 +46,4 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
34
46
|
};
|
|
35
47
|
|
|
36
48
|
exports.__awaiter = __awaiter;
|
|
49
|
+
exports.__rest = __rest;
|
package/_virtual/_tslib.js
CHANGED
|
@@ -14,6 +14,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
15
|
***************************************************************************** */
|
|
16
16
|
|
|
17
|
+
function __rest(s, e) {
|
|
18
|
+
var t = {};
|
|
19
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
20
|
+
t[p] = s[p];
|
|
21
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
22
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
23
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
24
|
+
t[p[i]] = s[p[i]];
|
|
25
|
+
}
|
|
26
|
+
return t;
|
|
27
|
+
}
|
|
28
|
+
|
|
17
29
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
18
30
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
31
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -29,4 +41,4 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
29
41
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
30
42
|
};
|
|
31
43
|
|
|
32
|
-
export { __awaiter };
|
|
44
|
+
export { __awaiter, __rest };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/message-transport",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.16",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@vue/reactivity": "3.4.21",
|
|
30
|
-
"@dynamic-labs/types": "2.1.0-alpha.
|
|
30
|
+
"@dynamic-labs/types": "2.1.0-alpha.16",
|
|
31
31
|
"eventemitter3": "5.0.1"
|
|
32
32
|
}
|
|
33
33
|
}
|
package/src/index.cjs
CHANGED
|
@@ -9,6 +9,8 @@ var makeWaitForInitEvent = require('./messageTransport/decorators/makeWaitForIni
|
|
|
9
9
|
var makeWaitForUnblock = require('./messageTransport/decorators/makeWaitForUnblock/makeWaitForUnblock.cjs');
|
|
10
10
|
var requestChannel = require('./requestChannel/requestChannel.cjs');
|
|
11
11
|
var parseMessageTransportData = require('./utils/parseMessageTransportData/parseMessageTransportData.cjs');
|
|
12
|
+
var serializeErrorForTransport = require('./utils/serializeErrorForTransport/serializeErrorForTransport.cjs');
|
|
13
|
+
var parseErrorFromTransport = require('./utils/parseErrorFromTransport/parseErrorFromTransport.cjs');
|
|
12
14
|
var createEventEmitterForMessages = require('./store/createEventEmitterForMessages/createEventEmitterForMessages.cjs');
|
|
13
15
|
var store = require('./store/store.cjs');
|
|
14
16
|
var storeSetter = require('./store/storeSetter/storeSetter.cjs');
|
|
@@ -22,6 +24,8 @@ exports.makeWaitForInitEvent = makeWaitForInitEvent.makeWaitForInitEvent;
|
|
|
22
24
|
exports.makeWaitForUnblock = makeWaitForUnblock.makeWaitForUnblock;
|
|
23
25
|
exports.createRequestChannel = requestChannel.createRequestChannel;
|
|
24
26
|
exports.parseMessageTransportData = parseMessageTransportData.parseMessageTransportData;
|
|
27
|
+
exports.serializeErrorForTransport = serializeErrorForTransport.serializeErrorForTransport;
|
|
28
|
+
exports.parseErrorFromTransport = parseErrorFromTransport.parseErrorFromTransport;
|
|
25
29
|
exports.createEventEmitterForMessages = createEventEmitterForMessages.createEventEmitterForMessages;
|
|
26
30
|
exports.createStore = store.createStore;
|
|
27
31
|
exports.createStoreSetter = storeSetter.createStoreSetter;
|
package/src/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { applyDefaultMessageOrigin, createMessageTransport, makeWaitForInitEvent, makeWaitForUnblock, type BypassBlockCallback, type MessageTransport, type MessageTransportCallback, type MessageTransportData, type MessageTransportDataOptionalOrigin, type MessageTransportWithDefaultOrigin, } from './messageTransport';
|
|
2
2
|
export { createRequestChannel, type RequestChannel } from './requestChannel';
|
|
3
3
|
export { parseMessageTransportData } from './utils/parseMessageTransportData';
|
|
4
|
+
export { serializeErrorForTransport } from './utils/serializeErrorForTransport';
|
|
5
|
+
export { parseErrorFromTransport } from './utils/parseErrorFromTransport';
|
|
4
6
|
export { createEventEmitterForMessages, createStore, createStoreSetter, type MessagesForEventEmitter, } from './store';
|
|
5
|
-
export type { Store, StoreKeys, StoreSetter, StoreStateEvents, StoreStateGetters,
|
|
6
|
-
export { sdkHasLoadedEventName, type AuthModuleMessages, type AuthModuleState, type ClientManifest, type OtpMessages, type SdkModuleMessages, type SdkModuleState, type WalletsModuleState, } from './messageTypes';
|
|
7
|
+
export type { Store, StoreEventListeners, StoreKeys, StoreSetter, StoreStateEvents, StoreStateGetters, } from './store/types';
|
|
8
|
+
export { sdkHasLoadedEventName, type AuthModuleMessages, type AuthModuleState, type ClientManifest, type OtpMessages, type SdkModuleMessages, type SdkModuleState, type EthMessages, type WalletsModuleState, type ConsoleMessages, type WebViewVisibilityMessages, type UserInterfaceModuleMessages, } from './messageTypes';
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,8 @@ export { makeWaitForInitEvent } from './messageTransport/decorators/makeWaitForI
|
|
|
5
5
|
export { makeWaitForUnblock } from './messageTransport/decorators/makeWaitForUnblock/makeWaitForUnblock.js';
|
|
6
6
|
export { createRequestChannel } from './requestChannel/requestChannel.js';
|
|
7
7
|
export { parseMessageTransportData } from './utils/parseMessageTransportData/parseMessageTransportData.js';
|
|
8
|
+
export { serializeErrorForTransport } from './utils/serializeErrorForTransport/serializeErrorForTransport.js';
|
|
9
|
+
export { parseErrorFromTransport } from './utils/parseErrorFromTransport/parseErrorFromTransport.js';
|
|
8
10
|
export { createEventEmitterForMessages } from './store/createEventEmitterForMessages/createEventEmitterForMessages.js';
|
|
9
11
|
export { createStore } from './store/store.js';
|
|
10
12
|
export { createStoreSetter } from './store/storeSetter/storeSetter.js';
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export * from './AuthModuleMessages';
|
|
2
|
+
export * from './EthMessages';
|
|
2
3
|
export * from './OtpMessages';
|
|
3
4
|
export * from './SdkModuleMessages';
|
|
4
5
|
export * from './WalletsModuleMessages';
|
|
6
|
+
export * from './ConsoleMessages';
|
|
7
|
+
export * from './WebViewVisibilityMessages';
|
|
8
|
+
export * from './UserInterfaceModuleMessages';
|
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
6
|
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
+
var parseErrorFromTransport = require('../utils/parseErrorFromTransport/parseErrorFromTransport.cjs');
|
|
8
|
+
var serializeErrorForTransport = require('../utils/serializeErrorForTransport/serializeErrorForTransport.cjs');
|
|
9
|
+
var isSerializedError = require('../utils/isSerializedError/isSerializedError.cjs');
|
|
7
10
|
|
|
8
11
|
/** Given a request event name, returns the event name for its resolve */
|
|
9
12
|
const getResolveMessageType = (type) => `${type}__resolve`;
|
|
@@ -65,7 +68,7 @@ const createRequestChannel = (messageTransport) => {
|
|
|
65
68
|
}
|
|
66
69
|
catch (error) {
|
|
67
70
|
messageTransport.emit({
|
|
68
|
-
args: [error],
|
|
71
|
+
args: [serializeErrorForTransport.serializeErrorForTransport(error)],
|
|
69
72
|
messageSessionId,
|
|
70
73
|
type: getRejectMessageType(requestType),
|
|
71
74
|
});
|
|
@@ -92,7 +95,12 @@ const createRequestChannel = (messageTransport) => {
|
|
|
92
95
|
cleanup();
|
|
93
96
|
}
|
|
94
97
|
if (incomingType === rejectMessageType) {
|
|
95
|
-
|
|
98
|
+
if (isSerializedError.isSerializedError(result)) {
|
|
99
|
+
reject(parseErrorFromTransport.parseErrorFromTransport(result));
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
reject(result);
|
|
103
|
+
}
|
|
96
104
|
cleanup();
|
|
97
105
|
}
|
|
98
106
|
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
+
import { parseErrorFromTransport } from '../utils/parseErrorFromTransport/parseErrorFromTransport.js';
|
|
4
|
+
import { serializeErrorForTransport } from '../utils/serializeErrorForTransport/serializeErrorForTransport.js';
|
|
5
|
+
import { isSerializedError } from '../utils/isSerializedError/isSerializedError.js';
|
|
3
6
|
|
|
4
7
|
/** Given a request event name, returns the event name for its resolve */
|
|
5
8
|
const getResolveMessageType = (type) => `${type}__resolve`;
|
|
@@ -61,7 +64,7 @@ const createRequestChannel = (messageTransport) => {
|
|
|
61
64
|
}
|
|
62
65
|
catch (error) {
|
|
63
66
|
messageTransport.emit({
|
|
64
|
-
args: [error],
|
|
67
|
+
args: [serializeErrorForTransport(error)],
|
|
65
68
|
messageSessionId,
|
|
66
69
|
type: getRejectMessageType(requestType),
|
|
67
70
|
});
|
|
@@ -88,7 +91,12 @@ const createRequestChannel = (messageTransport) => {
|
|
|
88
91
|
cleanup();
|
|
89
92
|
}
|
|
90
93
|
if (incomingType === rejectMessageType) {
|
|
91
|
-
|
|
94
|
+
if (isSerializedError(result)) {
|
|
95
|
+
reject(parseErrorFromTransport(result));
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
reject(result);
|
|
99
|
+
}
|
|
92
100
|
cleanup();
|
|
93
101
|
}
|
|
94
102
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { isSerializedError } from './isSerializedError';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const isSerializedError = (serializedError) => {
|
|
7
|
+
if (typeof serializedError !== 'object' || serializedError === null) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
const { message, stack } = serializedError;
|
|
11
|
+
return typeof message === 'string' && typeof stack === 'string';
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
exports.isSerializedError = isSerializedError;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
const isSerializedError = (serializedError) => {
|
|
3
|
+
if (typeof serializedError !== 'object' || serializedError === null) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
const { message, stack } = serializedError;
|
|
7
|
+
return typeof message === 'string' && typeof stack === 'string';
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { isSerializedError };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parseErrorFromTransport } from './parseErrorFromTransport';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Parses a serialized error object back into an Error instance.
|
|
10
|
+
* This function will recreate an Error or a specific subclass of Error
|
|
11
|
+
* based on the name property if it matches known error types.
|
|
12
|
+
* Additional properties are added back to the reconstructed error object.
|
|
13
|
+
*
|
|
14
|
+
* @param {SerializedError} serializedError - The serialized error object to parse.
|
|
15
|
+
* @returns {Error} - The reconstructed Error instance.
|
|
16
|
+
*/
|
|
17
|
+
const parseErrorFromTransport = (serializedError) => {
|
|
18
|
+
const { message, name, stack } = serializedError, otherProps = _tslib.__rest(serializedError, ["message", "name", "stack"]);
|
|
19
|
+
let error;
|
|
20
|
+
// Determine the type of the error based on the 'name' property and instantiate accordingly
|
|
21
|
+
switch (name) {
|
|
22
|
+
case 'TypeError':
|
|
23
|
+
error = new TypeError(message);
|
|
24
|
+
break;
|
|
25
|
+
case 'ReferenceError':
|
|
26
|
+
error = new ReferenceError(message);
|
|
27
|
+
break;
|
|
28
|
+
case 'SyntaxError':
|
|
29
|
+
error = new SyntaxError(message);
|
|
30
|
+
break;
|
|
31
|
+
case 'RangeError':
|
|
32
|
+
error = new RangeError(message);
|
|
33
|
+
break;
|
|
34
|
+
case 'EvalError':
|
|
35
|
+
error = new EvalError(message);
|
|
36
|
+
break;
|
|
37
|
+
case 'URIError':
|
|
38
|
+
error = new URIError(message);
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
// Default to a generic Error if the specific type isn't recognized
|
|
42
|
+
error = new Error(message);
|
|
43
|
+
error.name = name || 'Error'; // Ensure the name is set, defaulting to 'Error' if not provided
|
|
44
|
+
}
|
|
45
|
+
// Reattach the stack trace and any other enumerable properties
|
|
46
|
+
if (stack) {
|
|
47
|
+
error.stack = stack;
|
|
48
|
+
}
|
|
49
|
+
// Reattach other custom properties that may have been serialized
|
|
50
|
+
Object.assign(error, otherProps);
|
|
51
|
+
return error;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
exports.parseErrorFromTransport = parseErrorFromTransport;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SerializedError } from '../serializeErrorForTransport';
|
|
2
|
+
/**
|
|
3
|
+
* Parses a serialized error object back into an Error instance.
|
|
4
|
+
* This function will recreate an Error or a specific subclass of Error
|
|
5
|
+
* based on the name property if it matches known error types.
|
|
6
|
+
* Additional properties are added back to the reconstructed error object.
|
|
7
|
+
*
|
|
8
|
+
* @param {SerializedError} serializedError - The serialized error object to parse.
|
|
9
|
+
* @returns {Error} - The reconstructed Error instance.
|
|
10
|
+
*/
|
|
11
|
+
export declare const parseErrorFromTransport: (serializedError: SerializedError) => Error;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __rest } from '../../../_virtual/_tslib.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Parses a serialized error object back into an Error instance.
|
|
6
|
+
* This function will recreate an Error or a specific subclass of Error
|
|
7
|
+
* based on the name property if it matches known error types.
|
|
8
|
+
* Additional properties are added back to the reconstructed error object.
|
|
9
|
+
*
|
|
10
|
+
* @param {SerializedError} serializedError - The serialized error object to parse.
|
|
11
|
+
* @returns {Error} - The reconstructed Error instance.
|
|
12
|
+
*/
|
|
13
|
+
const parseErrorFromTransport = (serializedError) => {
|
|
14
|
+
const { message, name, stack } = serializedError, otherProps = __rest(serializedError, ["message", "name", "stack"]);
|
|
15
|
+
let error;
|
|
16
|
+
// Determine the type of the error based on the 'name' property and instantiate accordingly
|
|
17
|
+
switch (name) {
|
|
18
|
+
case 'TypeError':
|
|
19
|
+
error = new TypeError(message);
|
|
20
|
+
break;
|
|
21
|
+
case 'ReferenceError':
|
|
22
|
+
error = new ReferenceError(message);
|
|
23
|
+
break;
|
|
24
|
+
case 'SyntaxError':
|
|
25
|
+
error = new SyntaxError(message);
|
|
26
|
+
break;
|
|
27
|
+
case 'RangeError':
|
|
28
|
+
error = new RangeError(message);
|
|
29
|
+
break;
|
|
30
|
+
case 'EvalError':
|
|
31
|
+
error = new EvalError(message);
|
|
32
|
+
break;
|
|
33
|
+
case 'URIError':
|
|
34
|
+
error = new URIError(message);
|
|
35
|
+
break;
|
|
36
|
+
default:
|
|
37
|
+
// Default to a generic Error if the specific type isn't recognized
|
|
38
|
+
error = new Error(message);
|
|
39
|
+
error.name = name || 'Error'; // Ensure the name is set, defaulting to 'Error' if not provided
|
|
40
|
+
}
|
|
41
|
+
// Reattach the stack trace and any other enumerable properties
|
|
42
|
+
if (stack) {
|
|
43
|
+
error.stack = stack;
|
|
44
|
+
}
|
|
45
|
+
// Reattach other custom properties that may have been serialized
|
|
46
|
+
Object.assign(error, otherProps);
|
|
47
|
+
return error;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { parseErrorFromTransport };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { serializeErrorForTransport, type SerializedError, } from './serializeErrorForTransport';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Serializes an error to a JSON object to be sent by transport.
|
|
8
|
+
* This function checks if the input is an instance of Error to capture
|
|
9
|
+
* standard properties like message, name, and stack. It also attempts to
|
|
10
|
+
* serialize any enumerable properties that are present on error-like objects.
|
|
11
|
+
*
|
|
12
|
+
* @param {unknown} err - The error or error-like object to serialize.
|
|
13
|
+
* @returns {SerializedError} - The serialized error object.
|
|
14
|
+
*/
|
|
15
|
+
const serializeErrorForTransport = (err) => {
|
|
16
|
+
if (err instanceof Error) {
|
|
17
|
+
return Object.assign({
|
|
18
|
+
// @ts-expect-error message is a standard property of Error
|
|
19
|
+
message: err.message,
|
|
20
|
+
// @ts-expect-error name is a standard property of Error
|
|
21
|
+
name: err.name, stack: err.stack }, err);
|
|
22
|
+
}
|
|
23
|
+
else if (typeof err === 'object' && err !== null) {
|
|
24
|
+
const plainObject = {};
|
|
25
|
+
for (const [key, value] of Object.entries(err)) {
|
|
26
|
+
plainObject[key] = value;
|
|
27
|
+
}
|
|
28
|
+
return plainObject;
|
|
29
|
+
}
|
|
30
|
+
return { message: String(err) };
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
exports.serializeErrorForTransport = serializeErrorForTransport;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the shape of a serialized error object.
|
|
3
|
+
*/
|
|
4
|
+
export type SerializedError = {
|
|
5
|
+
message?: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
stack?: string;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Serializes an error to a JSON object to be sent by transport.
|
|
12
|
+
* This function checks if the input is an instance of Error to capture
|
|
13
|
+
* standard properties like message, name, and stack. It also attempts to
|
|
14
|
+
* serialize any enumerable properties that are present on error-like objects.
|
|
15
|
+
*
|
|
16
|
+
* @param {unknown} err - The error or error-like object to serialize.
|
|
17
|
+
* @returns {SerializedError} - The serialized error object.
|
|
18
|
+
*/
|
|
19
|
+
export declare const serializeErrorForTransport: (err: unknown) => SerializedError;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
/**
|
|
3
|
+
* Serializes an error to a JSON object to be sent by transport.
|
|
4
|
+
* This function checks if the input is an instance of Error to capture
|
|
5
|
+
* standard properties like message, name, and stack. It also attempts to
|
|
6
|
+
* serialize any enumerable properties that are present on error-like objects.
|
|
7
|
+
*
|
|
8
|
+
* @param {unknown} err - The error or error-like object to serialize.
|
|
9
|
+
* @returns {SerializedError} - The serialized error object.
|
|
10
|
+
*/
|
|
11
|
+
const serializeErrorForTransport = (err) => {
|
|
12
|
+
if (err instanceof Error) {
|
|
13
|
+
return Object.assign({
|
|
14
|
+
// @ts-expect-error message is a standard property of Error
|
|
15
|
+
message: err.message,
|
|
16
|
+
// @ts-expect-error name is a standard property of Error
|
|
17
|
+
name: err.name, stack: err.stack }, err);
|
|
18
|
+
}
|
|
19
|
+
else if (typeof err === 'object' && err !== null) {
|
|
20
|
+
const plainObject = {};
|
|
21
|
+
for (const [key, value] of Object.entries(err)) {
|
|
22
|
+
plainObject[key] = value;
|
|
23
|
+
}
|
|
24
|
+
return plainObject;
|
|
25
|
+
}
|
|
26
|
+
return { message: String(err) };
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { serializeErrorForTransport };
|