@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.
Files changed (53) hide show
  1. package/lib/component/index.d.ts +35 -0
  2. package/lib/component/index.js +83 -80
  3. package/lib/config.d.ts +33 -0
  4. package/lib/config.js +10 -7
  5. package/lib/connect/authenticator.d.ts +5 -0
  6. package/lib/connect/authenticator.js +14 -15
  7. package/lib/connect/handler.d.ts +2 -0
  8. package/lib/connect/handler.js +91 -65
  9. package/lib/connect/shared.d.ts +13 -0
  10. package/lib/connect/shared.js +26 -31
  11. package/lib/database/index.d.ts +13 -0
  12. package/lib/database/index.js +52 -39
  13. package/lib/env.d.ts +12 -0
  14. package/lib/env.js +12 -9
  15. package/lib/error-handler.d.ts +0 -0
  16. package/lib/error-handler.js +5 -5
  17. package/lib/index.d.ts +51 -0
  18. package/lib/index.js +51 -40
  19. package/lib/middlewares/auth.d.ts +3 -0
  20. package/lib/middlewares/auth.js +52 -49
  21. package/lib/middlewares/component.d.ts +7 -0
  22. package/lib/middlewares/component.js +28 -24
  23. package/lib/middlewares/index.d.ts +20 -0
  24. package/lib/middlewares/index.js +16 -8
  25. package/lib/middlewares/user.d.ts +10 -0
  26. package/lib/middlewares/user.js +20 -10
  27. package/lib/security/index.d.ts +9 -0
  28. package/lib/security/index.js +22 -21
  29. package/lib/service/auth.d.ts +9 -0
  30. package/lib/service/auth.js +131 -165
  31. package/lib/service/notification.d.ts +44 -0
  32. package/lib/service/notification.js +149 -129
  33. package/lib/types/notification.d.ts +71 -0
  34. package/lib/types/notification.js +3 -0
  35. package/lib/util/check-blocklet-env.d.ts +2 -0
  36. package/lib/util/check-blocklet-env.js +20 -19
  37. package/lib/util/constants.d.ts +5 -0
  38. package/lib/util/constants.js +6 -2
  39. package/lib/util/send-notification.d.ts +25 -0
  40. package/lib/util/send-notification.js +118 -115
  41. package/lib/validators/index.d.ts +12 -0
  42. package/lib/validators/index.js +13 -7
  43. package/lib/validators/notification.d.ts +59 -0
  44. package/lib/validators/notification.js +127 -97
  45. package/lib/version.d.ts +6 -0
  46. package/lib/version.js +6 -0
  47. package/lib/wallet-authenticator.d.ts +5 -0
  48. package/lib/wallet-authenticator.js +13 -16
  49. package/lib/wallet-handler.d.ts +17 -0
  50. package/lib/wallet-handler.js +121 -88
  51. package/lib/wallet.d.ts +3 -0
  52. package/lib/wallet.js +9 -10
  53. package/package.json +40 -18
@@ -1,21 +1,53 @@
1
- /* eslint-disable global-require */
2
- const axios = require('axios').create({ proxy: false });
3
- const pick = require('lodash/pick');
4
-
5
- const JWT = require('@arcblock/jwt');
6
- const { NODE_MODES } = require('@abtnode/constant');
7
-
8
- const validators = require('../validators');
9
- const { SERVICE_PREFIX } = require('./constants');
10
-
11
- const VERSION = require('../../package.json').version; // version of notification sdk
12
-
13
- const { validateNotification, validateReceiver, validateOption, validateChannelEvent } = validators;
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 = async (
31
- receiver,
32
- notification,
33
- { appDid, appSk } = {},
34
- port = process.env.ABT_NODE_SERVICE_PORT,
35
- options = {}
36
- ) => {
37
- await validateReceiver(receiver);
38
-
39
- const opt = pick(options, ['keepForOfflineUser']);
40
- await validateOption(opt);
41
-
42
- if (SERVER_MODE !== NODE_MODES.DEBUG) {
43
- await validateNotification(notification);
44
- }
45
-
46
- try {
47
- const { data: res } = await axios.post(
48
- `http://127.0.0.1:${port}${SERVICE_PREFIX}/api/send-to-user`,
49
- {
50
- apiVersion: VERSION,
51
- data: {
52
- sender: { appDid, token: JWT.sign(appDid, appSk) },
53
- receiver,
54
- notification,
55
- options: opt,
56
- },
57
- },
58
- {
59
- timeout: 60 * 1000,
60
- headers: getRequestHeaders(),
61
- }
62
- );
63
-
64
- return res;
65
- } catch (error) {
66
- console.error(error);
67
- throw new Error(error.response ? error.response.statusText : error.message);
68
- }
69
- };
70
-
71
- const sendToAppChannel = async (
72
- channel,
73
- event,
74
- notification,
75
- { appDid, appSk } = {},
76
- port = process.env.ABT_NODE_SERVICE_PORT,
77
- options = {}
78
- ) => {
79
- if (!channel) {
80
- throw new Error('channel is required');
81
- }
82
-
83
- if (!event) {
84
- throw new Error('event is required');
85
- }
86
-
87
- await validateChannelEvent(event);
88
-
89
- const opt = pick(options, ['socketId', 'userDid']);
90
-
91
- if (opt.userDid) {
92
- opt.socketDid = opt.userDid;
93
- delete opt.userDid;
94
- }
95
-
96
- if (SERVER_MODE !== NODE_MODES.DEBUG) {
97
- await validateNotification(notification);
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;
@@ -1,8 +1,14 @@
1
- const { validateNotification, validateReceiver, validateOption, validateChannelEvent } = require('./notification');
2
-
3
- module.exports = {
4
- validateNotification,
5
- validateReceiver,
6
- validateOption,
7
- validateChannelEvent,
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
- const JOI = require('joi');
2
-
3
- const { didExtension } = require('@blocklet/meta/lib/extension');
4
-
5
- const Joi = JOI.extend(didExtension);
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
- NOTIFICATION: 'notification',
9
- CONNECT: 'connect',
10
- FEED: 'feed',
11
- HI: 'hi',
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
- did: Joi.DID().trim().required(),
16
- chainHost: Joi.string().uri().required(),
17
- }).required();
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
- credential: Joi.object().required().unknown(true),
21
- tag: Joi.string(),
22
- }).required();
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
- address: Joi.DID().trim().allow(''),
26
- amount: Joi.string().required(),
27
- symbol: Joi.string().required(),
28
- senderDid: Joi.DID().trim().required(),
29
- chainHost: Joi.string().uri().required(),
30
- decimal: Joi.number().integer().required(),
31
- }).required();
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
- name: Joi.string().required(),
35
- title: Joi.string(),
36
- color: Joi.string(),
37
- bgColor: Joi.string(),
38
- link: Joi.string().uri(),
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
- type: Joi.string().required().valid('asset', 'vc', 'token'),
43
- data: Joi.object()
44
- .when('type', { is: 'asset', then: assetSchema })
45
- .concat(Joi.object().when('type', { is: 'vc', then: vcSchema }))
46
- .concat(Joi.object().when('type', { is: 'token', then: tokenSchema })),
47
- }).required();
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
- type: Joi.string().valid(TYPES.NOTIFICATION),
51
- title: Joi.string(),
52
- body: Joi.string(),
53
- attachments: Joi.array().items(attachmentSchema).default([]),
54
- actions: Joi.array().items(actionSchema).default([]),
55
- }).required();
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
- type: Joi.string().valid(TYPES.CONNECT),
59
- url: Joi.string().uri().required(),
60
- checkUrl: Joi.string().uri(),
61
- }).required();
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
- type: Joi.string().valid(TYPES.FEED),
65
- feedType: Joi.string().required(),
66
- data: Joi.object().required(),
67
- }).required();
68
-
69
- const notificationSchema = Joi.alternatives().try(notificationTypeSchema, connectTypeSchema, feedTypeSchema).required();
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
- id: Joi.string().required(),
73
- createdAt: Joi.date().iso().required(),
74
- type: Joi.string().required(),
75
- receiver: Joi.object({
76
- did: Joi.DID().trim().required(),
77
- }).required(),
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
- .unknown()
80
- .required();
81
-
82
- const receiverSchema = Joi.DID().trim().required();
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
- .try(Joi.array().items(notificationSchema), notificationSchema)
86
- .required();
87
-
88
- const inputReceiverSchema = Joi.alternatives().try(Joi.array().items(receiverSchema), receiverSchema).required();
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
- keepForOfflineUser: Joi.boolean(),
92
- }).unknown();
93
-
94
- const channelEventSchema = Joi.string().required();
95
-
96
- module.exports = {
97
- validateReceiver: inputReceiverSchema.validateAsync.bind(inputReceiverSchema),
98
- validateNotification: inputNotificationSchema.validateAsync.bind(inputNotificationSchema),
99
- validateMessage: messageSchema.validateAsync.bind(messageSchema),
100
- validateChannelEvent: channelEventSchema.validateAsync.bind(channelEventSchema),
101
- validateOption: optionSchema.validateAsync.bind(optionSchema),
102
- tokenSchema,
103
- actionSchema,
104
- assetSchema,
105
- vcSchema,
106
- attachmentSchema,
107
- notificationSchema,
108
- messageSchema,
109
- optionSchema,
110
- channelEventSchema,
111
- NOTIFICATION_TYPES: TYPES,
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
  };
@@ -0,0 +1,6 @@
1
+ declare const version = "1.8.34";
2
+ export { version };
3
+ declare const _default: {
4
+ version: string;
5
+ };
6
+ export default _default;
package/lib/version.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.version = void 0;
4
+ const version = '1.8.34';
5
+ exports.version = version;
6
+ exports.default = { version };
@@ -0,0 +1,5 @@
1
+ import { WalletAuthenticator as Authenticator } from '@arcblock/did-auth';
2
+ declare class WalletAuthenticator extends Authenticator {
3
+ constructor(options?: {});
4
+ }
5
+ export = WalletAuthenticator;
@@ -1,18 +1,15 @@
1
- const { WalletAuthenticator: Authenticator } = require('@arcblock/did-auth');
2
-
3
- const getWallet = require('./wallet');
4
- const checkBlockletEnv = require('./util/check-blocklet-env');
5
- const getShared = require('./connect/shared');
6
-
7
- class WalletAuthenticator extends Authenticator {
8
- constructor(options = {}) {
9
- checkBlockletEnv();
10
-
11
- super({
12
- wallet: getWallet().toJSON(),
13
- ...getShared(options),
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;