@blocklet/sdk 1.16.39-beta-20250222-094928-e54632fa → 1.16.39-beta-20250225-115803-28695007
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/lib/service/eventbus.d.ts +9 -0
- package/lib/service/eventbus.js +43 -0
- package/lib/service/notification.d.ts +7 -2
- package/lib/service/notification.js +47 -18
- package/lib/types/event.d.ts +14 -0
- package/lib/types/event.js +3 -0
- package/lib/util/send-notification.d.ts +9 -7
- package/lib/util/send-notification.js +28 -3
- package/lib/validators/event.d.ts +9 -0
- package/lib/validators/event.js +49 -0
- package/package.json +8 -8
- package/service/eventbus.js +1 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TEvent } from '../types/event';
|
|
2
|
+
declare const subscribe: (cb: (event: TEvent) => any | Promise<any>) => void;
|
|
3
|
+
declare const unsubscribe: (cb: (event: TEvent) => any | Promise<any>) => void;
|
|
4
|
+
declare const publish: (name: string, event: {
|
|
5
|
+
id?: string;
|
|
6
|
+
time?: string;
|
|
7
|
+
data: any;
|
|
8
|
+
}) => Promise<any>;
|
|
9
|
+
export { subscribe, unsubscribe, publish };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.publish = exports.unsubscribe = exports.subscribe = void 0;
|
|
7
|
+
const util_1 = require("@blocklet/meta/lib/util");
|
|
8
|
+
const notification_1 = require("./notification");
|
|
9
|
+
const check_blocklet_env_1 = __importDefault(require("../util/check-blocklet-env"));
|
|
10
|
+
const send_notification_1 = require("../util/send-notification");
|
|
11
|
+
const event_1 = require("../validators/event");
|
|
12
|
+
const subscribe = (cb) => {
|
|
13
|
+
(0, notification_1.ensureClient)();
|
|
14
|
+
notification_1._eventBus.on('event', cb);
|
|
15
|
+
};
|
|
16
|
+
exports.subscribe = subscribe;
|
|
17
|
+
const unsubscribe = (cb) => {
|
|
18
|
+
notification_1._eventBus.off('event', cb);
|
|
19
|
+
};
|
|
20
|
+
exports.unsubscribe = unsubscribe;
|
|
21
|
+
const publish = async (name, event) => {
|
|
22
|
+
(0, check_blocklet_env_1.default)();
|
|
23
|
+
(0, notification_1.ensureClient)();
|
|
24
|
+
const payload = {
|
|
25
|
+
id: event.id || (0, util_1.nanoid)(),
|
|
26
|
+
time: event.time || new Date().toISOString(),
|
|
27
|
+
object_type: event.data.object_type || '',
|
|
28
|
+
object_id: event.data.object_id || '',
|
|
29
|
+
type: name,
|
|
30
|
+
data: {
|
|
31
|
+
type: 'application/json',
|
|
32
|
+
...event.data,
|
|
33
|
+
},
|
|
34
|
+
source: process.env.BLOCKLET_COMPONENT_DID,
|
|
35
|
+
spec_version: '1.0.0',
|
|
36
|
+
};
|
|
37
|
+
const { error } = await (0, event_1.validateEvent)(payload);
|
|
38
|
+
if (error) {
|
|
39
|
+
throw new Error(`Invalid event: ${error}`);
|
|
40
|
+
}
|
|
41
|
+
return (0, send_notification_1.sendToEventBus)(payload, (0, notification_1.getSender)());
|
|
42
|
+
};
|
|
43
|
+
exports.publish = publish;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
2
|
import { TNotification, TNotificationInput, TSendOptions } from '../types/notification';
|
|
3
3
|
type $TSFixMe = any;
|
|
4
|
+
export declare const getSender: () => {
|
|
5
|
+
appDid: string;
|
|
6
|
+
appSk: string;
|
|
7
|
+
};
|
|
4
8
|
/**
|
|
5
9
|
*
|
|
6
10
|
* @param {Notification} notification
|
|
@@ -23,7 +27,9 @@ declare const doSendMail: (receiver: string | string[], notification: TNotificat
|
|
|
23
27
|
* }} options
|
|
24
28
|
* @returns
|
|
25
29
|
*/
|
|
26
|
-
declare const broadcast: (notification: TNotificationInput, options?: TSendOptions) => Promise<any>;
|
|
30
|
+
export declare const broadcast: (notification: TNotificationInput, options?: TSendOptions) => Promise<any>;
|
|
31
|
+
export declare const _eventBus: EventEmitter<[never]>;
|
|
32
|
+
export declare const ensureClient: () => void;
|
|
27
33
|
export declare const on: (event: string, cb?: $TSFixMe) => EventEmitter<[never]>;
|
|
28
34
|
export declare const off: any;
|
|
29
35
|
export declare const _message: {
|
|
@@ -33,7 +39,6 @@ export declare const _message: {
|
|
|
33
39
|
export { doSendToUser as sendToUser };
|
|
34
40
|
export { doSendMail as sendToMail };
|
|
35
41
|
export { doSendToRelay as sendToRelay };
|
|
36
|
-
export { broadcast };
|
|
37
42
|
declare const _default: {
|
|
38
43
|
sendToUser: (receiver: string | string[], notification: TNotificationInput, options?: TSendOptions) => Promise<any>;
|
|
39
44
|
sendToRelay: (topic: string, event: string, data: any) => Promise<any>;
|
|
@@ -36,12 +36,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
39
|
+
exports.sendToRelay = exports.sendToMail = exports.sendToUser = exports._message = exports.off = exports.on = exports.ensureClient = exports._eventBus = exports.broadcast = exports.getSender = void 0;
|
|
40
40
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
41
41
|
const Jwt = __importStar(require("@arcblock/jwt"));
|
|
42
42
|
const debug_1 = __importDefault(require("debug"));
|
|
43
43
|
const node_events_1 = require("node:events");
|
|
44
44
|
const ws_1 = require("@arcblock/ws");
|
|
45
|
+
const util_1 = require("@blocklet/meta/lib/util");
|
|
45
46
|
const channel_1 = require("@blocklet/meta/lib/channel");
|
|
46
47
|
const constant_1 = require("@blocklet/constant");
|
|
47
48
|
const check_blocklet_env_1 = __importDefault(require("../util/check-blocklet-env"));
|
|
@@ -58,6 +59,7 @@ const getSender = () => {
|
|
|
58
59
|
appSk: wallet.secretKey,
|
|
59
60
|
};
|
|
60
61
|
};
|
|
62
|
+
exports.getSender = getSender;
|
|
61
63
|
/**
|
|
62
64
|
*
|
|
63
65
|
* @param {Notification} notification
|
|
@@ -69,19 +71,19 @@ const getSender = () => {
|
|
|
69
71
|
// eslint-disable-next-line require-await
|
|
70
72
|
const doSendToUser = async (receiver, notification, options) => {
|
|
71
73
|
(0, check_blocklet_env_1.default)();
|
|
72
|
-
return (0, send_notification_1.sendToUser)(receiver, notification,
|
|
74
|
+
return (0, send_notification_1.sendToUser)(receiver, notification, (0, exports.getSender)(), options, 'send-to-user');
|
|
73
75
|
};
|
|
74
76
|
exports.sendToUser = doSendToUser;
|
|
75
77
|
// eslint-disable-next-line require-await
|
|
76
78
|
const doSendToRelay = async (topic, event, data) => {
|
|
77
79
|
(0, check_blocklet_env_1.default)();
|
|
78
|
-
return (0, send_notification_1.sendToRelay)(topic, event, data,
|
|
80
|
+
return (0, send_notification_1.sendToRelay)(topic, event, data, (0, exports.getSender)());
|
|
79
81
|
};
|
|
80
82
|
exports.sendToRelay = doSendToRelay;
|
|
81
83
|
// eslint-disable-next-line require-await
|
|
82
84
|
const doSendMail = async (receiver, notification, options) => {
|
|
83
85
|
(0, check_blocklet_env_1.default)();
|
|
84
|
-
return (0, send_notification_1.sendToUser)(receiver, notification,
|
|
86
|
+
return (0, send_notification_1.sendToUser)(receiver, notification, (0, exports.getSender)(), options, 'send-to-mail');
|
|
85
87
|
};
|
|
86
88
|
exports.sendToMail = doSendMail;
|
|
87
89
|
/**
|
|
@@ -98,15 +100,16 @@ exports.sendToMail = doSendMail;
|
|
|
98
100
|
// eslint-disable-next-line require-await
|
|
99
101
|
const broadcast = async (notification, options = {}) => {
|
|
100
102
|
(0, check_blocklet_env_1.default)();
|
|
101
|
-
const sender = getSender();
|
|
103
|
+
const sender = (0, exports.getSender)();
|
|
102
104
|
const { channel = (0, channel_1.getAppPublicChannel)(sender.appDid) } = options;
|
|
103
105
|
const { event = 'message' } = options;
|
|
104
|
-
return (0, send_notification_1.sendToAppChannel)(channel, event, notification, sender,
|
|
106
|
+
return (0, send_notification_1.sendToAppChannel)(channel, event, notification, sender, options);
|
|
105
107
|
};
|
|
106
108
|
exports.broadcast = broadcast;
|
|
107
109
|
const noop = () => { };
|
|
108
110
|
const emitter = new node_events_1.EventEmitter();
|
|
109
111
|
const messageEmitter = new node_events_1.EventEmitter();
|
|
112
|
+
exports._eventBus = new node_events_1.EventEmitter(); // for event bus
|
|
110
113
|
const emitError = (error) => {
|
|
111
114
|
messageEmitter.emit('error', error);
|
|
112
115
|
emitter.emit('error', error);
|
|
@@ -114,11 +117,12 @@ const emitError = (error) => {
|
|
|
114
117
|
const ensureErrorListener = () => {
|
|
115
118
|
emitter.on('error', noop);
|
|
116
119
|
messageEmitter.on('error', noop);
|
|
120
|
+
exports._eventBus.on('error', noop);
|
|
117
121
|
};
|
|
118
122
|
const joinChannelErrorHandler = (name, type, emitters) => (err) => {
|
|
119
123
|
const msg = `join ${name || 'channel'} ${type || 'error'}${err?.message ? ': ' : ''}${err?.message || ''}`;
|
|
120
124
|
console.error(msg);
|
|
121
|
-
(emitters || [emitter]).forEach((
|
|
125
|
+
(emitters || [emitter]).forEach((x) => x.emit('error', { message: msg }));
|
|
122
126
|
};
|
|
123
127
|
let client = null;
|
|
124
128
|
const initClient = () => {
|
|
@@ -144,18 +148,23 @@ const initClient = () => {
|
|
|
144
148
|
pk,
|
|
145
149
|
apiKey: process.env.BLOCKLET_COMPONENT_API_KEY,
|
|
146
150
|
}));
|
|
151
|
+
const eventBusChannel = client.channel((0, channel_1.getEventBusChannel)(did), () => ({ token: token(), pk }));
|
|
147
152
|
messageChannel
|
|
148
153
|
.join()
|
|
149
154
|
.receive('error', joinChannelErrorHandler('message channel', 'error', [messageEmitter, emitter]))
|
|
150
155
|
.receive('timeout', joinChannelErrorHandler('message channel', 'timeout', [messageEmitter, emitter]));
|
|
151
156
|
appPublicChannel
|
|
152
157
|
.join()
|
|
153
|
-
.receive('error', joinChannelErrorHandler('app
|
|
154
|
-
.receive('timeout', joinChannelErrorHandler('app
|
|
158
|
+
.receive('error', joinChannelErrorHandler('app public channel', 'error'))
|
|
159
|
+
.receive('timeout', joinChannelErrorHandler('app public channel', 'timeout'));
|
|
155
160
|
componentChannel
|
|
156
161
|
.join()
|
|
157
162
|
.receive('error', joinChannelErrorHandler('app component channel', 'error'))
|
|
158
163
|
.receive('timeout', joinChannelErrorHandler('app component channel', 'timeout'));
|
|
164
|
+
eventBusChannel
|
|
165
|
+
.join()
|
|
166
|
+
.receive('error', joinChannelErrorHandler('eventbus channel', 'error'))
|
|
167
|
+
.receive('timeout', joinChannelErrorHandler('eventbus channel', 'timeout'));
|
|
159
168
|
messageChannel.on('message', ({ status, response } = {}) => {
|
|
160
169
|
debug('messageChannel.on', { status, response });
|
|
161
170
|
if (status === 'ok') {
|
|
@@ -166,10 +175,20 @@ const initClient = () => {
|
|
|
166
175
|
}
|
|
167
176
|
else {
|
|
168
177
|
emitError(response);
|
|
169
|
-
console.error({
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
178
|
+
console.error('Message channel error', { status, response });
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
eventBusChannel.on('event', ({ status, response } = {}) => {
|
|
182
|
+
debug('eventBusChannel.on', { status, response });
|
|
183
|
+
if (status === 'ok') {
|
|
184
|
+
// ignore events from self
|
|
185
|
+
if (response.source !== process.env.BLOCKLET_COMPONENT_DID) {
|
|
186
|
+
exports._eventBus.emit('event', response);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
exports._eventBus.emit('error', response);
|
|
191
|
+
console.error('Event channel error', { status, response });
|
|
173
192
|
}
|
|
174
193
|
});
|
|
175
194
|
[...Object.keys(constant_1.BlockletInternalEvents), ...Object.keys(constant_1.TeamEvents)].forEach((key) => {
|
|
@@ -190,10 +209,19 @@ const initClient = () => {
|
|
|
190
209
|
return;
|
|
191
210
|
}
|
|
192
211
|
emitter.emit(event, data);
|
|
212
|
+
// Emit team events to event bus
|
|
213
|
+
if (constant_1.TeamEvents[key]) {
|
|
214
|
+
exports._eventBus.emit('event', {
|
|
215
|
+
id: (0, util_1.nanoid)(),
|
|
216
|
+
time: new Date().toISOString(),
|
|
217
|
+
type: `blocklet.${event}`,
|
|
218
|
+
data: { object: data.user },
|
|
219
|
+
});
|
|
220
|
+
}
|
|
193
221
|
}
|
|
194
222
|
else {
|
|
195
223
|
emitError(response);
|
|
196
|
-
console.error({ status, response });
|
|
224
|
+
console.error('Component channel error', { status, response });
|
|
197
225
|
}
|
|
198
226
|
});
|
|
199
227
|
});
|
|
@@ -204,7 +232,7 @@ const initClient = () => {
|
|
|
204
232
|
}
|
|
205
233
|
else {
|
|
206
234
|
emitter.emit('error', response);
|
|
207
|
-
console.error({ status, response });
|
|
235
|
+
console.error('App public channel error', { status, response });
|
|
208
236
|
}
|
|
209
237
|
});
|
|
210
238
|
}
|
|
@@ -217,15 +245,16 @@ const ensureClient = () => {
|
|
|
217
245
|
initClient();
|
|
218
246
|
}
|
|
219
247
|
};
|
|
248
|
+
exports.ensureClient = ensureClient;
|
|
220
249
|
const on = (event, cb) => {
|
|
221
|
-
ensureClient();
|
|
250
|
+
(0, exports.ensureClient)();
|
|
222
251
|
return emitter.on(event, cb);
|
|
223
252
|
};
|
|
224
253
|
exports.on = on;
|
|
225
254
|
exports.off = emitter.off.bind(emitter);
|
|
226
255
|
exports._message = {
|
|
227
256
|
on: (event, cb) => {
|
|
228
|
-
ensureClient();
|
|
257
|
+
(0, exports.ensureClient)();
|
|
229
258
|
return messageEmitter.on(event, cb);
|
|
230
259
|
},
|
|
231
260
|
off: messageEmitter.off.bind(messageEmitter),
|
|
@@ -234,7 +263,7 @@ exports.default = {
|
|
|
234
263
|
sendToUser: doSendToUser,
|
|
235
264
|
sendToRelay: doSendToRelay,
|
|
236
265
|
sendToMail: doSendMail,
|
|
237
|
-
broadcast,
|
|
266
|
+
broadcast: exports.broadcast,
|
|
238
267
|
on: exports.on,
|
|
239
268
|
off: exports.off,
|
|
240
269
|
_message: exports._message,
|
|
@@ -15,21 +15,23 @@ export type TNotificationSender = {
|
|
|
15
15
|
* @param {Object} options
|
|
16
16
|
* @returns
|
|
17
17
|
*/
|
|
18
|
-
declare const sendToUser: (receiver: string | string[], notification: TNotification | TNotificationInput, { appDid, appSk, type }: TNotificationSender,
|
|
18
|
+
declare const sendToUser: (receiver: string | string[], notification: TNotification | TNotificationInput, { appDid, appSk, type }: TNotificationSender, options?: {
|
|
19
19
|
keepForOfflineUser?: boolean;
|
|
20
20
|
locale?: string;
|
|
21
21
|
channels?: ("app" | "email" | "push" | "webhook")[];
|
|
22
|
-
}, pathname?: string) => Promise<any>;
|
|
23
|
-
declare const sendToAppChannel: (channel: string, event: string, notification: TNotificationInput, { appDid, appSk }: TNotificationSender,
|
|
22
|
+
}, pathname?: string, port?: string) => Promise<any>;
|
|
23
|
+
declare const sendToAppChannel: (channel: string, event: string, notification: TNotificationInput, { appDid, appSk }: TNotificationSender, options?: TSendOptions, port?: string) => Promise<any>;
|
|
24
24
|
declare const sendToRelay: (topic: string, event: string, data: any, { appDid, appSk }: TNotificationSender, port?: string) => Promise<any>;
|
|
25
|
-
|
|
25
|
+
declare const sendToEventBus: (event: any, { appDid, appSk }: TNotificationSender, port?: string) => Promise<any>;
|
|
26
|
+
export { sendToUser, sendToAppChannel, sendToRelay, sendToEventBus };
|
|
26
27
|
declare const _default: {
|
|
27
|
-
sendToUser: (receiver: string | string[], notification: TNotification | TNotificationInput, { appDid, appSk, type }: TNotificationSender,
|
|
28
|
+
sendToUser: (receiver: string | string[], notification: TNotification | TNotificationInput, { appDid, appSk, type }: TNotificationSender, options?: {
|
|
28
29
|
keepForOfflineUser?: boolean;
|
|
29
30
|
locale?: string;
|
|
30
31
|
channels?: ("app" | "email" | "push" | "webhook")[];
|
|
31
|
-
}, pathname?: string) => Promise<any>;
|
|
32
|
-
sendToAppChannel: (channel: string, event: string, notification: TNotificationInput, { appDid, appSk }: TNotificationSender,
|
|
32
|
+
}, pathname?: string, port?: string) => Promise<any>;
|
|
33
|
+
sendToAppChannel: (channel: string, event: string, notification: TNotificationInput, { appDid, appSk }: TNotificationSender, options?: TSendOptions, port?: string) => Promise<any>;
|
|
33
34
|
sendToRelay: (topic: string, event: string, data: any, { appDid, appSk }: TNotificationSender, port?: string) => Promise<any>;
|
|
35
|
+
sendToEventBus: (event: any, { appDid, appSk }: TNotificationSender, port?: string) => Promise<any>;
|
|
34
36
|
};
|
|
35
37
|
export default _default;
|
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.sendToRelay = exports.sendToAppChannel = exports.sendToUser = void 0;
|
|
39
|
+
exports.sendToEventBus = exports.sendToRelay = exports.sendToAppChannel = exports.sendToUser = void 0;
|
|
40
40
|
const axios_1 = __importDefault(require("axios"));
|
|
41
41
|
const pick_1 = __importDefault(require("lodash/pick"));
|
|
42
42
|
const JWT = __importStar(require("@arcblock/jwt"));
|
|
@@ -64,7 +64,7 @@ const getRequestHeaders = () => ({ 'User-Agent': `BlockletSDK/${VERSION}` });
|
|
|
64
64
|
* @param {Object} options
|
|
65
65
|
* @returns
|
|
66
66
|
*/
|
|
67
|
-
const sendToUser = async (receiver, notification, { appDid, appSk, type },
|
|
67
|
+
const sendToUser = async (receiver, notification, { appDid, appSk, type }, options = {}, pathname = 'send-to-user', port = process.env.ABT_NODE_SERVICE_PORT) => {
|
|
68
68
|
if (['send-to-user', 'send-to-push-kit', 'send-to-wallet'].includes(pathname)) {
|
|
69
69
|
await (0, index_1.validateReceiver)(receiver);
|
|
70
70
|
}
|
|
@@ -102,7 +102,7 @@ const sendToUser = async (receiver, notification, { appDid, appSk, type }, port
|
|
|
102
102
|
}
|
|
103
103
|
};
|
|
104
104
|
exports.sendToUser = sendToUser;
|
|
105
|
-
const sendToAppChannel = async (channel, event, notification, { appDid, appSk }, port = process.env.ABT_NODE_SERVICE_PORT
|
|
105
|
+
const sendToAppChannel = async (channel, event, notification, { appDid, appSk }, options = {}, port = process.env.ABT_NODE_SERVICE_PORT) => {
|
|
106
106
|
if (!channel) {
|
|
107
107
|
throw new Error('channel is required');
|
|
108
108
|
}
|
|
@@ -172,8 +172,33 @@ const sendToRelay = async (topic, event, data, { appDid, appSk }, port = process
|
|
|
172
172
|
}
|
|
173
173
|
};
|
|
174
174
|
exports.sendToRelay = sendToRelay;
|
|
175
|
+
const sendToEventBus = async (event, { appDid, appSk }, port = process.env.ABT_NODE_SERVICE_PORT) => {
|
|
176
|
+
if (!event) {
|
|
177
|
+
throw new Error('event is required');
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
const { data: res } = await axios.post(`http://${(0, parse_docker_endpoint_1.getServerHost)()}:${port}${constants_1.SERVICE_PREFIX}/api/send-to-event-bus`, {
|
|
181
|
+
apiVersion: VERSION,
|
|
182
|
+
data: {
|
|
183
|
+
sender: { appDid, token: JWT.sign(appDid, appSk) },
|
|
184
|
+
channel: (0, channel_1.getEventBusChannel)(appDid),
|
|
185
|
+
event,
|
|
186
|
+
},
|
|
187
|
+
}, {
|
|
188
|
+
timeout: 60 * 1000,
|
|
189
|
+
headers: getRequestHeaders(),
|
|
190
|
+
});
|
|
191
|
+
return res;
|
|
192
|
+
}
|
|
193
|
+
catch (err) {
|
|
194
|
+
console.error(err.response ? err.response.data : err);
|
|
195
|
+
throw new Error(err.response ? err.response.data : err.message);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
exports.sendToEventBus = sendToEventBus;
|
|
175
199
|
exports.default = {
|
|
176
200
|
sendToUser,
|
|
177
201
|
sendToAppChannel,
|
|
178
202
|
sendToRelay,
|
|
203
|
+
sendToEventBus,
|
|
179
204
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import JOI from 'joi';
|
|
2
|
+
declare const eventSchema: JOI.ObjectSchema<any>;
|
|
3
|
+
declare const validateEvent: any;
|
|
4
|
+
export { eventSchema, validateEvent };
|
|
5
|
+
declare const _default: {
|
|
6
|
+
eventSchema: JOI.ObjectSchema<any>;
|
|
7
|
+
validateEvent: any;
|
|
8
|
+
};
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateEvent = exports.eventSchema = void 0;
|
|
7
|
+
/* eslint-disable import/prefer-default-export */
|
|
8
|
+
const joi_1 = __importDefault(require("joi"));
|
|
9
|
+
const extension_1 = require("@blocklet/meta/lib/extension");
|
|
10
|
+
const Joi = joi_1.default.extend(extension_1.didExtension);
|
|
11
|
+
// {
|
|
12
|
+
// "id": "evt_T2UiJ2VHUxVo3J6BuULkrp15",
|
|
13
|
+
// "source": "componentDid",
|
|
14
|
+
// "type": "customer.subscription.renewed",
|
|
15
|
+
// "time": "2025-02-19T03:46:42.662Z",
|
|
16
|
+
// "spec_version": "1.0",
|
|
17
|
+
// "object_type": "Subscription",
|
|
18
|
+
// "object_id": "sub_hmL7FQTmMbYVELkH6uVo6m9P",
|
|
19
|
+
// "data": {
|
|
20
|
+
// "type": "application/json",
|
|
21
|
+
// "object": {
|
|
22
|
+
// "id": "sub_hmL7FQTmMbYVELkH6uVo6m9P"
|
|
23
|
+
// },
|
|
24
|
+
// "previous_attributes": {}
|
|
25
|
+
// }
|
|
26
|
+
// }
|
|
27
|
+
const eventSchema = Joi.object({
|
|
28
|
+
id: Joi.string().required(),
|
|
29
|
+
source: Joi.DID().required(),
|
|
30
|
+
type: Joi.string().required(),
|
|
31
|
+
time: Joi.date().iso().required(),
|
|
32
|
+
spec_version: Joi.string().required(),
|
|
33
|
+
object_type: Joi.string().optional().empty(''),
|
|
34
|
+
object_id: Joi.string().optional().empty(''),
|
|
35
|
+
data: Joi.object({
|
|
36
|
+
type: Joi.string().optional().default('application/json'),
|
|
37
|
+
object: Joi.any().optional(),
|
|
38
|
+
previous_attributes: Joi.any().optional().empty(null),
|
|
39
|
+
}).required(),
|
|
40
|
+
})
|
|
41
|
+
.options({ stripUnknown: true, allowUnknown: true })
|
|
42
|
+
.meta({ className: 'TEvent' });
|
|
43
|
+
exports.eventSchema = eventSchema;
|
|
44
|
+
const validateEvent = eventSchema.validateAsync.bind(eventSchema);
|
|
45
|
+
exports.validateEvent = validateEvent;
|
|
46
|
+
exports.default = {
|
|
47
|
+
eventSchema,
|
|
48
|
+
validateEvent,
|
|
49
|
+
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.39-beta-
|
|
6
|
+
"version": "1.16.39-beta-20250225-115803-28695007",
|
|
7
7
|
"description": "graphql client to read/write data on abt node",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"typings": "lib/index.d.ts",
|
|
@@ -27,16 +27,16 @@
|
|
|
27
27
|
"author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
|
|
28
28
|
"license": "Apache-2.0",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@abtnode/client": "1.16.39-beta-
|
|
31
|
-
"@abtnode/constant": "1.16.39-beta-
|
|
32
|
-
"@abtnode/util": "1.16.39-beta-
|
|
30
|
+
"@abtnode/client": "1.16.39-beta-20250225-115803-28695007",
|
|
31
|
+
"@abtnode/constant": "1.16.39-beta-20250225-115803-28695007",
|
|
32
|
+
"@abtnode/util": "1.16.39-beta-20250225-115803-28695007",
|
|
33
33
|
"@arcblock/did": "1.19.10",
|
|
34
34
|
"@arcblock/did-auth": "1.19.10",
|
|
35
35
|
"@arcblock/jwt": "1.19.10",
|
|
36
36
|
"@arcblock/ws": "1.19.10",
|
|
37
|
-
"@blocklet/constant": "1.16.39-beta-
|
|
38
|
-
"@blocklet/env": "1.16.39-beta-
|
|
39
|
-
"@blocklet/meta": "1.16.39-beta-
|
|
37
|
+
"@blocklet/constant": "1.16.39-beta-20250225-115803-28695007",
|
|
38
|
+
"@blocklet/env": "1.16.39-beta-20250225-115803-28695007",
|
|
39
|
+
"@blocklet/meta": "1.16.39-beta-20250225-115803-28695007",
|
|
40
40
|
"@did-connect/authenticator": "^2.2.7",
|
|
41
41
|
"@did-connect/handler": "^2.2.7",
|
|
42
42
|
"@nedb/core": "^2.1.5",
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"ts-node": "^10.9.1",
|
|
83
83
|
"typescript": "^5.6.3"
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "d6c75e9336becf1eabe733058d030bdda0be9848"
|
|
86
86
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../lib/service/eventbus');
|