@blocklet/sdk 1.8.32 → 1.8.34
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/component/index.d.ts +35 -0
- package/lib/component/index.js +83 -80
- package/lib/config.d.ts +33 -0
- package/lib/config.js +10 -7
- package/lib/connect/authenticator.d.ts +5 -0
- package/lib/connect/authenticator.js +14 -15
- package/lib/connect/handler.d.ts +2 -0
- package/lib/connect/handler.js +91 -65
- package/lib/connect/shared.d.ts +13 -0
- package/lib/connect/shared.js +26 -31
- package/lib/database/index.d.ts +13 -0
- package/lib/database/index.js +52 -39
- package/lib/env.d.ts +12 -0
- package/lib/env.js +12 -9
- package/lib/error-handler.d.ts +0 -0
- package/lib/error-handler.js +5 -5
- package/lib/index.d.ts +51 -0
- package/lib/index.js +51 -40
- package/lib/middlewares/auth.d.ts +3 -0
- package/lib/middlewares/auth.js +52 -49
- package/lib/middlewares/component.d.ts +7 -0
- package/lib/middlewares/component.js +28 -24
- package/lib/middlewares/index.d.ts +20 -0
- package/lib/middlewares/index.js +16 -8
- package/lib/middlewares/user.d.ts +10 -0
- package/lib/middlewares/user.js +20 -10
- package/lib/security/index.d.ts +9 -0
- package/lib/security/index.js +22 -21
- package/lib/service/auth.d.ts +9 -0
- package/lib/service/auth.js +131 -165
- package/lib/service/notification.d.ts +44 -0
- package/lib/service/notification.js +149 -129
- package/lib/types/notification.d.ts +71 -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 -19
- package/lib/util/constants.d.ts +5 -0
- package/lib/util/constants.js +6 -2
- package/lib/util/send-notification.d.ts +25 -0
- package/lib/util/send-notification.js +118 -115
- package/lib/validators/index.d.ts +12 -0
- package/lib/validators/index.js +13 -7
- package/lib/validators/notification.d.ts +59 -0
- package/lib/validators/notification.js +127 -97
- 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 +13 -16
- package/lib/wallet-handler.d.ts +17 -0
- package/lib/wallet-handler.js +121 -88
- package/lib/wallet.d.ts +3 -0
- package/lib/wallet.js +9 -10
- package/package.json +40 -18
|
@@ -1,21 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.sendToAppChannel = exports.sendToUser = void 0;
|
|
39
|
+
const axios_1 = __importDefault(require("axios"));
|
|
40
|
+
const pick_1 = __importDefault(require("lodash/pick"));
|
|
41
|
+
const JWT = __importStar(require("@arcblock/jwt"));
|
|
42
|
+
const constant_1 = __importDefault(require("@abtnode/constant"));
|
|
43
|
+
const index_1 = require("../validators/index");
|
|
44
|
+
const constants_1 = require("./constants");
|
|
45
|
+
const version_1 = require("../version");
|
|
46
|
+
const axios = axios_1.default.create({ proxy: false });
|
|
47
|
+
const { NODE_MODES } = constant_1.default;
|
|
48
|
+
const VERSION = version_1.version; // version of notification sdk
|
|
15
49
|
const SERVER_MODE = process.env.ABT_NODE_MODE;
|
|
16
|
-
|
|
17
50
|
const getRequestHeaders = () => ({ 'User-Agent': `BlockletSDK/${VERSION}` });
|
|
18
|
-
|
|
19
51
|
/**
|
|
20
52
|
* @param {String|Array} receiver
|
|
21
53
|
* @param {Object} notification
|
|
@@ -27,103 +59,74 @@ const getRequestHeaders = () => ({ 'User-Agent': `BlockletSDK/${VERSION}` });
|
|
|
27
59
|
* @param {Object} options
|
|
28
60
|
* @returns
|
|
29
61
|
*/
|
|
30
|
-
const sendToUser =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
try {
|
|
101
|
-
const { data: res } = await axios.post(
|
|
102
|
-
`http://127.0.0.1:${port}${SERVICE_PREFIX}/api/send-to-app-channel`,
|
|
103
|
-
{
|
|
104
|
-
apiVersion: VERSION,
|
|
105
|
-
data: {
|
|
106
|
-
sender: { appDid, token: JWT.sign(appDid, appSk) },
|
|
107
|
-
channel,
|
|
108
|
-
event,
|
|
109
|
-
notification,
|
|
110
|
-
options: opt,
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
timeout: 60 * 1000,
|
|
115
|
-
headers: getRequestHeaders(),
|
|
116
|
-
}
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
return res;
|
|
120
|
-
} catch (error) {
|
|
121
|
-
console.error(error);
|
|
122
|
-
throw new Error(error.response ? error.response.statusText : error.message);
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
module.exports = {
|
|
127
|
-
sendToUser,
|
|
128
|
-
sendToAppChannel,
|
|
62
|
+
const sendToUser = (receiver, notification, { appDid, appSk }, port = process.env.ABT_NODE_SERVICE_PORT, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
yield (0, index_1.validateReceiver)(receiver);
|
|
64
|
+
const opt = (0, pick_1.default)(options, ['keepForOfflineUser']);
|
|
65
|
+
yield (0, index_1.validateOption)(opt);
|
|
66
|
+
if (SERVER_MODE !== NODE_MODES.DEBUG) {
|
|
67
|
+
yield (0, index_1.validateNotification)(notification);
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const { data: res } = yield axios.post(`http://127.0.0.1:${port}${constants_1.SERVICE_PREFIX}/api/send-to-user`, {
|
|
71
|
+
apiVersion: VERSION,
|
|
72
|
+
data: {
|
|
73
|
+
sender: { appDid, token: JWT.sign(appDid, appSk) },
|
|
74
|
+
receiver,
|
|
75
|
+
notification,
|
|
76
|
+
options: opt,
|
|
77
|
+
},
|
|
78
|
+
}, {
|
|
79
|
+
timeout: 60 * 1000,
|
|
80
|
+
headers: getRequestHeaders(),
|
|
81
|
+
});
|
|
82
|
+
return res;
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
console.error(err.response ? err.response.data : err);
|
|
86
|
+
throw new Error(err.response ? err.response.data : err.message);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
exports.sendToUser = sendToUser;
|
|
90
|
+
const sendToAppChannel = (channel, event, notification, { appDid, appSk }, port = process.env.ABT_NODE_SERVICE_PORT, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
|
+
if (!channel) {
|
|
92
|
+
throw new Error('channel is required');
|
|
93
|
+
}
|
|
94
|
+
if (!event) {
|
|
95
|
+
throw new Error('event is required');
|
|
96
|
+
}
|
|
97
|
+
yield (0, index_1.validateChannelEvent)(event);
|
|
98
|
+
const opt = (0, pick_1.default)(options, ['socketId', 'userDid']);
|
|
99
|
+
if (opt.userDid) {
|
|
100
|
+
// @ts-expect-error TS(2551) FIXME: Property 'socketDid' does not exist on type 'Pick<... Remove this comment to see the full error message
|
|
101
|
+
opt.socketDid = opt.userDid;
|
|
102
|
+
delete opt.userDid;
|
|
103
|
+
}
|
|
104
|
+
if (SERVER_MODE !== NODE_MODES.DEBUG) {
|
|
105
|
+
yield (0, index_1.validateNotification)(notification);
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
const { data: res } = yield axios.post(`http://127.0.0.1:${port}${constants_1.SERVICE_PREFIX}/api/send-to-app-channel`, {
|
|
109
|
+
apiVersion: VERSION,
|
|
110
|
+
data: {
|
|
111
|
+
sender: { appDid, token: JWT.sign(appDid, appSk) },
|
|
112
|
+
channel,
|
|
113
|
+
event,
|
|
114
|
+
notification,
|
|
115
|
+
options: opt,
|
|
116
|
+
},
|
|
117
|
+
}, {
|
|
118
|
+
timeout: 60 * 1000,
|
|
119
|
+
headers: getRequestHeaders(),
|
|
120
|
+
});
|
|
121
|
+
return res;
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
console.error(err.response ? err.response.data : err);
|
|
125
|
+
throw new Error(err.response ? err.response.data : err.message);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
exports.sendToAppChannel = sendToAppChannel;
|
|
129
|
+
exports.default = {
|
|
130
|
+
sendToUser,
|
|
131
|
+
sendToAppChannel,
|
|
129
132
|
};
|
|
@@ -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,8 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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,
|
|
8
14
|
};
|
|
@@ -0,0 +1,59 @@
|
|
|
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 actionSchema: JOI.ObjectSchema<any>;
|
|
12
|
+
declare const attachmentSchema: JOI.ObjectSchema<any>;
|
|
13
|
+
declare const notificationTypeSchema: JOI.ObjectSchema<any>;
|
|
14
|
+
declare const connectTypeSchema: JOI.ObjectSchema<any>;
|
|
15
|
+
declare const feedTypeSchema: JOI.ObjectSchema<any>;
|
|
16
|
+
declare const notificationSchema: JOI.AlternativesSchema<any>;
|
|
17
|
+
declare const messageSchema: JOI.ObjectSchema<any>;
|
|
18
|
+
declare const inputNotificationSchema: JOI.AlternativesSchema<any>;
|
|
19
|
+
declare const optionSchema: JOI.ObjectSchema<any>;
|
|
20
|
+
declare const channelEventSchema: JOI.StringSchema<string>;
|
|
21
|
+
export declare const validateReceiver: any;
|
|
22
|
+
export declare const validateNotification: any;
|
|
23
|
+
export declare const validateMessage: any;
|
|
24
|
+
export declare const validateChannelEvent: any;
|
|
25
|
+
export declare const validateOption: any;
|
|
26
|
+
export { tokenSchema };
|
|
27
|
+
export { actionSchema };
|
|
28
|
+
export { assetSchema };
|
|
29
|
+
export { vcSchema };
|
|
30
|
+
export { attachmentSchema };
|
|
31
|
+
export { notificationSchema };
|
|
32
|
+
export { messageSchema };
|
|
33
|
+
export { optionSchema };
|
|
34
|
+
export { channelEventSchema };
|
|
35
|
+
export { TYPES as NOTIFICATION_TYPES };
|
|
36
|
+
export { inputNotificationSchema, notificationTypeSchema, connectTypeSchema, feedTypeSchema };
|
|
37
|
+
declare const _default: {
|
|
38
|
+
validateReceiver: any;
|
|
39
|
+
validateNotification: any;
|
|
40
|
+
validateMessage: any;
|
|
41
|
+
validateChannelEvent: any;
|
|
42
|
+
validateOption: any;
|
|
43
|
+
tokenSchema: JOI.ObjectSchema<any>;
|
|
44
|
+
actionSchema: JOI.ObjectSchema<any>;
|
|
45
|
+
assetSchema: JOI.ObjectSchema<any>;
|
|
46
|
+
vcSchema: JOI.ObjectSchema<any>;
|
|
47
|
+
attachmentSchema: JOI.ObjectSchema<any>;
|
|
48
|
+
notificationSchema: JOI.AlternativesSchema<any>;
|
|
49
|
+
messageSchema: JOI.ObjectSchema<any>;
|
|
50
|
+
optionSchema: JOI.ObjectSchema<any>;
|
|
51
|
+
channelEventSchema: JOI.StringSchema<string>;
|
|
52
|
+
NOTIFICATION_TYPES: {
|
|
53
|
+
NOTIFICATION: string;
|
|
54
|
+
CONNECT: string;
|
|
55
|
+
FEED: string;
|
|
56
|
+
HI: string;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export default _default;
|
|
@@ -1,112 +1,142 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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.feedTypeSchema = exports.connectTypeSchema = exports.notificationTypeSchema = exports.inputNotificationSchema = exports.NOTIFICATION_TYPES = exports.channelEventSchema = exports.optionSchema = exports.messageSchema = exports.notificationSchema = exports.attachmentSchema = exports.vcSchema = exports.assetSchema = exports.actionSchema = exports.tokenSchema = exports.validateOption = exports.validateChannelEvent = exports.validateMessage = exports.validateNotification = exports.validateReceiver = void 0;
|
|
7
|
+
const joi_1 = __importDefault(require("joi"));
|
|
8
|
+
const extension_1 = require("@blocklet/meta/lib/extension");
|
|
9
|
+
const Joi = joi_1.default.extend(extension_1.didExtension);
|
|
7
10
|
const TYPES = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
NOTIFICATION: 'notification',
|
|
12
|
+
CONNECT: 'connect',
|
|
13
|
+
FEED: 'feed',
|
|
14
|
+
HI: 'hi',
|
|
12
15
|
};
|
|
13
|
-
|
|
16
|
+
exports.NOTIFICATION_TYPES = TYPES;
|
|
14
17
|
const assetSchema = Joi.object({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
})
|
|
18
|
-
|
|
18
|
+
did: Joi.DID().trim().required(),
|
|
19
|
+
chainHost: Joi.string().uri().required(),
|
|
20
|
+
})
|
|
21
|
+
.required()
|
|
22
|
+
.meta({ className: 'TDataAsset' });
|
|
23
|
+
exports.assetSchema = assetSchema;
|
|
19
24
|
const vcSchema = Joi.object({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
})
|
|
23
|
-
|
|
25
|
+
credential: Joi.object().required().unknown(true),
|
|
26
|
+
tag: Joi.string(),
|
|
27
|
+
})
|
|
28
|
+
.required()
|
|
29
|
+
.meta({ className: 'TDataVC', unknownType: 'any' });
|
|
30
|
+
exports.vcSchema = vcSchema;
|
|
24
31
|
const tokenSchema = Joi.object({
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
})
|
|
32
|
-
|
|
32
|
+
address: Joi.DID().trim().allow(''),
|
|
33
|
+
amount: Joi.string().required(),
|
|
34
|
+
symbol: Joi.string().required(),
|
|
35
|
+
senderDid: Joi.DID().trim().required(),
|
|
36
|
+
chainHost: Joi.string().uri().required(),
|
|
37
|
+
decimal: Joi.number().integer().required(),
|
|
38
|
+
})
|
|
39
|
+
.required()
|
|
40
|
+
.meta({ className: 'TDataToken' });
|
|
41
|
+
exports.tokenSchema = tokenSchema;
|
|
33
42
|
const actionSchema = Joi.object({
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
40
|
-
|
|
43
|
+
name: Joi.string().required(),
|
|
44
|
+
title: Joi.string(),
|
|
45
|
+
color: Joi.string(),
|
|
46
|
+
bgColor: Joi.string(),
|
|
47
|
+
link: Joi.string().uri(),
|
|
48
|
+
}).meta({ className: 'TNotificationAction' });
|
|
49
|
+
exports.actionSchema = actionSchema;
|
|
41
50
|
const attachmentSchema = Joi.object({
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
})
|
|
48
|
-
|
|
51
|
+
type: Joi.string().required().valid('asset', 'vc', 'token'),
|
|
52
|
+
data: Joi.object()
|
|
53
|
+
.when('type', { is: 'asset', then: assetSchema })
|
|
54
|
+
.concat(Joi.object().when('type', { is: 'vc', then: vcSchema }))
|
|
55
|
+
.concat(Joi.object().when('type', { is: 'token', then: tokenSchema })),
|
|
56
|
+
})
|
|
57
|
+
.required()
|
|
58
|
+
.meta({ className: 'TNotificationAttachment' });
|
|
59
|
+
exports.attachmentSchema = attachmentSchema;
|
|
49
60
|
const notificationTypeSchema = Joi.object({
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
})
|
|
56
|
-
|
|
61
|
+
type: Joi.string().valid(TYPES.NOTIFICATION),
|
|
62
|
+
title: Joi.string(),
|
|
63
|
+
body: Joi.string(),
|
|
64
|
+
attachments: Joi.array().items(attachmentSchema).default([]),
|
|
65
|
+
actions: Joi.array().items(actionSchema).default([]),
|
|
66
|
+
})
|
|
67
|
+
.required()
|
|
68
|
+
.meta({ className: 'TNotificationItem' });
|
|
69
|
+
exports.notificationTypeSchema = notificationTypeSchema;
|
|
57
70
|
const connectTypeSchema = Joi.object({
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
})
|
|
62
|
-
|
|
71
|
+
type: Joi.string().valid(TYPES.CONNECT),
|
|
72
|
+
url: Joi.string().uri().required(),
|
|
73
|
+
checkUrl: Joi.string().uri(),
|
|
74
|
+
})
|
|
75
|
+
.required()
|
|
76
|
+
.meta({ className: 'TNotificationConnect' });
|
|
77
|
+
exports.connectTypeSchema = connectTypeSchema;
|
|
63
78
|
const feedTypeSchema = Joi.object({
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
79
|
+
type: Joi.string().valid(TYPES.FEED),
|
|
80
|
+
feedType: Joi.string().required(),
|
|
81
|
+
data: Joi.object().required(),
|
|
82
|
+
})
|
|
83
|
+
.required()
|
|
84
|
+
.meta({ className: 'TNotificationFeed' });
|
|
85
|
+
exports.feedTypeSchema = feedTypeSchema;
|
|
86
|
+
const notificationSchema = Joi.alternatives()
|
|
87
|
+
.try(notificationTypeSchema, connectTypeSchema, feedTypeSchema)
|
|
88
|
+
.required()
|
|
89
|
+
.meta({ className: 'TNotification' });
|
|
90
|
+
exports.notificationSchema = notificationSchema;
|
|
71
91
|
const messageSchema = Joi.object({
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
92
|
+
id: Joi.string().required(),
|
|
93
|
+
createdAt: Joi.date().iso().required(),
|
|
94
|
+
type: Joi.string().required(),
|
|
95
|
+
receiver: Joi.object({
|
|
96
|
+
did: Joi.DID().trim().required(),
|
|
97
|
+
}).required(),
|
|
78
98
|
})
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
99
|
+
.unknown()
|
|
100
|
+
.required()
|
|
101
|
+
.meta({ className: 'TMessage', unknownType: 'any' });
|
|
102
|
+
exports.messageSchema = messageSchema;
|
|
103
|
+
const receiverSchema = Joi.DID().trim().required().meta({ className: 'TReceiver' });
|
|
84
104
|
const inputNotificationSchema = Joi.alternatives()
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
105
|
+
.try(Joi.array().items(notificationSchema), notificationSchema)
|
|
106
|
+
.required()
|
|
107
|
+
.meta({ className: 'TNotificationInput' });
|
|
108
|
+
exports.inputNotificationSchema = inputNotificationSchema;
|
|
109
|
+
const inputReceiverSchema = Joi.alternatives()
|
|
110
|
+
.try(Joi.array().items(receiverSchema), receiverSchema)
|
|
111
|
+
.required()
|
|
112
|
+
.meta({ className: 'TReceiverInput' });
|
|
90
113
|
const optionSchema = Joi.object({
|
|
91
|
-
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
114
|
+
keepForOfflineUser: Joi.boolean(),
|
|
115
|
+
})
|
|
116
|
+
.unknown()
|
|
117
|
+
.meta({ className: 'TSendOptions', unknownType: 'any' });
|
|
118
|
+
exports.optionSchema = optionSchema;
|
|
119
|
+
const channelEventSchema = Joi.string().required().meta({ className: 'TChannelEvent' });
|
|
120
|
+
exports.channelEventSchema = channelEventSchema;
|
|
121
|
+
exports.validateReceiver = inputReceiverSchema.validateAsync.bind(inputReceiverSchema);
|
|
122
|
+
exports.validateNotification = inputNotificationSchema.validateAsync.bind(inputNotificationSchema);
|
|
123
|
+
exports.validateMessage = messageSchema.validateAsync.bind(messageSchema);
|
|
124
|
+
exports.validateChannelEvent = channelEventSchema.validateAsync.bind(channelEventSchema);
|
|
125
|
+
exports.validateOption = optionSchema.validateAsync.bind(optionSchema);
|
|
126
|
+
exports.default = {
|
|
127
|
+
validateReceiver: exports.validateReceiver,
|
|
128
|
+
validateNotification: exports.validateNotification,
|
|
129
|
+
validateMessage: exports.validateMessage,
|
|
130
|
+
validateChannelEvent: exports.validateChannelEvent,
|
|
131
|
+
validateOption: exports.validateOption,
|
|
132
|
+
tokenSchema,
|
|
133
|
+
actionSchema,
|
|
134
|
+
assetSchema,
|
|
135
|
+
vcSchema,
|
|
136
|
+
attachmentSchema,
|
|
137
|
+
notificationSchema,
|
|
138
|
+
messageSchema,
|
|
139
|
+
optionSchema,
|
|
140
|
+
channelEventSchema,
|
|
141
|
+
NOTIFICATION_TYPES: TYPES,
|
|
112
142
|
};
|
package/lib/version.d.ts
ADDED
package/lib/version.js
ADDED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
});
|
|
15
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const did_auth_1 = require("@arcblock/did-auth");
|
|
6
|
+
const wallet_1 = __importDefault(require("./wallet"));
|
|
7
|
+
const check_blocklet_env_1 = __importDefault(require("./util/check-blocklet-env"));
|
|
8
|
+
const shared_1 = __importDefault(require("./connect/shared"));
|
|
9
|
+
class WalletAuthenticator extends did_auth_1.WalletAuthenticator {
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
(0, check_blocklet_env_1.default)();
|
|
12
|
+
super(Object.assign({ wallet: (0, wallet_1.default)().toJSON() }, (0, shared_1.default)(options)));
|
|
13
|
+
}
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
module.exports = WalletAuthenticator;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { WalletHandlers as Handler } from '@arcblock/did-auth';
|
|
2
|
+
declare class WalletHandlers extends Handler {
|
|
3
|
+
enableConnect: boolean;
|
|
4
|
+
sendNotificationFn: $TSFixMe;
|
|
5
|
+
/**
|
|
6
|
+
* @param {boolean} autoConnect enable auto connect to wallet (wallet does not need to scan qr code)
|
|
7
|
+
* @param {boolean} connectedDidOnly only current login did or connected did can connect
|
|
8
|
+
* @param {function} sendNotificationFn use in a non-blocklet environment
|
|
9
|
+
*/
|
|
10
|
+
constructor({ autoConnect, connectedDidOnly, sendNotificationFn, options, ...opts }: $TSFixMe);
|
|
11
|
+
getConnectedDid: ({ req, didwallet, extraParams }: $TSFixMe) => any;
|
|
12
|
+
attach({ onStart, ...opts }: {
|
|
13
|
+
[x: string]: any;
|
|
14
|
+
onStart?: () => {};
|
|
15
|
+
}): void;
|
|
16
|
+
}
|
|
17
|
+
export = WalletHandlers;
|