@eventusgo/sdk 0.1.0 → 0.1.1
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/dist/index.d.ts +4 -1
- package/dist/index.js +25 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -46,6 +46,9 @@ type ConfigureMockEventusOptions = {
|
|
|
46
46
|
ready?: boolean;
|
|
47
47
|
reset?: boolean;
|
|
48
48
|
};
|
|
49
|
+
declare class EventusBridgeUnavailableError extends Error {
|
|
50
|
+
constructor(message?: string);
|
|
51
|
+
}
|
|
49
52
|
type NativeBridgeUser = Record<string, unknown>;
|
|
50
53
|
type NativeBridgeRecord = Record<string, unknown>;
|
|
51
54
|
type NativeEventusBridge = {
|
|
@@ -79,4 +82,4 @@ declare class EventusClientImpl implements EventusClient {
|
|
|
79
82
|
declare const eventus: EventusClientImpl;
|
|
80
83
|
declare function configureMockEventus(options?: ConfigureMockEventusOptions): void;
|
|
81
84
|
|
|
82
|
-
export { type ConfigureMockEventusOptions, type EventusClient, type EventusContext, type EventusEventHandler, type EventusEventMap, type EventusEventName, type EventusManifest, type EventusPermission, type EventusRuntimeSource, type EventusTheme, type EventusUser, configureMockEventus, eventus };
|
|
85
|
+
export { type ConfigureMockEventusOptions, EventusBridgeUnavailableError, type EventusClient, type EventusContext, type EventusEventHandler, type EventusEventMap, type EventusEventName, type EventusManifest, type EventusPermission, type EventusRuntimeSource, type EventusTheme, type EventusUser, configureMockEventus, eventus };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
var EventusBridgeUnavailableError = class extends Error {
|
|
3
|
+
constructor(message = "No Eventus bridge is connected.") {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "EventusBridgeUnavailableError";
|
|
6
|
+
}
|
|
7
|
+
};
|
|
2
8
|
var EventEmitter = class {
|
|
3
9
|
listeners = /* @__PURE__ */ new Map();
|
|
4
10
|
on(event, handler) {
|
|
@@ -87,6 +93,7 @@ function mapNativeContext(bridge) {
|
|
|
87
93
|
};
|
|
88
94
|
}
|
|
89
95
|
var mockState = {
|
|
96
|
+
enabled: false,
|
|
90
97
|
context: createDefaultMockContext(),
|
|
91
98
|
manifestOverride: void 0,
|
|
92
99
|
ready: false
|
|
@@ -107,6 +114,9 @@ var EventusClientImpl = class {
|
|
|
107
114
|
this.emitReady(mapNativeContext(bridge), "native");
|
|
108
115
|
return;
|
|
109
116
|
}
|
|
117
|
+
if (!mockState.enabled) {
|
|
118
|
+
throw new EventusBridgeUnavailableError();
|
|
119
|
+
}
|
|
110
120
|
mockState.ready = true;
|
|
111
121
|
this.emitReady(mockState.context, "mock");
|
|
112
122
|
}
|
|
@@ -115,6 +125,9 @@ var EventusClientImpl = class {
|
|
|
115
125
|
if (bridge) {
|
|
116
126
|
return mapNativeContext(bridge);
|
|
117
127
|
}
|
|
128
|
+
if (!mockState.enabled) {
|
|
129
|
+
throw new EventusBridgeUnavailableError();
|
|
130
|
+
}
|
|
118
131
|
return mockState.context;
|
|
119
132
|
}
|
|
120
133
|
getManifest() {
|
|
@@ -135,6 +148,11 @@ var EventusClientImpl = class {
|
|
|
135
148
|
return bridgeAction(payload);
|
|
136
149
|
}
|
|
137
150
|
}
|
|
151
|
+
if (!mockState.enabled) {
|
|
152
|
+
throw new EventusBridgeUnavailableError(
|
|
153
|
+
`Eventus request "${action}" requires a native bridge or explicit mock mode.`
|
|
154
|
+
);
|
|
155
|
+
}
|
|
138
156
|
const mockedResponse = {
|
|
139
157
|
mock: true,
|
|
140
158
|
action,
|
|
@@ -148,13 +166,18 @@ var EventusClientImpl = class {
|
|
|
148
166
|
}
|
|
149
167
|
configureMock(options = {}) {
|
|
150
168
|
const previousTheme = mockState.context.theme;
|
|
169
|
+
const shouldEnableMock = !!options.context || "manifest" in options || typeof options.ready === "boolean";
|
|
151
170
|
if (options.reset) {
|
|
171
|
+
mockState.enabled = false;
|
|
152
172
|
mockState.context = createDefaultMockContext();
|
|
153
173
|
mockState.manifestOverride = void 0;
|
|
154
174
|
mockState.ready = false;
|
|
155
175
|
this.lastReadySource = void 0;
|
|
156
176
|
this.hasReadyRequest = false;
|
|
157
177
|
}
|
|
178
|
+
if (shouldEnableMock) {
|
|
179
|
+
mockState.enabled = true;
|
|
180
|
+
}
|
|
158
181
|
if (options.context) {
|
|
159
182
|
const nextUser = options.context.user ? {
|
|
160
183
|
...mockState.context.user ?? {},
|
|
@@ -194,7 +217,7 @@ var EventusClientImpl = class {
|
|
|
194
217
|
});
|
|
195
218
|
}
|
|
196
219
|
handleBridgeReady = () => {
|
|
197
|
-
if (!this.hasReadyRequest && this.lastReadySource
|
|
220
|
+
if (!this.hasReadyRequest && this.lastReadySource === void 0) {
|
|
198
221
|
return;
|
|
199
222
|
}
|
|
200
223
|
const bridge = readWindowBridge();
|
|
@@ -230,6 +253,7 @@ function configureMockEventus(options = {}) {
|
|
|
230
253
|
eventus.configureMock(options);
|
|
231
254
|
}
|
|
232
255
|
export {
|
|
256
|
+
EventusBridgeUnavailableError,
|
|
233
257
|
configureMockEventus,
|
|
234
258
|
eventus
|
|
235
259
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eventusgo/sdk",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Eventus mini-app SDK with
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Eventus mini-app SDK with an explicit browser mock mode.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|