@blocklet/sdk 1.15.17 → 1.16.0-beta-b16cb035
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/README.md +1 -198
- package/lib/component/index.d.ts +35 -0
- package/lib/component/index.js +95 -0
- package/lib/config.d.ts +33 -0
- package/lib/config.js +17 -0
- package/lib/connect/authenticator.d.ts +5 -0
- package/lib/connect/authenticator.js +18 -0
- package/lib/connect/handler.d.ts +2 -0
- package/lib/connect/handler.js +90 -0
- package/lib/connect/shared.d.ts +19 -0
- package/lib/connect/shared.js +81 -0
- package/lib/database/index.d.ts +13 -0
- package/lib/database/index.js +46 -0
- package/lib/embed/adapters/express.d.ts +3 -0
- package/lib/embed/adapters/express.js +13 -0
- package/lib/embed/generate.d.ts +6 -0
- package/lib/embed/generate.js +30 -0
- package/lib/embed/get-embed-url.d.ts +1 -0
- package/lib/embed/get-embed-url.js +55 -0
- package/lib/embed/get-embed.d.ts +1 -0
- package/lib/embed/get-embed.js +32 -0
- package/lib/embed/index.d.ts +10 -0
- package/lib/embed/index.js +13 -0
- package/lib/embed/message.d.ts +26 -0
- package/lib/embed/message.js +134 -0
- package/lib/env.d.ts +17 -0
- package/lib/env.js +3 -0
- package/lib/error-handler.d.ts +0 -0
- package/lib/error-handler.js +5 -5
- package/lib/index.d.ts +53 -0
- package/lib/index.js +49 -12
- package/lib/middlewares/auth.d.ts +8 -0
- package/lib/middlewares/auth.js +54 -0
- package/lib/middlewares/component.d.ts +7 -0
- package/lib/middlewares/component.js +32 -0
- package/lib/middlewares/index.d.ts +24 -0
- package/lib/middlewares/index.js +17 -0
- package/lib/middlewares/user.d.ts +10 -0
- package/lib/middlewares/user.js +12 -0
- package/lib/security/index.d.ts +9 -0
- package/lib/security/index.js +27 -0
- package/lib/service/auth.d.ts +31 -0
- package/lib/service/auth.js +129 -136
- package/lib/service/notification.d.ts +47 -0
- package/lib/service/notification.js +182 -18
- package/lib/types/notification.d.ts +113 -0
- package/lib/types/notification.js +3 -0
- package/lib/util/check-blocklet-env.d.ts +2 -0
- package/lib/util/check-blocklet-env.js +20 -17
- package/lib/util/constants.d.ts +5 -0
- package/lib/util/constants.js +6 -2
- package/lib/util/env.d.ts +19 -0
- package/lib/util/env.js +33 -0
- package/lib/util/send-notification.d.ts +26 -0
- package/lib/util/send-notification.js +149 -38
- package/lib/validators/index.d.ts +12 -0
- package/lib/validators/index.js +13 -5
- package/lib/validators/notification.d.ts +74 -0
- package/lib/validators/notification.js +227 -69
- package/lib/version.d.ts +6 -0
- package/lib/version.js +6 -0
- package/lib/wallet-authenticator.d.ts +5 -0
- package/lib/wallet-authenticator.js +16 -51
- package/lib/wallet-handler.d.ts +19 -0
- package/lib/wallet-handler.js +109 -87
- package/lib/wallet.d.ts +3 -0
- package/lib/wallet.js +10 -0
- package/package.json +52 -19
- package/lib/database.js +0 -98
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
export type TChannelEvent = string;
|
|
2
|
+
export interface TDataAsset {
|
|
3
|
+
chainHost: string;
|
|
4
|
+
did: unknown;
|
|
5
|
+
}
|
|
6
|
+
export interface TDataDapp {
|
|
7
|
+
appDID: unknown;
|
|
8
|
+
desc?: string;
|
|
9
|
+
logo: string;
|
|
10
|
+
title: string;
|
|
11
|
+
url: string;
|
|
12
|
+
}
|
|
13
|
+
export interface TDataImage {
|
|
14
|
+
alt?: string;
|
|
15
|
+
url: string;
|
|
16
|
+
}
|
|
17
|
+
export interface TDataLink {
|
|
18
|
+
description?: string;
|
|
19
|
+
image?: string;
|
|
20
|
+
title?: string;
|
|
21
|
+
url: string;
|
|
22
|
+
}
|
|
23
|
+
export interface TDataText {
|
|
24
|
+
color?: string;
|
|
25
|
+
size?: 'small' | 'normal' | 'big';
|
|
26
|
+
text: string;
|
|
27
|
+
type: string;
|
|
28
|
+
}
|
|
29
|
+
export interface TDataToken {
|
|
30
|
+
address?: unknown;
|
|
31
|
+
amount: string;
|
|
32
|
+
chainHost: string;
|
|
33
|
+
decimal: number;
|
|
34
|
+
senderDid: unknown;
|
|
35
|
+
symbol: string;
|
|
36
|
+
}
|
|
37
|
+
export interface TDataTransaction {
|
|
38
|
+
chainId: string;
|
|
39
|
+
hash: string;
|
|
40
|
+
}
|
|
41
|
+
export interface TDataVC {
|
|
42
|
+
credential: {
|
|
43
|
+
/**
|
|
44
|
+
* Unknown Property
|
|
45
|
+
*/
|
|
46
|
+
[x: string]: unknown;
|
|
47
|
+
};
|
|
48
|
+
tag?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface TMessage {
|
|
51
|
+
/**
|
|
52
|
+
* Any Property
|
|
53
|
+
*/
|
|
54
|
+
[x: string]: any;
|
|
55
|
+
createdAt: Date;
|
|
56
|
+
id: string;
|
|
57
|
+
receiver: {
|
|
58
|
+
did: unknown;
|
|
59
|
+
};
|
|
60
|
+
type: string;
|
|
61
|
+
}
|
|
62
|
+
export interface TNotification {
|
|
63
|
+
actions?: TNotificationAction[];
|
|
64
|
+
attachments?: TNotificationAttachment[];
|
|
65
|
+
blocks?: TNotificationAttachment[];
|
|
66
|
+
body?: string;
|
|
67
|
+
checkUrl?: string;
|
|
68
|
+
data?: object;
|
|
69
|
+
feedType?: string;
|
|
70
|
+
severity?: 'normal' | 'success' | 'error' | 'warning';
|
|
71
|
+
title?: string;
|
|
72
|
+
type?: 'notification' | 'connect' | 'feed' | 'hi';
|
|
73
|
+
url?: string;
|
|
74
|
+
}
|
|
75
|
+
export interface TNotificationAction {
|
|
76
|
+
bgColor?: string;
|
|
77
|
+
color?: string;
|
|
78
|
+
link?: string;
|
|
79
|
+
name: string;
|
|
80
|
+
title?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface TNotificationAttachment {
|
|
83
|
+
data?: any;
|
|
84
|
+
fields?: any;
|
|
85
|
+
type: 'asset' | 'vc' | 'token' | 'text' | 'image' | 'divider' | 'transaction' | 'dapp' | 'link' | 'section';
|
|
86
|
+
}
|
|
87
|
+
export interface TNotificationConnect {
|
|
88
|
+
checkUrl?: string;
|
|
89
|
+
type?: 'connect';
|
|
90
|
+
url: string;
|
|
91
|
+
}
|
|
92
|
+
export interface TNotificationFeed {
|
|
93
|
+
data: object;
|
|
94
|
+
feedType: string;
|
|
95
|
+
type?: 'feed';
|
|
96
|
+
}
|
|
97
|
+
export type TNotificationInput = TNotification[];
|
|
98
|
+
export interface TNotificationItem {
|
|
99
|
+
actions?: TNotificationAction[];
|
|
100
|
+
attachments?: TNotificationAttachment[];
|
|
101
|
+
blocks?: TNotificationAttachment[];
|
|
102
|
+
body?: string;
|
|
103
|
+
severity?: 'normal' | 'success' | 'error' | 'warning';
|
|
104
|
+
title?: string;
|
|
105
|
+
type?: 'notification';
|
|
106
|
+
}
|
|
107
|
+
export interface TSendOptions {
|
|
108
|
+
/**
|
|
109
|
+
* Any Property
|
|
110
|
+
*/
|
|
111
|
+
[x: string]: any;
|
|
112
|
+
keepForOfflineUser?: boolean;
|
|
113
|
+
}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
const checkBlockletEnvironment = () => {
|
|
3
|
+
const envNames = [
|
|
4
|
+
'BLOCKLET_APP_ID',
|
|
5
|
+
'BLOCKLET_APP_NAME',
|
|
6
|
+
'BLOCKLET_APP_DESCRIPTION',
|
|
7
|
+
'BLOCKLET_APP_SK',
|
|
8
|
+
'BLOCKLET_DID',
|
|
9
|
+
'ABT_NODE',
|
|
10
|
+
'ABT_NODE_DID',
|
|
11
|
+
'ABT_NODE_PK',
|
|
12
|
+
'ABT_NODE_PORT',
|
|
13
|
+
'ABT_NODE_SERVICE_PORT',
|
|
14
|
+
];
|
|
15
|
+
envNames.forEach((envName) => {
|
|
16
|
+
if (!process.env[envName]) {
|
|
17
|
+
throw new Error(`${envName} does not exist in environments`);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
18
20
|
};
|
|
21
|
+
module.exports = checkBlockletEnvironment;
|
package/lib/util/constants.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SERVICE_PREFIX = void 0;
|
|
4
|
+
exports.SERVICE_PREFIX = '/.well-known/service';
|
|
5
|
+
exports.default = {
|
|
6
|
+
SERVICE_PREFIX: exports.SERVICE_PREFIX,
|
|
3
7
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
type BlockletPreferences = {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
};
|
|
5
|
+
export declare function parseEnv(env?: NodeJS.ProcessEnv): Readonly<{
|
|
6
|
+
appId: string;
|
|
7
|
+
appPid: string;
|
|
8
|
+
appName: string;
|
|
9
|
+
appDescription: string;
|
|
10
|
+
appUrl: string;
|
|
11
|
+
isComponent: boolean;
|
|
12
|
+
dataDir: string;
|
|
13
|
+
cacheDir: string;
|
|
14
|
+
mode: string;
|
|
15
|
+
appStorageEndpoint: string;
|
|
16
|
+
serverVersion: string;
|
|
17
|
+
preferences: BlockletPreferences;
|
|
18
|
+
}>;
|
|
19
|
+
export {};
|
package/lib/util/env.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseEnv = void 0;
|
|
4
|
+
const constant_1 = require("@blocklet/constant");
|
|
5
|
+
function parseEnv(env = process.env) {
|
|
6
|
+
const preferences = Object.keys(env)
|
|
7
|
+
.filter((x) => x.startsWith(constant_1.BLOCKLET_PREFERENCE_PREFIX))
|
|
8
|
+
.reduce((acc, x) => {
|
|
9
|
+
const key = x.replace(constant_1.BLOCKLET_PREFERENCE_PREFIX, '');
|
|
10
|
+
try {
|
|
11
|
+
acc[key] = JSON.parse(env[x]);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
acc[key] = env[x];
|
|
15
|
+
}
|
|
16
|
+
return acc;
|
|
17
|
+
}, {});
|
|
18
|
+
return Object.freeze({
|
|
19
|
+
appId: env.BLOCKLET_APP_ID,
|
|
20
|
+
appPid: env.BLOCKLET_APP_PID,
|
|
21
|
+
appName: env.BLOCKLET_APP_NAME,
|
|
22
|
+
appDescription: env.BLOCKLET_APP_DESCRIPTION,
|
|
23
|
+
appUrl: env.BLOCKLET_APP_URL,
|
|
24
|
+
isComponent: env.BLOCKLET_DID !== env.BLOCKLET_REAL_DID,
|
|
25
|
+
dataDir: env.BLOCKLET_DATA_DIR,
|
|
26
|
+
cacheDir: env.BLOCKLET_CACHE_DIR,
|
|
27
|
+
mode: env.BLOCKLET_MODE,
|
|
28
|
+
appStorageEndpoint: env.BLOCKLET_APP_SPACE_ENDPOINT,
|
|
29
|
+
serverVersion: env.ABT_NODE,
|
|
30
|
+
preferences,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exports.parseEnv = parseEnv;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TNotificationInput, TSendOptions } from '../types/notification';
|
|
2
|
+
export type TNotificationSender = {
|
|
3
|
+
appDid: string;
|
|
4
|
+
appSk: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* @param {String|Array} receiver
|
|
8
|
+
* @param {Object} notification
|
|
9
|
+
* @param {{
|
|
10
|
+
* appDid: String
|
|
11
|
+
* appSk: String
|
|
12
|
+
* }} sender
|
|
13
|
+
* @param {String|Number} port port of abtnode service endpoint
|
|
14
|
+
* @param {Object} options
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
declare const sendToUser: (receiver: string | string[], notification: TNotificationInput, { appDid, appSk }: TNotificationSender, port?: string, options?: {}) => Promise<any>;
|
|
18
|
+
declare const sendToAppChannel: (channel: string, event: string, notification: TNotificationInput, { appDid, appSk }: TNotificationSender, port?: string, options?: TSendOptions) => Promise<any>;
|
|
19
|
+
declare const sendToRelay: (topic: string, event: string, data: any, { appDid, appSk }: TNotificationSender, port?: string) => Promise<any>;
|
|
20
|
+
export { sendToUser, sendToAppChannel, sendToRelay };
|
|
21
|
+
declare const _default: {
|
|
22
|
+
sendToUser: (receiver: string | string[], notification: TNotificationInput, { appDid, appSk }: TNotificationSender, port?: string, options?: {}) => Promise<any>;
|
|
23
|
+
sendToAppChannel: (channel: string, event: string, notification: TNotificationInput, { appDid, appSk }: TNotificationSender, port?: string, options?: TSendOptions) => Promise<any>;
|
|
24
|
+
sendToRelay: (topic: string, event: string, data: any, { appDid, appSk }: TNotificationSender, port?: string) => Promise<any>;
|
|
25
|
+
};
|
|
26
|
+
export default _default;
|
|
@@ -1,45 +1,156 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.sendToRelay = exports.sendToAppChannel = exports.sendToUser = void 0;
|
|
30
|
+
const axios_1 = __importDefault(require("axios"));
|
|
31
|
+
const pick_1 = __importDefault(require("lodash/pick"));
|
|
32
|
+
const JWT = __importStar(require("@arcblock/jwt"));
|
|
33
|
+
const constant_1 = __importDefault(require("@abtnode/constant"));
|
|
34
|
+
const channel_1 = require("@blocklet/meta/lib/channel");
|
|
35
|
+
const index_1 = require("../validators/index");
|
|
36
|
+
const constants_1 = require("./constants");
|
|
37
|
+
const version_1 = require("../version");
|
|
38
|
+
const axios = axios_1.default.create({ proxy: false });
|
|
39
|
+
const { NODE_MODES } = constant_1.default;
|
|
40
|
+
const VERSION = version_1.version; // version of notification sdk
|
|
41
|
+
const SERVER_MODE = process.env.ABT_NODE_MODE;
|
|
42
|
+
const getRequestHeaders = () => ({ 'User-Agent': `BlockletSDK/${VERSION}` });
|
|
13
43
|
/**
|
|
14
44
|
* @param {String|Array} receiver
|
|
15
45
|
* @param {Object} notification
|
|
16
|
-
* @param {
|
|
46
|
+
* @param {{
|
|
47
|
+
* appDid: String
|
|
48
|
+
* appSk: String
|
|
49
|
+
* }} sender
|
|
17
50
|
* @param {String|Number} port port of abtnode service endpoint
|
|
51
|
+
* @param {Object} options
|
|
18
52
|
* @returns
|
|
19
53
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
54
|
+
const sendToUser = async (receiver, notification, { appDid, appSk }, port = process.env.ABT_NODE_SERVICE_PORT, options = {}) => {
|
|
55
|
+
await (0, index_1.validateReceiver)(receiver);
|
|
56
|
+
const opt = (0, pick_1.default)(options, ['keepForOfflineUser']);
|
|
57
|
+
await (0, index_1.validateOption)(opt);
|
|
58
|
+
if (SERVER_MODE !== NODE_MODES.DEBUG) {
|
|
59
|
+
await (0, index_1.validateNotification)(notification);
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const { data: res } = await axios.post(`http://127.0.0.1:${port}${constants_1.SERVICE_PREFIX}/api/send-to-user`, {
|
|
63
|
+
apiVersion: VERSION,
|
|
64
|
+
data: {
|
|
65
|
+
sender: { appDid, token: JWT.sign(appDid, appSk) },
|
|
66
|
+
receiver,
|
|
67
|
+
notification,
|
|
68
|
+
options: opt,
|
|
69
|
+
},
|
|
70
|
+
}, {
|
|
71
|
+
timeout: 60 * 1000,
|
|
72
|
+
headers: getRequestHeaders(),
|
|
73
|
+
});
|
|
74
|
+
return res;
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
console.error(err.response ? err.response.data : err);
|
|
78
|
+
throw new Error(err.response ? err.response.data : err.message);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
exports.sendToUser = sendToUser;
|
|
82
|
+
const sendToAppChannel = async (channel, event, notification, { appDid, appSk }, port = process.env.ABT_NODE_SERVICE_PORT, options = {}) => {
|
|
83
|
+
if (!channel) {
|
|
84
|
+
throw new Error('channel is required');
|
|
85
|
+
}
|
|
86
|
+
if (!event) {
|
|
87
|
+
throw new Error('event is required');
|
|
88
|
+
}
|
|
89
|
+
await (0, index_1.validateChannelEvent)(event);
|
|
90
|
+
const opt = (0, pick_1.default)(options, ['socketId', 'userDid']);
|
|
91
|
+
if (opt.userDid) {
|
|
92
|
+
// @ts-expect-error TS(2551) FIXME: Property 'socketDid' does not exist on type 'Pick<... Remove this comment to see the full error message
|
|
93
|
+
opt.socketDid = opt.userDid;
|
|
94
|
+
delete opt.userDid;
|
|
95
|
+
}
|
|
96
|
+
if (SERVER_MODE !== NODE_MODES.DEBUG) {
|
|
97
|
+
await (0, index_1.validateNotification)(notification);
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
const { data: res } = await axios.post(`http://127.0.0.1:${port}${constants_1.SERVICE_PREFIX}/api/send-to-app-channel`, {
|
|
101
|
+
apiVersion: VERSION,
|
|
102
|
+
data: {
|
|
103
|
+
sender: { appDid, token: JWT.sign(appDid, appSk) },
|
|
104
|
+
channel,
|
|
105
|
+
event,
|
|
106
|
+
notification,
|
|
107
|
+
options: opt,
|
|
108
|
+
},
|
|
109
|
+
}, {
|
|
110
|
+
timeout: 60 * 1000,
|
|
111
|
+
headers: getRequestHeaders(),
|
|
112
|
+
});
|
|
113
|
+
return res;
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
console.error(err.response ? err.response.data : err);
|
|
117
|
+
throw new Error(err.response ? err.response.data : err.message);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
exports.sendToAppChannel = sendToAppChannel;
|
|
121
|
+
const sendToRelay = async (topic, event, data, { appDid, appSk }, port = process.env.ABT_NODE_SERVICE_PORT) => {
|
|
122
|
+
if (!topic) {
|
|
123
|
+
throw new Error('topic is required');
|
|
124
|
+
}
|
|
125
|
+
if (!event) {
|
|
126
|
+
throw new Error('event is required');
|
|
127
|
+
}
|
|
128
|
+
if (!data) {
|
|
129
|
+
throw new Error('data is required');
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
const { data: res } = await axios.post(`http://127.0.0.1:${port}${constants_1.SERVICE_PREFIX}/relay/api/send-to-relay-channel`, {
|
|
133
|
+
apiVersion: VERSION,
|
|
134
|
+
data: {
|
|
135
|
+
sender: { appDid, token: JWT.sign(appDid, appSk) },
|
|
136
|
+
channel: (0, channel_1.getRelayChannel)(appDid, topic),
|
|
137
|
+
event,
|
|
138
|
+
data,
|
|
139
|
+
},
|
|
140
|
+
}, {
|
|
141
|
+
timeout: 60 * 1000,
|
|
142
|
+
headers: getRequestHeaders(),
|
|
143
|
+
});
|
|
144
|
+
return res;
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
console.error(err.response ? err.response.data : err);
|
|
148
|
+
throw new Error(err.response ? err.response.data : err.message);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
exports.sendToRelay = sendToRelay;
|
|
152
|
+
exports.default = {
|
|
153
|
+
sendToUser,
|
|
154
|
+
sendToAppChannel,
|
|
155
|
+
sendToRelay,
|
|
45
156
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { validateNotification, validateReceiver, validateOption, validateChannelEvent } from './notification';
|
|
2
|
+
export { validateNotification };
|
|
3
|
+
export { validateReceiver };
|
|
4
|
+
export { validateOption };
|
|
5
|
+
export { validateChannelEvent };
|
|
6
|
+
declare const _default: {
|
|
7
|
+
validateNotification: any;
|
|
8
|
+
validateReceiver: any;
|
|
9
|
+
validateOption: any;
|
|
10
|
+
validateChannelEvent: any;
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
package/lib/validators/index.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateChannelEvent = exports.validateOption = exports.validateReceiver = exports.validateNotification = void 0;
|
|
4
|
+
const notification_1 = require("./notification");
|
|
5
|
+
Object.defineProperty(exports, "validateNotification", { enumerable: true, get: function () { return notification_1.validateNotification; } });
|
|
6
|
+
Object.defineProperty(exports, "validateReceiver", { enumerable: true, get: function () { return notification_1.validateReceiver; } });
|
|
7
|
+
Object.defineProperty(exports, "validateOption", { enumerable: true, get: function () { return notification_1.validateOption; } });
|
|
8
|
+
Object.defineProperty(exports, "validateChannelEvent", { enumerable: true, get: function () { return notification_1.validateChannelEvent; } });
|
|
9
|
+
exports.default = {
|
|
10
|
+
validateNotification: notification_1.validateNotification,
|
|
11
|
+
validateReceiver: notification_1.validateReceiver,
|
|
12
|
+
validateOption: notification_1.validateOption,
|
|
13
|
+
validateChannelEvent: notification_1.validateChannelEvent,
|
|
6
14
|
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import JOI from 'joi';
|
|
2
|
+
declare const TYPES: {
|
|
3
|
+
NOTIFICATION: string;
|
|
4
|
+
CONNECT: string;
|
|
5
|
+
FEED: string;
|
|
6
|
+
HI: string;
|
|
7
|
+
};
|
|
8
|
+
declare const assetSchema: JOI.ObjectSchema<any>;
|
|
9
|
+
declare const vcSchema: JOI.ObjectSchema<any>;
|
|
10
|
+
declare const tokenSchema: JOI.ObjectSchema<any>;
|
|
11
|
+
declare const textSchema: JOI.ObjectSchema<any>;
|
|
12
|
+
declare const imageSchema: JOI.ObjectSchema<any>;
|
|
13
|
+
declare const transactionSchema: JOI.ObjectSchema<any>;
|
|
14
|
+
declare const dappSchema: JOI.ObjectSchema<any>;
|
|
15
|
+
declare const linkSchema: JOI.ObjectSchema<any>;
|
|
16
|
+
declare const actionSchema: JOI.ObjectSchema<any>;
|
|
17
|
+
declare const attachmentSchema: JOI.ObjectSchema<any>;
|
|
18
|
+
declare const notificationTypeSchema: JOI.ObjectSchema<any>;
|
|
19
|
+
declare const connectTypeSchema: JOI.ObjectSchema<any>;
|
|
20
|
+
declare const feedTypeSchema: JOI.ObjectSchema<any>;
|
|
21
|
+
declare const notificationSchema: JOI.ObjectSchema<any>;
|
|
22
|
+
declare const messageSchema: JOI.ObjectSchema<any>;
|
|
23
|
+
declare const inputNotificationSchema: JOI.ArraySchema<any[]>;
|
|
24
|
+
declare const optionSchema: JOI.ObjectSchema<any>;
|
|
25
|
+
declare const channelEventSchema: JOI.StringSchema<string>;
|
|
26
|
+
export declare const validateReceiver: any;
|
|
27
|
+
export declare const validateNotification: any;
|
|
28
|
+
export declare const validateMessage: any;
|
|
29
|
+
export declare const validateChannelEvent: any;
|
|
30
|
+
export declare const validateOption: any;
|
|
31
|
+
export { tokenSchema };
|
|
32
|
+
export { actionSchema };
|
|
33
|
+
export { assetSchema };
|
|
34
|
+
export { vcSchema };
|
|
35
|
+
export { transactionSchema };
|
|
36
|
+
export { textSchema };
|
|
37
|
+
export { linkSchema };
|
|
38
|
+
export { imageSchema };
|
|
39
|
+
export { dappSchema };
|
|
40
|
+
export { attachmentSchema };
|
|
41
|
+
export { notificationSchema };
|
|
42
|
+
export { messageSchema };
|
|
43
|
+
export { optionSchema };
|
|
44
|
+
export { channelEventSchema };
|
|
45
|
+
export { TYPES as NOTIFICATION_TYPES };
|
|
46
|
+
export { inputNotificationSchema, notificationTypeSchema, connectTypeSchema, feedTypeSchema };
|
|
47
|
+
declare const _default: {
|
|
48
|
+
validateReceiver: any;
|
|
49
|
+
validateNotification: any;
|
|
50
|
+
validateMessage: any;
|
|
51
|
+
validateChannelEvent: any;
|
|
52
|
+
validateOption: any;
|
|
53
|
+
tokenSchema: JOI.ObjectSchema<any>;
|
|
54
|
+
actionSchema: JOI.ObjectSchema<any>;
|
|
55
|
+
assetSchema: JOI.ObjectSchema<any>;
|
|
56
|
+
vcSchema: JOI.ObjectSchema<any>;
|
|
57
|
+
transactionSchema: JOI.ObjectSchema<any>;
|
|
58
|
+
textSchema: JOI.ObjectSchema<any>;
|
|
59
|
+
linkSchema: JOI.ObjectSchema<any>;
|
|
60
|
+
imageSchema: JOI.ObjectSchema<any>;
|
|
61
|
+
dappSchema: JOI.ObjectSchema<any>;
|
|
62
|
+
attachmentSchema: JOI.ObjectSchema<any>;
|
|
63
|
+
notificationSchema: JOI.ObjectSchema<any>;
|
|
64
|
+
messageSchema: JOI.ObjectSchema<any>;
|
|
65
|
+
optionSchema: JOI.ObjectSchema<any>;
|
|
66
|
+
channelEventSchema: JOI.StringSchema<string>;
|
|
67
|
+
NOTIFICATION_TYPES: {
|
|
68
|
+
NOTIFICATION: string;
|
|
69
|
+
CONNECT: string;
|
|
70
|
+
FEED: string;
|
|
71
|
+
HI: string;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
export default _default;
|