@dynamic-labs-sdk/client 0.0.1-alpha.3 → 0.0.1-alpha.4
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 +10 -0
- package/core.cjs.js +9 -5
- package/core.esm.js +2 -2
- package/getClient.cjs.js +226 -0
- package/getClient.esm.js +210 -0
- package/index.cjs.js +38 -152
- package/index.esm.js +11 -128
- package/package.json +1 -1
- package/src/client/core/createCore/{initialState.d.ts → getInitialState.d.ts} +2 -2
- package/src/client/core/createCore/getInitialState.d.ts.map +1 -0
- package/src/exports/core.d.ts +4 -0
- package/src/exports/core.d.ts.map +1 -1
- package/src/exports/index.d.ts +4 -1
- package/src/exports/index.d.ts.map +1 -1
- package/src/utils/getClient/errors/ClientNotPresentError.d.ts.map +1 -0
- package/events.cjs.js +0 -101
- package/events.esm.js +0 -93
- package/src/client/core/createCore/initialState.d.ts.map +0 -1
- package/src/utils/getClient/erros/ClientNotPresentError.d.ts.map +0 -1
- /package/src/utils/getClient/{erros → errors}/ClientNotPresentError.d.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## 0.0.1-alpha.4 (2025-05-28)
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- allow manual init of client ([#88](https://github.com/dynamic-labs/dynamic-sdk/pull/88))
|
|
6
|
+
|
|
7
|
+
### 🩹 Fixes
|
|
8
|
+
|
|
9
|
+
- client core accidentally sharing state among different instances ([#89](https://github.com/dynamic-labs/dynamic-sdk/pull/89))
|
|
10
|
+
|
|
1
11
|
## 0.0.1-alpha.3 (2025-05-27)
|
|
2
12
|
|
|
3
13
|
### 🩹 Fixes
|
package/core.cjs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var getClient = require('./getClient.cjs.js');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Registers an extension to the client.
|
|
@@ -12,11 +12,15 @@ var events = require('./events.cjs.js');
|
|
|
12
12
|
* @param extensionKey - The key of the extension to register.
|
|
13
13
|
* @returns The client instance.
|
|
14
14
|
*/ const registerExtension = (client, extensionKey)=>{
|
|
15
|
-
const core =
|
|
15
|
+
const core = getClient.getCore(client);
|
|
16
16
|
core.extensions.add(extensionKey);
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
exports.
|
|
20
|
-
exports.
|
|
21
|
-
exports.
|
|
19
|
+
exports.CannotTrackError = getClient.CannotTrackError;
|
|
20
|
+
exports.ClientNotPresentError = getClient.ClientNotPresentError;
|
|
21
|
+
exports.InvalidStorageSet = getClient.InvalidStorageSet;
|
|
22
|
+
exports.emitEvent = getClient.emitEvent;
|
|
23
|
+
exports.getClient = getClient.getClient;
|
|
24
|
+
exports.getCore = getClient.getCore;
|
|
25
|
+
exports.subscribeWithSelector = getClient.subscribeWithSelector;
|
|
22
26
|
exports.registerExtension = registerExtension;
|
package/core.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as getCore } from './
|
|
2
|
-
export { e as emitEvent, s as subscribeWithSelector } from './
|
|
1
|
+
import { g as getCore } from './getClient.esm.js';
|
|
2
|
+
export { C as CannotTrackError, f as ClientNotPresentError, I as InvalidStorageSet, e as emitEvent, a as getClient, s as subscribeWithSelector } from './getClient.esm.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Registers an extension to the client.
|
package/getClient.cjs.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const getCore = (client)=>{
|
|
4
|
+
// @ts-expect-error - this was hidden from the public API
|
|
5
|
+
return client.__core;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Shallow compare two objects.
|
|
10
|
+
*
|
|
11
|
+
* Source: https://github.com/pmndrs/zustand/blob/main/src/vanilla/shallow.ts
|
|
12
|
+
*/ const isEqualShallow = (objA, objB)=>{
|
|
13
|
+
if (Object.is(objA, objB)) return true;
|
|
14
|
+
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
15
|
+
return objA === objB;
|
|
16
|
+
}
|
|
17
|
+
if (objA instanceof Map && objB instanceof Map) {
|
|
18
|
+
if (objA.size !== objB.size) return false;
|
|
19
|
+
for (const [key, value] of objA){
|
|
20
|
+
if (!Object.is(value, objB.get(key))) return false;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
if (objA instanceof Set && objB instanceof Set) {
|
|
25
|
+
if (objA.size !== objB.size) return false;
|
|
26
|
+
for (const value of objA){
|
|
27
|
+
if (!objB.has(value)) return false;
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
const keysA = Object.keys(objA);
|
|
32
|
+
if (keysA.length !== Object.keys(objB).length) return false;
|
|
33
|
+
for (const keyA of keysA){
|
|
34
|
+
if (!Object.prototype.hasOwnProperty.call(objB, keyA) || !Object.is(objA[keyA], objB[keyA])) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (objA.constructor !== objB.constructor) return false;
|
|
39
|
+
return true;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Allows subscribing to a slice of the state.
|
|
44
|
+
* The slice is a computation of the states.
|
|
45
|
+
*
|
|
46
|
+
* The callback will only be called when the slice has changed.
|
|
47
|
+
* Change is determined by shallow comparison.
|
|
48
|
+
*
|
|
49
|
+
* Returns a function to unsubscribe the callback.
|
|
50
|
+
*/ const subscribeWithSelector = (observable, selector)=>(callback)=>{
|
|
51
|
+
let lastSlice = selector(observable.get());
|
|
52
|
+
return observable.subscribe((value)=>{
|
|
53
|
+
const nextSlice = selector(value);
|
|
54
|
+
if (isEqualShallow(nextSlice, lastSlice)) return;
|
|
55
|
+
lastSlice = nextSlice;
|
|
56
|
+
callback(nextSlice);
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
function _extends() {
|
|
61
|
+
_extends = Object.assign || function assign(target) {
|
|
62
|
+
for(var i = 1; i < arguments.length; i++){
|
|
63
|
+
var source = arguments[i];
|
|
64
|
+
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
65
|
+
}
|
|
66
|
+
return target;
|
|
67
|
+
};
|
|
68
|
+
return _extends.apply(this, arguments);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
var version = "0.0.1-alpha.4";
|
|
72
|
+
var dependencies = {
|
|
73
|
+
"@dynamic-labs/sdk-api-core": "0.0.630"};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Listen to an event from the client.
|
|
77
|
+
*
|
|
78
|
+
* @returns A function that can be called to remove the listener.
|
|
79
|
+
*/ const onEvent = (client, event, listener)=>{
|
|
80
|
+
const { eventEmitter } = getCore(client);
|
|
81
|
+
eventEmitter.on(event, listener);
|
|
82
|
+
return ()=>{
|
|
83
|
+
eventEmitter.off(event, listener);
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Remove a listener from an event.
|
|
88
|
+
*/ const offEvent = (client, event, listener)=>{
|
|
89
|
+
const { eventEmitter } = getCore(client);
|
|
90
|
+
eventEmitter.off(event, listener);
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Listen to an event that will only fire once.
|
|
94
|
+
*
|
|
95
|
+
* @returns A function that can be called to remove the listener.
|
|
96
|
+
*/ const onceEvent = (client, event, listener)=>{
|
|
97
|
+
const { eventEmitter } = getCore(client);
|
|
98
|
+
eventEmitter.once(event, listener);
|
|
99
|
+
return ()=>{
|
|
100
|
+
eventEmitter.off(event, listener);
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Emit an event.
|
|
105
|
+
*/ const emitEvent = (client, event, ...args)=>{
|
|
106
|
+
const { eventEmitter } = getCore(client);
|
|
107
|
+
eventEmitter.emit(event, ...args);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const getDetails = ({ details, cause })=>{
|
|
111
|
+
if (cause instanceof BaseError) {
|
|
112
|
+
return cause.details;
|
|
113
|
+
}
|
|
114
|
+
if (cause == null ? void 0 : cause.message) {
|
|
115
|
+
return cause.message;
|
|
116
|
+
}
|
|
117
|
+
return details;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Formats the error message with all available information
|
|
121
|
+
*/ const formatMessage = ({ shortMessage, details, docsUrl, metaMessages })=>{
|
|
122
|
+
return [
|
|
123
|
+
shortMessage,
|
|
124
|
+
'',
|
|
125
|
+
...metaMessages ? [
|
|
126
|
+
...metaMessages,
|
|
127
|
+
''
|
|
128
|
+
] : [],
|
|
129
|
+
...docsUrl ? [
|
|
130
|
+
`Docs: ${docsUrl}`
|
|
131
|
+
] : [],
|
|
132
|
+
...details ? [
|
|
133
|
+
`Details: ${details}`
|
|
134
|
+
] : [],
|
|
135
|
+
`Version: ${version}`,
|
|
136
|
+
`Timestamp: ${new Date().toISOString()}`
|
|
137
|
+
].join('\n');
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Base error class that provides structured error handling with detailed information
|
|
141
|
+
*/ class BaseError extends Error {
|
|
142
|
+
/**
|
|
143
|
+
* Walks the cause chain of the error and returns the root error
|
|
144
|
+
*/ walk() {
|
|
145
|
+
const cause = this.cause;
|
|
146
|
+
if (cause instanceof BaseError) {
|
|
147
|
+
return cause.walk();
|
|
148
|
+
}
|
|
149
|
+
return cause;
|
|
150
|
+
}
|
|
151
|
+
constructor(args){
|
|
152
|
+
const details = getDetails(args);
|
|
153
|
+
super(formatMessage(_extends({}, args, {
|
|
154
|
+
details
|
|
155
|
+
})), args.cause ? {
|
|
156
|
+
cause: args.cause
|
|
157
|
+
} : undefined);
|
|
158
|
+
this.name = 'BaseError';
|
|
159
|
+
this.details = details;
|
|
160
|
+
var _args_name;
|
|
161
|
+
this.name = (_args_name = args.name) != null ? _args_name : this.name;
|
|
162
|
+
var _args_cause;
|
|
163
|
+
this.cause = (_args_cause = args.cause) != null ? _args_cause : this.cause;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
class CannotTrackError extends BaseError {
|
|
168
|
+
constructor(){
|
|
169
|
+
super({
|
|
170
|
+
cause: null,
|
|
171
|
+
docsUrl: null,
|
|
172
|
+
name: 'CannotTrackError',
|
|
173
|
+
shortMessage: 'All track calls must be performed in the same node tick'
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
class InvalidStorageSet extends BaseError {
|
|
179
|
+
constructor({ key, value }){
|
|
180
|
+
super({
|
|
181
|
+
cause: null,
|
|
182
|
+
docsUrl: null,
|
|
183
|
+
metaMessages: [
|
|
184
|
+
`key: ${key}`,
|
|
185
|
+
value
|
|
186
|
+
],
|
|
187
|
+
name: 'InvalidStorageSet',
|
|
188
|
+
shortMessage: 'Tried to store a value that does not match the schema'
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
class ClientNotPresentError extends BaseError {
|
|
194
|
+
constructor(){
|
|
195
|
+
super({
|
|
196
|
+
cause: null,
|
|
197
|
+
docsUrl: null,
|
|
198
|
+
name: 'ClientNotPresentError',
|
|
199
|
+
shortMessage: 'The client is not present in the target object.'
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const getClient = (target)=>{
|
|
205
|
+
if (!Object.prototype.hasOwnProperty.call(target, '__client')) {
|
|
206
|
+
throw new ClientNotPresentError();
|
|
207
|
+
}
|
|
208
|
+
// @ts-expect-error - this was hidden from the public API
|
|
209
|
+
return target.__client;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
exports.BaseError = BaseError;
|
|
213
|
+
exports.CannotTrackError = CannotTrackError;
|
|
214
|
+
exports.ClientNotPresentError = ClientNotPresentError;
|
|
215
|
+
exports.InvalidStorageSet = InvalidStorageSet;
|
|
216
|
+
exports._extends = _extends;
|
|
217
|
+
exports.dependencies = dependencies;
|
|
218
|
+
exports.emitEvent = emitEvent;
|
|
219
|
+
exports.getClient = getClient;
|
|
220
|
+
exports.getCore = getCore;
|
|
221
|
+
exports.isEqualShallow = isEqualShallow;
|
|
222
|
+
exports.offEvent = offEvent;
|
|
223
|
+
exports.onEvent = onEvent;
|
|
224
|
+
exports.onceEvent = onceEvent;
|
|
225
|
+
exports.subscribeWithSelector = subscribeWithSelector;
|
|
226
|
+
exports.version = version;
|
package/getClient.esm.js
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
const getCore = (client)=>{
|
|
2
|
+
// @ts-expect-error - this was hidden from the public API
|
|
3
|
+
return client.__core;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Shallow compare two objects.
|
|
8
|
+
*
|
|
9
|
+
* Source: https://github.com/pmndrs/zustand/blob/main/src/vanilla/shallow.ts
|
|
10
|
+
*/ const isEqualShallow = (objA, objB)=>{
|
|
11
|
+
if (Object.is(objA, objB)) return true;
|
|
12
|
+
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
13
|
+
return objA === objB;
|
|
14
|
+
}
|
|
15
|
+
if (objA instanceof Map && objB instanceof Map) {
|
|
16
|
+
if (objA.size !== objB.size) return false;
|
|
17
|
+
for (const [key, value] of objA){
|
|
18
|
+
if (!Object.is(value, objB.get(key))) return false;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
if (objA instanceof Set && objB instanceof Set) {
|
|
23
|
+
if (objA.size !== objB.size) return false;
|
|
24
|
+
for (const value of objA){
|
|
25
|
+
if (!objB.has(value)) return false;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
const keysA = Object.keys(objA);
|
|
30
|
+
if (keysA.length !== Object.keys(objB).length) return false;
|
|
31
|
+
for (const keyA of keysA){
|
|
32
|
+
if (!Object.prototype.hasOwnProperty.call(objB, keyA) || !Object.is(objA[keyA], objB[keyA])) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (objA.constructor !== objB.constructor) return false;
|
|
37
|
+
return true;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Allows subscribing to a slice of the state.
|
|
42
|
+
* The slice is a computation of the states.
|
|
43
|
+
*
|
|
44
|
+
* The callback will only be called when the slice has changed.
|
|
45
|
+
* Change is determined by shallow comparison.
|
|
46
|
+
*
|
|
47
|
+
* Returns a function to unsubscribe the callback.
|
|
48
|
+
*/ const subscribeWithSelector = (observable, selector)=>(callback)=>{
|
|
49
|
+
let lastSlice = selector(observable.get());
|
|
50
|
+
return observable.subscribe((value)=>{
|
|
51
|
+
const nextSlice = selector(value);
|
|
52
|
+
if (isEqualShallow(nextSlice, lastSlice)) return;
|
|
53
|
+
lastSlice = nextSlice;
|
|
54
|
+
callback(nextSlice);
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
function _extends() {
|
|
59
|
+
_extends = Object.assign || function assign(target) {
|
|
60
|
+
for(var i = 1; i < arguments.length; i++){
|
|
61
|
+
var source = arguments[i];
|
|
62
|
+
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
63
|
+
}
|
|
64
|
+
return target;
|
|
65
|
+
};
|
|
66
|
+
return _extends.apply(this, arguments);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
var version = "0.0.1-alpha.4";
|
|
70
|
+
var dependencies = {
|
|
71
|
+
"@dynamic-labs/sdk-api-core": "0.0.630"};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Listen to an event from the client.
|
|
75
|
+
*
|
|
76
|
+
* @returns A function that can be called to remove the listener.
|
|
77
|
+
*/ const onEvent = (client, event, listener)=>{
|
|
78
|
+
const { eventEmitter } = getCore(client);
|
|
79
|
+
eventEmitter.on(event, listener);
|
|
80
|
+
return ()=>{
|
|
81
|
+
eventEmitter.off(event, listener);
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Remove a listener from an event.
|
|
86
|
+
*/ const offEvent = (client, event, listener)=>{
|
|
87
|
+
const { eventEmitter } = getCore(client);
|
|
88
|
+
eventEmitter.off(event, listener);
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Listen to an event that will only fire once.
|
|
92
|
+
*
|
|
93
|
+
* @returns A function that can be called to remove the listener.
|
|
94
|
+
*/ const onceEvent = (client, event, listener)=>{
|
|
95
|
+
const { eventEmitter } = getCore(client);
|
|
96
|
+
eventEmitter.once(event, listener);
|
|
97
|
+
return ()=>{
|
|
98
|
+
eventEmitter.off(event, listener);
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Emit an event.
|
|
103
|
+
*/ const emitEvent = (client, event, ...args)=>{
|
|
104
|
+
const { eventEmitter } = getCore(client);
|
|
105
|
+
eventEmitter.emit(event, ...args);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const getDetails = ({ details, cause })=>{
|
|
109
|
+
if (cause instanceof BaseError) {
|
|
110
|
+
return cause.details;
|
|
111
|
+
}
|
|
112
|
+
if (cause == null ? void 0 : cause.message) {
|
|
113
|
+
return cause.message;
|
|
114
|
+
}
|
|
115
|
+
return details;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Formats the error message with all available information
|
|
119
|
+
*/ const formatMessage = ({ shortMessage, details, docsUrl, metaMessages })=>{
|
|
120
|
+
return [
|
|
121
|
+
shortMessage,
|
|
122
|
+
'',
|
|
123
|
+
...metaMessages ? [
|
|
124
|
+
...metaMessages,
|
|
125
|
+
''
|
|
126
|
+
] : [],
|
|
127
|
+
...docsUrl ? [
|
|
128
|
+
`Docs: ${docsUrl}`
|
|
129
|
+
] : [],
|
|
130
|
+
...details ? [
|
|
131
|
+
`Details: ${details}`
|
|
132
|
+
] : [],
|
|
133
|
+
`Version: ${version}`,
|
|
134
|
+
`Timestamp: ${new Date().toISOString()}`
|
|
135
|
+
].join('\n');
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Base error class that provides structured error handling with detailed information
|
|
139
|
+
*/ class BaseError extends Error {
|
|
140
|
+
/**
|
|
141
|
+
* Walks the cause chain of the error and returns the root error
|
|
142
|
+
*/ walk() {
|
|
143
|
+
const cause = this.cause;
|
|
144
|
+
if (cause instanceof BaseError) {
|
|
145
|
+
return cause.walk();
|
|
146
|
+
}
|
|
147
|
+
return cause;
|
|
148
|
+
}
|
|
149
|
+
constructor(args){
|
|
150
|
+
const details = getDetails(args);
|
|
151
|
+
super(formatMessage(_extends({}, args, {
|
|
152
|
+
details
|
|
153
|
+
})), args.cause ? {
|
|
154
|
+
cause: args.cause
|
|
155
|
+
} : undefined);
|
|
156
|
+
this.name = 'BaseError';
|
|
157
|
+
this.details = details;
|
|
158
|
+
var _args_name;
|
|
159
|
+
this.name = (_args_name = args.name) != null ? _args_name : this.name;
|
|
160
|
+
var _args_cause;
|
|
161
|
+
this.cause = (_args_cause = args.cause) != null ? _args_cause : this.cause;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
class CannotTrackError extends BaseError {
|
|
166
|
+
constructor(){
|
|
167
|
+
super({
|
|
168
|
+
cause: null,
|
|
169
|
+
docsUrl: null,
|
|
170
|
+
name: 'CannotTrackError',
|
|
171
|
+
shortMessage: 'All track calls must be performed in the same node tick'
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
class InvalidStorageSet extends BaseError {
|
|
177
|
+
constructor({ key, value }){
|
|
178
|
+
super({
|
|
179
|
+
cause: null,
|
|
180
|
+
docsUrl: null,
|
|
181
|
+
metaMessages: [
|
|
182
|
+
`key: ${key}`,
|
|
183
|
+
value
|
|
184
|
+
],
|
|
185
|
+
name: 'InvalidStorageSet',
|
|
186
|
+
shortMessage: 'Tried to store a value that does not match the schema'
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
class ClientNotPresentError extends BaseError {
|
|
192
|
+
constructor(){
|
|
193
|
+
super({
|
|
194
|
+
cause: null,
|
|
195
|
+
docsUrl: null,
|
|
196
|
+
name: 'ClientNotPresentError',
|
|
197
|
+
shortMessage: 'The client is not present in the target object.'
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const getClient = (target)=>{
|
|
203
|
+
if (!Object.prototype.hasOwnProperty.call(target, '__client')) {
|
|
204
|
+
throw new ClientNotPresentError();
|
|
205
|
+
}
|
|
206
|
+
// @ts-expect-error - this was hidden from the public API
|
|
207
|
+
return target.__client;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export { BaseError as B, CannotTrackError as C, InvalidStorageSet as I, _extends as _, getClient as a, onceEvent as b, onEvent as c, dependencies as d, emitEvent as e, ClientNotPresentError as f, getCore as g, isEqualShallow as i, offEvent as o, subscribeWithSelector as s, version as v };
|
package/index.cjs.js
CHANGED
|
@@ -1,43 +1,28 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var getClient = require('./getClient.cjs.js');
|
|
4
4
|
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
5
5
|
var mini = require('@zod/mini');
|
|
6
6
|
var EventEmitter = require('eventemitter3');
|
|
7
7
|
|
|
8
|
-
function _extends() {
|
|
9
|
-
_extends = Object.assign || function assign(target) {
|
|
10
|
-
for(var i = 1; i < arguments.length; i++){
|
|
11
|
-
var source = arguments[i];
|
|
12
|
-
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
13
|
-
}
|
|
14
|
-
return target;
|
|
15
|
-
};
|
|
16
|
-
return _extends.apply(this, arguments);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
var version = "0.0.1-alpha.3";
|
|
20
|
-
var dependencies = {
|
|
21
|
-
"@dynamic-labs/sdk-api-core": "0.0.630"};
|
|
22
|
-
|
|
23
8
|
/**
|
|
24
9
|
* Returns a new instance of the SDK API client.
|
|
25
10
|
*
|
|
26
11
|
* This is not meant for storing, as it is very light we can create it whenever needed.
|
|
27
12
|
*/ const createApiClient = (client)=>{
|
|
28
|
-
const core =
|
|
13
|
+
const core = getClient.getCore(client);
|
|
29
14
|
const settings = {
|
|
30
15
|
basePath: core.apiBaseUrl,
|
|
31
16
|
headers: {
|
|
32
17
|
'Content-Type': 'application/json',
|
|
33
|
-
'x-dyn-api-version': dependencies['@dynamic-labs/sdk-api-core'],
|
|
18
|
+
'x-dyn-api-version': getClient.dependencies['@dynamic-labs/sdk-api-core'],
|
|
34
19
|
'x-dyn-version': core.version
|
|
35
20
|
}
|
|
36
21
|
};
|
|
37
22
|
if (client.token) {
|
|
38
23
|
settings.headers.Authorization = `Bearer ${client.token}`;
|
|
39
24
|
}
|
|
40
|
-
return new sdkApiCore.SDKApi(new sdkApiCore.Configuration(_extends({}, settings, {
|
|
25
|
+
return new sdkApiCore.SDKApi(new sdkApiCore.Configuration(getClient._extends({}, settings, {
|
|
41
26
|
fetchApi: core.fetch
|
|
42
27
|
})));
|
|
43
28
|
};
|
|
@@ -45,7 +30,7 @@ var dependencies = {
|
|
|
45
30
|
/**
|
|
46
31
|
* Updates the project settings in the core state to the latest values.
|
|
47
32
|
*/ const fetchProjectSettings = async (client)=>{
|
|
48
|
-
const core =
|
|
33
|
+
const core = getClient.getCore(client);
|
|
49
34
|
const apiClient = createApiClient(client);
|
|
50
35
|
const projectSettings = await apiClient.getEnvironmentSettings({
|
|
51
36
|
environmentId: core.environmentId,
|
|
@@ -60,7 +45,7 @@ var dependencies = {
|
|
|
60
45
|
};
|
|
61
46
|
|
|
62
47
|
const logout = async (client)=>{
|
|
63
|
-
const core =
|
|
48
|
+
const core = getClient.getCore(client);
|
|
64
49
|
const apiClient = createApiClient(client);
|
|
65
50
|
await apiClient.revokeSession({
|
|
66
51
|
environmentId: core.environmentId
|
|
@@ -70,7 +55,7 @@ const logout = async (client)=>{
|
|
|
70
55
|
token: null,
|
|
71
56
|
user: null
|
|
72
57
|
});
|
|
73
|
-
|
|
58
|
+
getClient.emitEvent(client, 'logout');
|
|
74
59
|
// Refetch project settings
|
|
75
60
|
void fetchProjectSettings(client);
|
|
76
61
|
};
|
|
@@ -103,9 +88,9 @@ const logout = async (client)=>{
|
|
|
103
88
|
/**
|
|
104
89
|
* Sets up a timeout to log out the user when their token expires.
|
|
105
90
|
*/ const initializeAuth = (client)=>{
|
|
106
|
-
const core =
|
|
91
|
+
const core = getClient.getCore(client);
|
|
107
92
|
let clearExpirationTimeout = null;
|
|
108
|
-
const onChangeExpiration =
|
|
93
|
+
const onChangeExpiration = getClient.subscribeWithSelector(core.state, (state)=>state.sessionExpiresAt);
|
|
109
94
|
const checkExpiration = ()=>{
|
|
110
95
|
const expiration = core.state.get().sessionExpiresAt;
|
|
111
96
|
clearExpirationTimeout == null ? void 0 : clearExpirationTimeout();
|
|
@@ -138,18 +123,18 @@ const logout = async (client)=>{
|
|
|
138
123
|
};
|
|
139
124
|
|
|
140
125
|
const raiseStateEvents = (client)=>{
|
|
141
|
-
const core =
|
|
126
|
+
const core = getClient.getCore(client);
|
|
142
127
|
core.state.subscribe((value, previous)=>{
|
|
143
128
|
const eventEntries = Object.entries(stateChangeEvents);
|
|
144
129
|
eventEntries.forEach(([key, event])=>{
|
|
145
130
|
// Check if this key had a change
|
|
146
|
-
if (
|
|
131
|
+
if (getClient.isEqualShallow(value[key], previous[key])) return;
|
|
147
132
|
core.eventEmitter.emit(event, value[key], previous[key]);
|
|
148
133
|
});
|
|
149
134
|
});
|
|
150
135
|
};
|
|
151
136
|
|
|
152
|
-
const SDK_API_CORE_VERSION = dependencies['@dynamic-labs/sdk-api-core'];
|
|
137
|
+
const SDK_API_CORE_VERSION = getClient.dependencies['@dynamic-labs/sdk-api-core'];
|
|
153
138
|
|
|
154
139
|
const createStorageKeySchema = (params)=>{
|
|
155
140
|
return params;
|
|
@@ -177,7 +162,7 @@ const stateStorageKeySchema = createStorageKeySchema({
|
|
|
177
162
|
});
|
|
178
163
|
|
|
179
164
|
const hydrateStateWithStorage = async (client)=>{
|
|
180
|
-
const core =
|
|
165
|
+
const core = getClient.getCore(client);
|
|
181
166
|
const stateChanges = {};
|
|
182
167
|
// ================ TOKEN =================
|
|
183
168
|
const session = await core.storage.getItem(sessionKeySchema);
|
|
@@ -204,7 +189,7 @@ const hydrateStateWithStorage = async (client)=>{
|
|
|
204
189
|
};
|
|
205
190
|
|
|
206
191
|
const syncStateWithStorage = (client)=>{
|
|
207
|
-
const core =
|
|
192
|
+
const core = getClient.getCore(client);
|
|
208
193
|
core.state.subscribe((state)=>{
|
|
209
194
|
if (state.sessionExpiresAt === null) {
|
|
210
195
|
void core.storage.removeItem(sessionKeySchema);
|
|
@@ -230,64 +215,7 @@ const initializeStorageSync = async (client)=>{
|
|
|
230
215
|
syncStateWithStorage(client);
|
|
231
216
|
};
|
|
232
217
|
|
|
233
|
-
|
|
234
|
-
if (cause instanceof BaseError) {
|
|
235
|
-
return cause.details;
|
|
236
|
-
}
|
|
237
|
-
if (cause == null ? void 0 : cause.message) {
|
|
238
|
-
return cause.message;
|
|
239
|
-
}
|
|
240
|
-
return details;
|
|
241
|
-
};
|
|
242
|
-
/**
|
|
243
|
-
* Formats the error message with all available information
|
|
244
|
-
*/ const formatMessage = ({ shortMessage, details, docsUrl, metaMessages })=>{
|
|
245
|
-
return [
|
|
246
|
-
shortMessage,
|
|
247
|
-
'',
|
|
248
|
-
...metaMessages ? [
|
|
249
|
-
...metaMessages,
|
|
250
|
-
''
|
|
251
|
-
] : [],
|
|
252
|
-
...docsUrl ? [
|
|
253
|
-
`Docs: ${docsUrl}`
|
|
254
|
-
] : [],
|
|
255
|
-
...details ? [
|
|
256
|
-
`Details: ${details}`
|
|
257
|
-
] : [],
|
|
258
|
-
`Version: ${version}`,
|
|
259
|
-
`Timestamp: ${new Date().toISOString()}`
|
|
260
|
-
].join('\n');
|
|
261
|
-
};
|
|
262
|
-
/**
|
|
263
|
-
* Base error class that provides structured error handling with detailed information
|
|
264
|
-
*/ class BaseError extends Error {
|
|
265
|
-
/**
|
|
266
|
-
* Walks the cause chain of the error and returns the root error
|
|
267
|
-
*/ walk() {
|
|
268
|
-
const cause = this.cause;
|
|
269
|
-
if (cause instanceof BaseError) {
|
|
270
|
-
return cause.walk();
|
|
271
|
-
}
|
|
272
|
-
return cause;
|
|
273
|
-
}
|
|
274
|
-
constructor(args){
|
|
275
|
-
const details = getDetails(args);
|
|
276
|
-
super(formatMessage(_extends({}, args, {
|
|
277
|
-
details
|
|
278
|
-
})), args.cause ? {
|
|
279
|
-
cause: args.cause
|
|
280
|
-
} : undefined);
|
|
281
|
-
this.name = 'BaseError';
|
|
282
|
-
this.details = details;
|
|
283
|
-
var _args_name;
|
|
284
|
-
this.name = (_args_name = args.name) != null ? _args_name : this.name;
|
|
285
|
-
var _args_cause;
|
|
286
|
-
this.cause = (_args_cause = args.cause) != null ? _args_cause : this.cause;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
class ClientAlreadyInitializedError extends BaseError {
|
|
218
|
+
class ClientAlreadyInitializedError extends getClient.BaseError {
|
|
291
219
|
constructor(){
|
|
292
220
|
super({
|
|
293
221
|
cause: null,
|
|
@@ -302,7 +230,7 @@ class ClientAlreadyInitializedError extends BaseError {
|
|
|
302
230
|
* Orchestrates the initialization of all modules and services of the SDK, and keeps
|
|
303
231
|
* the loading flag updated.
|
|
304
232
|
*/ const initializeClient = async (client)=>{
|
|
305
|
-
const core =
|
|
233
|
+
const core = getClient.getCore(client);
|
|
306
234
|
if (core.state.get().initStatus !== 'uninitialized') {
|
|
307
235
|
throw new ClientAlreadyInitializedError();
|
|
308
236
|
}
|
|
@@ -352,17 +280,6 @@ const createDeferredPromise = ()=>{
|
|
|
352
280
|
};
|
|
353
281
|
};
|
|
354
282
|
|
|
355
|
-
class CannotTrackError extends BaseError {
|
|
356
|
-
constructor(){
|
|
357
|
-
super({
|
|
358
|
-
cause: null,
|
|
359
|
-
docsUrl: null,
|
|
360
|
-
name: 'CannotTrackError',
|
|
361
|
-
shortMessage: 'All track calls must be performed in the same node tick'
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
283
|
/**
|
|
367
284
|
* Creates a tracker that associates names with promises and raises as promises resolve.
|
|
368
285
|
*/ const createAsyncTrack = ()=>{
|
|
@@ -384,7 +301,7 @@ class CannotTrackError extends BaseError {
|
|
|
384
301
|
};
|
|
385
302
|
const track = ({ name, promise })=>{
|
|
386
303
|
if (!isTrackEnabled) {
|
|
387
|
-
throw new CannotTrackError();
|
|
304
|
+
throw new getClient.CannotTrackError();
|
|
388
305
|
}
|
|
389
306
|
// Disable tracking in the next node tick
|
|
390
307
|
void Promise.resolve().then(()=>isTrackEnabled = false);
|
|
@@ -469,21 +386,6 @@ const defaultConsole = console;
|
|
|
469
386
|
};
|
|
470
387
|
};
|
|
471
388
|
|
|
472
|
-
class InvalidStorageSet extends BaseError {
|
|
473
|
-
constructor({ key, value }){
|
|
474
|
-
super({
|
|
475
|
-
cause: null,
|
|
476
|
-
docsUrl: null,
|
|
477
|
-
metaMessages: [
|
|
478
|
-
`key: ${key}`,
|
|
479
|
-
value
|
|
480
|
-
],
|
|
481
|
-
name: 'InvalidStorageSet',
|
|
482
|
-
shortMessage: 'Tried to store a value that does not match the schema'
|
|
483
|
-
});
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
|
|
487
389
|
const formatForStorage = (value)=>{
|
|
488
390
|
const item = {
|
|
489
391
|
value
|
|
@@ -529,7 +431,7 @@ const parseFromStorage = (value)=>{
|
|
|
529
431
|
setItem: async (storageKeySchema, value)=>{
|
|
530
432
|
const parsed = storageKeySchema.schema.safeParse(value);
|
|
531
433
|
if (!parsed.success) {
|
|
532
|
-
throw new InvalidStorageSet({
|
|
434
|
+
throw new getClient.InvalidStorageSet({
|
|
533
435
|
key: storageKeySchema.key,
|
|
534
436
|
value: JSON.stringify(value)
|
|
535
437
|
});
|
|
@@ -580,13 +482,13 @@ const createObservableState = (getInitialState)=>{
|
|
|
580
482
|
|
|
581
483
|
/**
|
|
582
484
|
* The initial values for the state of the client.
|
|
583
|
-
*/ const
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
};
|
|
485
|
+
*/ const getInitialState = ()=>({
|
|
486
|
+
initStatus: 'uninitialized',
|
|
487
|
+
projectSettings: null,
|
|
488
|
+
sessionExpiresAt: null,
|
|
489
|
+
token: null,
|
|
490
|
+
user: null
|
|
491
|
+
});
|
|
590
492
|
|
|
591
493
|
/**
|
|
592
494
|
* Creates a core instance that contains all the services and state of the Dynamic SDK client.
|
|
@@ -604,7 +506,7 @@ const createObservableState = (getInitialState)=>{
|
|
|
604
506
|
const fetch = (_config_coreConfig_fetch = (_config_coreConfig3 = config.coreConfig) == null ? void 0 : _config_coreConfig3.fetch) != null ? _config_coreConfig_fetch : createWebFetch();
|
|
605
507
|
var _config_coreConfig_openDeeplink;
|
|
606
508
|
const openDeeplink = (_config_coreConfig_openDeeplink = (_config_coreConfig4 = config.coreConfig) == null ? void 0 : _config_coreConfig4.openDeeplink) != null ? _config_coreConfig_openDeeplink : createWebDeeplinkOpener();
|
|
607
|
-
const state = createObservableState(
|
|
509
|
+
const state = createObservableState(getInitialState);
|
|
608
510
|
const eventEmitter = createEventEmitter();
|
|
609
511
|
const initTrack = createAsyncTrack();
|
|
610
512
|
return {
|
|
@@ -618,7 +520,7 @@ const createObservableState = (getInitialState)=>{
|
|
|
618
520
|
openDeeplink,
|
|
619
521
|
state,
|
|
620
522
|
storage,
|
|
621
|
-
version
|
|
523
|
+
version: getClient.version
|
|
622
524
|
};
|
|
623
525
|
};
|
|
624
526
|
|
|
@@ -652,7 +554,7 @@ const createDynamicClient = (config)=>{
|
|
|
652
554
|
/**
|
|
653
555
|
* Checks if an extension has been applied to the client.
|
|
654
556
|
*/ const hasExtension = (client, extensionKey)=>{
|
|
655
|
-
const core =
|
|
557
|
+
const core = getClient.getCore(client);
|
|
656
558
|
return core.extensions.has(extensionKey);
|
|
657
559
|
};
|
|
658
560
|
|
|
@@ -666,27 +568,8 @@ const assignClient = (target, client)=>{
|
|
|
666
568
|
return target;
|
|
667
569
|
};
|
|
668
570
|
|
|
669
|
-
class ClientNotPresentError extends BaseError {
|
|
670
|
-
constructor(){
|
|
671
|
-
super({
|
|
672
|
-
cause: null,
|
|
673
|
-
docsUrl: null,
|
|
674
|
-
name: 'ClientNotPresentError',
|
|
675
|
-
shortMessage: 'The client is not present in the target object.'
|
|
676
|
-
});
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
const getClient = (target)=>{
|
|
681
|
-
if (!Object.prototype.hasOwnProperty.call(target, '__client')) {
|
|
682
|
-
throw new ClientNotPresentError();
|
|
683
|
-
}
|
|
684
|
-
// @ts-expect-error - this was hidden from the public API
|
|
685
|
-
return target.__client;
|
|
686
|
-
};
|
|
687
|
-
|
|
688
571
|
const sendEmailOTP = async (client, { email })=>{
|
|
689
|
-
const core =
|
|
572
|
+
const core = getClient.getCore(client);
|
|
690
573
|
const apiClient = createApiClient(client);
|
|
691
574
|
const { verificationUUID } = await apiClient.createEmailVerification({
|
|
692
575
|
emailVerificationCreateRequest: {
|
|
@@ -1625,7 +1508,7 @@ const supportedCountries = {
|
|
|
1625
1508
|
};
|
|
1626
1509
|
|
|
1627
1510
|
const sendSmsOTP = async (client, { isoCountryCode, phoneNumber })=>{
|
|
1628
|
-
const core =
|
|
1511
|
+
const core = getClient.getCore(client);
|
|
1629
1512
|
const apiClient = createApiClient(client);
|
|
1630
1513
|
const phoneCountryCode = supportedCountries[isoCountryCode].code;
|
|
1631
1514
|
const { verificationUUID } = await apiClient.createSmsVerification({
|
|
@@ -1645,8 +1528,8 @@ const sendSmsOTP = async (client, { isoCountryCode, phoneNumber })=>{
|
|
|
1645
1528
|
};
|
|
1646
1529
|
|
|
1647
1530
|
const verifyOTP = async (otpVerification, { verificationToken })=>{
|
|
1648
|
-
const client = getClient(otpVerification);
|
|
1649
|
-
const core =
|
|
1531
|
+
const client = getClient.getClient(otpVerification);
|
|
1532
|
+
const core = getClient.getCore(client);
|
|
1650
1533
|
const apiClient = createApiClient(client);
|
|
1651
1534
|
let response;
|
|
1652
1535
|
const verifyRequest = {
|
|
@@ -1674,11 +1557,14 @@ const verifyOTP = async (otpVerification, { verificationToken })=>{
|
|
|
1674
1557
|
return user;
|
|
1675
1558
|
};
|
|
1676
1559
|
|
|
1677
|
-
exports.
|
|
1678
|
-
exports.
|
|
1679
|
-
exports.
|
|
1560
|
+
exports.BaseError = getClient.BaseError;
|
|
1561
|
+
exports.offEvent = getClient.offEvent;
|
|
1562
|
+
exports.onEvent = getClient.onEvent;
|
|
1563
|
+
exports.onceEvent = getClient.onceEvent;
|
|
1564
|
+
exports.ClientAlreadyInitializedError = ClientAlreadyInitializedError;
|
|
1680
1565
|
exports.createDynamicClient = createDynamicClient;
|
|
1681
1566
|
exports.hasExtension = hasExtension;
|
|
1567
|
+
exports.initializeClient = initializeClient;
|
|
1682
1568
|
exports.logout = logout;
|
|
1683
1569
|
exports.sendEmailOTP = sendEmailOTP;
|
|
1684
1570
|
exports.sendSmsOTP = sendSmsOTP;
|
package/index.esm.js
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
1
|
-
import { g as getCore, e as emitEvent, s as subscribeWithSelector, i as isEqualShallow } from './
|
|
2
|
-
export { o as offEvent,
|
|
1
|
+
import { g as getCore, _ as _extends, d as dependencies, e as emitEvent, s as subscribeWithSelector, i as isEqualShallow, B as BaseError, C as CannotTrackError, I as InvalidStorageSet, v as version, a as getClient } from './getClient.esm.js';
|
|
2
|
+
export { o as offEvent, c as onEvent, b as onceEvent } from './getClient.esm.js';
|
|
3
3
|
import { SDKApi, Configuration } from '@dynamic-labs/sdk-api-core';
|
|
4
4
|
import { z } from '@zod/mini';
|
|
5
5
|
import EventEmitter$1, { EventEmitter } from 'eventemitter3';
|
|
6
6
|
|
|
7
|
-
function _extends() {
|
|
8
|
-
_extends = Object.assign || function assign(target) {
|
|
9
|
-
for(var i = 1; i < arguments.length; i++){
|
|
10
|
-
var source = arguments[i];
|
|
11
|
-
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
12
|
-
}
|
|
13
|
-
return target;
|
|
14
|
-
};
|
|
15
|
-
return _extends.apply(this, arguments);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
var version = "0.0.1-alpha.3";
|
|
19
|
-
var dependencies = {
|
|
20
|
-
"@dynamic-labs/sdk-api-core": "0.0.630"};
|
|
21
|
-
|
|
22
7
|
/**
|
|
23
8
|
* Returns a new instance of the SDK API client.
|
|
24
9
|
*
|
|
@@ -229,63 +214,6 @@ const initializeStorageSync = async (client)=>{
|
|
|
229
214
|
syncStateWithStorage(client);
|
|
230
215
|
};
|
|
231
216
|
|
|
232
|
-
const getDetails = ({ details, cause })=>{
|
|
233
|
-
if (cause instanceof BaseError) {
|
|
234
|
-
return cause.details;
|
|
235
|
-
}
|
|
236
|
-
if (cause == null ? void 0 : cause.message) {
|
|
237
|
-
return cause.message;
|
|
238
|
-
}
|
|
239
|
-
return details;
|
|
240
|
-
};
|
|
241
|
-
/**
|
|
242
|
-
* Formats the error message with all available information
|
|
243
|
-
*/ const formatMessage = ({ shortMessage, details, docsUrl, metaMessages })=>{
|
|
244
|
-
return [
|
|
245
|
-
shortMessage,
|
|
246
|
-
'',
|
|
247
|
-
...metaMessages ? [
|
|
248
|
-
...metaMessages,
|
|
249
|
-
''
|
|
250
|
-
] : [],
|
|
251
|
-
...docsUrl ? [
|
|
252
|
-
`Docs: ${docsUrl}`
|
|
253
|
-
] : [],
|
|
254
|
-
...details ? [
|
|
255
|
-
`Details: ${details}`
|
|
256
|
-
] : [],
|
|
257
|
-
`Version: ${version}`,
|
|
258
|
-
`Timestamp: ${new Date().toISOString()}`
|
|
259
|
-
].join('\n');
|
|
260
|
-
};
|
|
261
|
-
/**
|
|
262
|
-
* Base error class that provides structured error handling with detailed information
|
|
263
|
-
*/ class BaseError extends Error {
|
|
264
|
-
/**
|
|
265
|
-
* Walks the cause chain of the error and returns the root error
|
|
266
|
-
*/ walk() {
|
|
267
|
-
const cause = this.cause;
|
|
268
|
-
if (cause instanceof BaseError) {
|
|
269
|
-
return cause.walk();
|
|
270
|
-
}
|
|
271
|
-
return cause;
|
|
272
|
-
}
|
|
273
|
-
constructor(args){
|
|
274
|
-
const details = getDetails(args);
|
|
275
|
-
super(formatMessage(_extends({}, args, {
|
|
276
|
-
details
|
|
277
|
-
})), args.cause ? {
|
|
278
|
-
cause: args.cause
|
|
279
|
-
} : undefined);
|
|
280
|
-
this.name = 'BaseError';
|
|
281
|
-
this.details = details;
|
|
282
|
-
var _args_name;
|
|
283
|
-
this.name = (_args_name = args.name) != null ? _args_name : this.name;
|
|
284
|
-
var _args_cause;
|
|
285
|
-
this.cause = (_args_cause = args.cause) != null ? _args_cause : this.cause;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
217
|
class ClientAlreadyInitializedError extends BaseError {
|
|
290
218
|
constructor(){
|
|
291
219
|
super({
|
|
@@ -351,17 +279,6 @@ const createDeferredPromise = ()=>{
|
|
|
351
279
|
};
|
|
352
280
|
};
|
|
353
281
|
|
|
354
|
-
class CannotTrackError extends BaseError {
|
|
355
|
-
constructor(){
|
|
356
|
-
super({
|
|
357
|
-
cause: null,
|
|
358
|
-
docsUrl: null,
|
|
359
|
-
name: 'CannotTrackError',
|
|
360
|
-
shortMessage: 'All track calls must be performed in the same node tick'
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
282
|
/**
|
|
366
283
|
* Creates a tracker that associates names with promises and raises as promises resolve.
|
|
367
284
|
*/ const createAsyncTrack = ()=>{
|
|
@@ -468,21 +385,6 @@ const defaultConsole = console;
|
|
|
468
385
|
};
|
|
469
386
|
};
|
|
470
387
|
|
|
471
|
-
class InvalidStorageSet extends BaseError {
|
|
472
|
-
constructor({ key, value }){
|
|
473
|
-
super({
|
|
474
|
-
cause: null,
|
|
475
|
-
docsUrl: null,
|
|
476
|
-
metaMessages: [
|
|
477
|
-
`key: ${key}`,
|
|
478
|
-
value
|
|
479
|
-
],
|
|
480
|
-
name: 'InvalidStorageSet',
|
|
481
|
-
shortMessage: 'Tried to store a value that does not match the schema'
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
|
|
486
388
|
const formatForStorage = (value)=>{
|
|
487
389
|
const item = {
|
|
488
390
|
value
|
|
@@ -579,13 +481,13 @@ const createObservableState = (getInitialState)=>{
|
|
|
579
481
|
|
|
580
482
|
/**
|
|
581
483
|
* The initial values for the state of the client.
|
|
582
|
-
*/ const
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
};
|
|
484
|
+
*/ const getInitialState = ()=>({
|
|
485
|
+
initStatus: 'uninitialized',
|
|
486
|
+
projectSettings: null,
|
|
487
|
+
sessionExpiresAt: null,
|
|
488
|
+
token: null,
|
|
489
|
+
user: null
|
|
490
|
+
});
|
|
589
491
|
|
|
590
492
|
/**
|
|
591
493
|
* Creates a core instance that contains all the services and state of the Dynamic SDK client.
|
|
@@ -603,7 +505,7 @@ const createObservableState = (getInitialState)=>{
|
|
|
603
505
|
const fetch = (_config_coreConfig_fetch = (_config_coreConfig3 = config.coreConfig) == null ? void 0 : _config_coreConfig3.fetch) != null ? _config_coreConfig_fetch : createWebFetch();
|
|
604
506
|
var _config_coreConfig_openDeeplink;
|
|
605
507
|
const openDeeplink = (_config_coreConfig_openDeeplink = (_config_coreConfig4 = config.coreConfig) == null ? void 0 : _config_coreConfig4.openDeeplink) != null ? _config_coreConfig_openDeeplink : createWebDeeplinkOpener();
|
|
606
|
-
const state = createObservableState(
|
|
508
|
+
const state = createObservableState(getInitialState);
|
|
607
509
|
const eventEmitter = createEventEmitter();
|
|
608
510
|
const initTrack = createAsyncTrack();
|
|
609
511
|
return {
|
|
@@ -665,25 +567,6 @@ const assignClient = (target, client)=>{
|
|
|
665
567
|
return target;
|
|
666
568
|
};
|
|
667
569
|
|
|
668
|
-
class ClientNotPresentError extends BaseError {
|
|
669
|
-
constructor(){
|
|
670
|
-
super({
|
|
671
|
-
cause: null,
|
|
672
|
-
docsUrl: null,
|
|
673
|
-
name: 'ClientNotPresentError',
|
|
674
|
-
shortMessage: 'The client is not present in the target object.'
|
|
675
|
-
});
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
const getClient = (target)=>{
|
|
680
|
-
if (!Object.prototype.hasOwnProperty.call(target, '__client')) {
|
|
681
|
-
throw new ClientNotPresentError();
|
|
682
|
-
}
|
|
683
|
-
// @ts-expect-error - this was hidden from the public API
|
|
684
|
-
return target.__client;
|
|
685
|
-
};
|
|
686
|
-
|
|
687
570
|
const sendEmailOTP = async (client, { email })=>{
|
|
688
571
|
const core = getCore(client);
|
|
689
572
|
const apiClient = createApiClient(client);
|
|
@@ -1673,4 +1556,4 @@ const verifyOTP = async (otpVerification, { verificationToken })=>{
|
|
|
1673
1556
|
return user;
|
|
1674
1557
|
};
|
|
1675
1558
|
|
|
1676
|
-
export { createDynamicClient, hasExtension, logout, sendEmailOTP, sendSmsOTP, verifyOTP };
|
|
1559
|
+
export { BaseError, ClientAlreadyInitializedError, createDynamicClient, hasExtension, initializeClient, logout, sendEmailOTP, sendSmsOTP, verifyOTP };
|
package/package.json
CHANGED
|
@@ -2,5 +2,5 @@ import type { DynamicCoreState } from '../types';
|
|
|
2
2
|
/**
|
|
3
3
|
* The initial values for the state of the client.
|
|
4
4
|
*/
|
|
5
|
-
export declare const
|
|
6
|
-
//# sourceMappingURL=
|
|
5
|
+
export declare const getInitialState: () => DynamicCoreState;
|
|
6
|
+
//# sourceMappingURL=getInitialState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getInitialState.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/client/core/createCore/getInitialState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD;;GAEG;AACH,eAAO,MAAM,eAAe,QAAO,gBAMjC,CAAC"}
|
package/src/exports/core.d.ts
CHANGED
|
@@ -2,5 +2,9 @@ export { getCore } from '../client/core/getCore';
|
|
|
2
2
|
export type { DynamicCore, DynamicCoreState, DynamicInitStatus, } from '../client/core/types';
|
|
3
3
|
export { emitEvent } from '../modules/events';
|
|
4
4
|
export { registerExtension } from '../modules/extension/registerExtension';
|
|
5
|
+
export { CannotTrackError } from '../services/asyncTrack/errors/CannotTrackError';
|
|
6
|
+
export { InvalidStorageSet } from '../services/storage/createWebStorage/errors/InvalidStorageSet';
|
|
7
|
+
export { getClient } from '../utils/getClient';
|
|
8
|
+
export { ClientNotPresentError } from '../utils/getClient/errors/ClientNotPresentError';
|
|
5
9
|
export { subscribeWithSelector } from '../utils/observable/subscribeWithSelector';
|
|
6
10
|
//# sourceMappingURL=core.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../../packages/client/src/exports/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAC"}
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../../packages/client/src/exports/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,gDAAgD,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,+DAA+D,CAAC;AAClG,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iDAAiD,CAAC;AACxF,OAAO,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAC"}
|
package/src/exports/index.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
export type { DynamicCoreConfig } from '../client/core/types';
|
|
2
2
|
export { createDynamicClient } from '../client/createDynamicClient';
|
|
3
3
|
export type { DynamicClient, DynamicClientConfig } from '../client/types';
|
|
4
|
+
export { BaseError } from '../errors/base/BaseError';
|
|
4
5
|
export { logout } from '../modules/auth/logout';
|
|
5
6
|
export { offEvent, onceEvent, onEvent } from '../modules/events';
|
|
6
7
|
export { hasExtension } from '../modules/extension/hasExtension';
|
|
8
|
+
export { initializeClient } from '../modules/initializeClient';
|
|
9
|
+
export { ClientAlreadyInitializedError } from '../modules/initializeClient/errors/ClientAlreadyInitializedError';
|
|
7
10
|
export { sendEmailOTP } from '../modules/otp/sendEmailOTP';
|
|
8
11
|
export { sendSmsOTP } from '../modules/otp/sendSmsOTP';
|
|
9
12
|
export type { OTPVerification } from '../modules/otp/types';
|
|
10
13
|
export { verifyOTP } from '../modules/otp/verifyOTP';
|
|
11
|
-
import '../modules/state/raiseStateEvents/events';
|
|
12
14
|
import '../modules/auth/logout/events';
|
|
15
|
+
import '../modules/state/raiseStateEvents/events';
|
|
13
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/client/src/exports/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,YAAY,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAGrD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/client/src/exports/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,YAAY,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,6BAA6B,EAAE,MAAM,kEAAkE,CAAC;AACjH,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAGrD,OAAO,+BAA+B,CAAC;AACvC,OAAO,0CAA0C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientNotPresentError.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/utils/getClient/errors/ClientNotPresentError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,qBAAa,qBAAsB,SAAQ,SAAS;;CASnD"}
|
package/events.cjs.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const getCore = (client)=>{
|
|
4
|
-
// @ts-expect-error - this was hidden from the public API
|
|
5
|
-
return client.__core;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Shallow compare two objects.
|
|
10
|
-
*
|
|
11
|
-
* Source: https://github.com/pmndrs/zustand/blob/main/src/vanilla/shallow.ts
|
|
12
|
-
*/ const isEqualShallow = (objA, objB)=>{
|
|
13
|
-
if (Object.is(objA, objB)) return true;
|
|
14
|
-
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
15
|
-
return objA === objB;
|
|
16
|
-
}
|
|
17
|
-
if (objA instanceof Map && objB instanceof Map) {
|
|
18
|
-
if (objA.size !== objB.size) return false;
|
|
19
|
-
for (const [key, value] of objA){
|
|
20
|
-
if (!Object.is(value, objB.get(key))) return false;
|
|
21
|
-
}
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
if (objA instanceof Set && objB instanceof Set) {
|
|
25
|
-
if (objA.size !== objB.size) return false;
|
|
26
|
-
for (const value of objA){
|
|
27
|
-
if (!objB.has(value)) return false;
|
|
28
|
-
}
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
const keysA = Object.keys(objA);
|
|
32
|
-
if (keysA.length !== Object.keys(objB).length) return false;
|
|
33
|
-
for (const keyA of keysA){
|
|
34
|
-
if (!Object.prototype.hasOwnProperty.call(objB, keyA) || !Object.is(objA[keyA], objB[keyA])) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (objA.constructor !== objB.constructor) return false;
|
|
39
|
-
return true;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Allows subscribing to a slice of the state.
|
|
44
|
-
* The slice is a computation of the states.
|
|
45
|
-
*
|
|
46
|
-
* The callback will only be called when the slice has changed.
|
|
47
|
-
* Change is determined by shallow comparison.
|
|
48
|
-
*
|
|
49
|
-
* Returns a function to unsubscribe the callback.
|
|
50
|
-
*/ const subscribeWithSelector = (observable, selector)=>(callback)=>{
|
|
51
|
-
let lastSlice = selector(observable.get());
|
|
52
|
-
return observable.subscribe((value)=>{
|
|
53
|
-
const nextSlice = selector(value);
|
|
54
|
-
if (isEqualShallow(nextSlice, lastSlice)) return;
|
|
55
|
-
lastSlice = nextSlice;
|
|
56
|
-
callback(nextSlice);
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Listen to an event from the client.
|
|
62
|
-
*
|
|
63
|
-
* @returns A function that can be called to remove the listener.
|
|
64
|
-
*/ const onEvent = (client, event, listener)=>{
|
|
65
|
-
const { eventEmitter } = getCore(client);
|
|
66
|
-
eventEmitter.on(event, listener);
|
|
67
|
-
return ()=>{
|
|
68
|
-
eventEmitter.off(event, listener);
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* Remove a listener from an event.
|
|
73
|
-
*/ const offEvent = (client, event, listener)=>{
|
|
74
|
-
const { eventEmitter } = getCore(client);
|
|
75
|
-
eventEmitter.off(event, listener);
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* Listen to an event that will only fire once.
|
|
79
|
-
*
|
|
80
|
-
* @returns A function that can be called to remove the listener.
|
|
81
|
-
*/ const onceEvent = (client, event, listener)=>{
|
|
82
|
-
const { eventEmitter } = getCore(client);
|
|
83
|
-
eventEmitter.once(event, listener);
|
|
84
|
-
return ()=>{
|
|
85
|
-
eventEmitter.off(event, listener);
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
/**
|
|
89
|
-
* Emit an event.
|
|
90
|
-
*/ const emitEvent = (client, event, ...args)=>{
|
|
91
|
-
const { eventEmitter } = getCore(client);
|
|
92
|
-
eventEmitter.emit(event, ...args);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
exports.emitEvent = emitEvent;
|
|
96
|
-
exports.getCore = getCore;
|
|
97
|
-
exports.isEqualShallow = isEqualShallow;
|
|
98
|
-
exports.offEvent = offEvent;
|
|
99
|
-
exports.onEvent = onEvent;
|
|
100
|
-
exports.onceEvent = onceEvent;
|
|
101
|
-
exports.subscribeWithSelector = subscribeWithSelector;
|
package/events.esm.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
const getCore = (client)=>{
|
|
2
|
-
// @ts-expect-error - this was hidden from the public API
|
|
3
|
-
return client.__core;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Shallow compare two objects.
|
|
8
|
-
*
|
|
9
|
-
* Source: https://github.com/pmndrs/zustand/blob/main/src/vanilla/shallow.ts
|
|
10
|
-
*/ const isEqualShallow = (objA, objB)=>{
|
|
11
|
-
if (Object.is(objA, objB)) return true;
|
|
12
|
-
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
13
|
-
return objA === objB;
|
|
14
|
-
}
|
|
15
|
-
if (objA instanceof Map && objB instanceof Map) {
|
|
16
|
-
if (objA.size !== objB.size) return false;
|
|
17
|
-
for (const [key, value] of objA){
|
|
18
|
-
if (!Object.is(value, objB.get(key))) return false;
|
|
19
|
-
}
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
if (objA instanceof Set && objB instanceof Set) {
|
|
23
|
-
if (objA.size !== objB.size) return false;
|
|
24
|
-
for (const value of objA){
|
|
25
|
-
if (!objB.has(value)) return false;
|
|
26
|
-
}
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
const keysA = Object.keys(objA);
|
|
30
|
-
if (keysA.length !== Object.keys(objB).length) return false;
|
|
31
|
-
for (const keyA of keysA){
|
|
32
|
-
if (!Object.prototype.hasOwnProperty.call(objB, keyA) || !Object.is(objA[keyA], objB[keyA])) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (objA.constructor !== objB.constructor) return false;
|
|
37
|
-
return true;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Allows subscribing to a slice of the state.
|
|
42
|
-
* The slice is a computation of the states.
|
|
43
|
-
*
|
|
44
|
-
* The callback will only be called when the slice has changed.
|
|
45
|
-
* Change is determined by shallow comparison.
|
|
46
|
-
*
|
|
47
|
-
* Returns a function to unsubscribe the callback.
|
|
48
|
-
*/ const subscribeWithSelector = (observable, selector)=>(callback)=>{
|
|
49
|
-
let lastSlice = selector(observable.get());
|
|
50
|
-
return observable.subscribe((value)=>{
|
|
51
|
-
const nextSlice = selector(value);
|
|
52
|
-
if (isEqualShallow(nextSlice, lastSlice)) return;
|
|
53
|
-
lastSlice = nextSlice;
|
|
54
|
-
callback(nextSlice);
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Listen to an event from the client.
|
|
60
|
-
*
|
|
61
|
-
* @returns A function that can be called to remove the listener.
|
|
62
|
-
*/ const onEvent = (client, event, listener)=>{
|
|
63
|
-
const { eventEmitter } = getCore(client);
|
|
64
|
-
eventEmitter.on(event, listener);
|
|
65
|
-
return ()=>{
|
|
66
|
-
eventEmitter.off(event, listener);
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Remove a listener from an event.
|
|
71
|
-
*/ const offEvent = (client, event, listener)=>{
|
|
72
|
-
const { eventEmitter } = getCore(client);
|
|
73
|
-
eventEmitter.off(event, listener);
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* Listen to an event that will only fire once.
|
|
77
|
-
*
|
|
78
|
-
* @returns A function that can be called to remove the listener.
|
|
79
|
-
*/ const onceEvent = (client, event, listener)=>{
|
|
80
|
-
const { eventEmitter } = getCore(client);
|
|
81
|
-
eventEmitter.once(event, listener);
|
|
82
|
-
return ()=>{
|
|
83
|
-
eventEmitter.off(event, listener);
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
/**
|
|
87
|
-
* Emit an event.
|
|
88
|
-
*/ const emitEvent = (client, event, ...args)=>{
|
|
89
|
-
const { eventEmitter } = getCore(client);
|
|
90
|
-
eventEmitter.emit(event, ...args);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export { onceEvent as a, onEvent as b, emitEvent as e, getCore as g, isEqualShallow as i, offEvent as o, subscribeWithSelector as s };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"initialState.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/client/core/createCore/initialState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,gBAM1B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ClientNotPresentError.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/utils/getClient/erros/ClientNotPresentError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,qBAAa,qBAAsB,SAAQ,SAAS;;CASnD"}
|
|
File without changes
|