@blocklet/sdk 1.16.20-beta-cf6dfce1 → 1.16.20-beta-148929e2

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.
@@ -3,8 +3,6 @@ import { AxiosResponse, Method } from 'axios';
3
3
  import { IncomingMessage } from 'http';
4
4
  import * as Util from './util';
5
5
  import type { Resource } from './util';
6
- declare const getChildWebEndpoint: (name: string) => string;
7
- declare const getParentWebEndpoint: () => string;
8
6
  declare const getComponentWebEndpoint: (keyword: string) => string;
9
7
  type CallComponentOptions<D = any, P = any> = {
10
8
  name?: string;
@@ -33,19 +31,20 @@ declare const getResources: ({ types, skipRunningCheck, }?: {
33
31
  types?: string[];
34
32
  skipRunningCheck?: boolean;
35
33
  }) => Resource[];
34
+ declare const waitForComponentRunning: (name: string, timeout?: number, interval?: number) => Promise<boolean>;
36
35
  export { call };
37
36
  export { getUrl };
38
37
  export { getComponentMountPoint };
39
38
  export { getComponentWebEndpoint };
39
+ export { waitForComponentRunning };
40
40
  export { getResourceExportDir };
41
41
  export { getResources };
42
- export { getChildWebEndpoint };
43
- export { getParentWebEndpoint };
44
42
  declare const _default: {
45
43
  call: CallComponent;
46
44
  getUrl: (...parts: string[]) => string;
47
45
  getComponentMountPoint: (keyword: string) => string;
48
46
  getComponentWebEndpoint: (keyword: string) => string;
47
+ waitForComponentRunning: (name: string, timeout?: number, interval?: number) => Promise<boolean>;
49
48
  getResourceExportDir: ({ projectId, releaseId }?: {
50
49
  projectId: string;
51
50
  releaseId?: string;
@@ -54,7 +53,5 @@ declare const _default: {
54
53
  types?: string[];
55
54
  skipRunningCheck?: boolean;
56
55
  }) => Util.Resource[];
57
- getChildWebEndpoint: (name: string) => string;
58
- getParentWebEndpoint: () => string;
59
56
  };
60
57
  export default _default;
@@ -26,12 +26,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getParentWebEndpoint = exports.getChildWebEndpoint = exports.getResources = exports.getResourceExportDir = exports.getComponentWebEndpoint = exports.getComponentMountPoint = exports.getUrl = exports.call = void 0;
29
+ exports.getResources = exports.getResourceExportDir = exports.waitForComponentRunning = exports.getComponentWebEndpoint = exports.getComponentMountPoint = exports.getUrl = exports.call = void 0;
30
30
  const path_1 = require("path");
31
- const util_1 = require("@blocklet/meta/lib/util");
32
31
  const axios_1 = __importDefault(require("axios"));
33
32
  const get_1 = __importDefault(require("lodash/get"));
34
33
  const url_join_1 = __importDefault(require("url-join"));
34
+ const wait_port_1 = __importDefault(require("wait-port"));
35
35
  const constant_1 = require("@blocklet/constant");
36
36
  const config_1 = require("../config");
37
37
  const verify_sign_1 = require("../util/verify-sign");
@@ -61,24 +61,6 @@ const doCall = async ({ url, headers = {}, ...options }) => {
61
61
  throw error;
62
62
  }
63
63
  };
64
- const parsePorts = () => JSON.parse(process.env.BLOCKLET_WEB_PORTS);
65
- const getWebEndpoint = (name) => {
66
- const ports = parsePorts();
67
- if (ports[name]) {
68
- return `http://127.0.0.1:${ports[name]}`;
69
- }
70
- return '';
71
- };
72
- const getChildWebEndpoint = (name) => {
73
- const fullName = `${process.env.BLOCKLET_REAL_NAME}/${name}`;
74
- return getWebEndpoint(fullName);
75
- };
76
- exports.getChildWebEndpoint = getChildWebEndpoint;
77
- const getParentWebEndpoint = () => {
78
- const parentName = (0, util_1.getParentComponentName)(process.env.BLOCKLET_REAL_NAME);
79
- return getWebEndpoint(parentName);
80
- };
81
- exports.getParentWebEndpoint = getParentWebEndpoint;
82
64
  const getComponent = (name) => {
83
65
  const item = config_1.components.find((x) => [x.title, x.name, x.did].includes(name));
84
66
  return item;
@@ -141,13 +123,28 @@ const getResources = ({ types, skipRunningCheck, } = {}) => {
141
123
  return Util.getResources({ components: config_1.components, types, skipRunningCheck });
142
124
  };
143
125
  exports.getResources = getResources;
126
+ const waitForComponentRunning = async (name, timeout = 30000, interval = 250) => {
127
+ const component = getComponent(name);
128
+ if (!component) {
129
+ throw new Error(`can not find component ${name}`);
130
+ }
131
+ const { port } = component;
132
+ if (!port) {
133
+ throw new Error(`can not find port for component ${name}`);
134
+ }
135
+ const result = await (0, wait_port_1.default)({ host: '127.0.0.1', port, timeout, interval });
136
+ if (result.open) {
137
+ return true;
138
+ }
139
+ throw new Error(`component ${name} is not running not unreachable`);
140
+ };
141
+ exports.waitForComponentRunning = waitForComponentRunning;
144
142
  exports.default = {
145
143
  call,
146
144
  getUrl,
147
145
  getComponentMountPoint,
148
146
  getComponentWebEndpoint,
147
+ waitForComponentRunning,
149
148
  getResourceExportDir,
150
149
  getResources,
151
- getChildWebEndpoint,
152
- getParentWebEndpoint, // deprecated
153
150
  };
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import EventEmitter from 'events';
3
- import { TNotificationInput, TSendOptions } from '../types/notification';
3
+ import { TNotification, TNotificationInput, TSendOptions } from '../types/notification';
4
4
  type $TSFixMe = any;
5
5
  /**
6
6
  *
@@ -12,6 +12,7 @@ type $TSFixMe = any;
12
12
  */
13
13
  declare const doSendToUser: (receiver: string | string[], notification: TNotificationInput, options?: TSendOptions) => Promise<any>;
14
14
  declare const doSendToRelay: (topic: string, event: string, data: any) => Promise<any>;
15
+ declare const doSendMail: (receiver: string | string[], notification: TNotification, options?: TSendOptions) => Promise<any>;
15
16
  /**
16
17
  *
17
18
  * @param {Notification} notification
@@ -31,11 +32,13 @@ export declare const _message: {
31
32
  off: any;
32
33
  };
33
34
  export { doSendToUser as sendToUser };
35
+ export { doSendMail as sendToMail };
34
36
  export { doSendToRelay as sendToRelay };
35
37
  export { broadcast };
36
38
  declare const _default: {
37
39
  sendToUser: (receiver: string | string[], notification: TNotificationInput, options?: TSendOptions) => Promise<any>;
38
40
  sendToRelay: (topic: string, event: string, data: any) => Promise<any>;
41
+ sendToMail: (receiver: string | string[], notification: TNotification, options?: TSendOptions) => Promise<any>;
39
42
  broadcast: (notification: TNotificationInput, options?: TSendOptions) => Promise<any>;
40
43
  on: (event: string, cb?: any) => EventEmitter;
41
44
  off: any;
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.broadcast = exports.sendToRelay = exports.sendToUser = exports._message = exports.off = exports.on = void 0;
29
+ exports.broadcast = exports.sendToRelay = exports.sendToMail = exports.sendToUser = exports._message = exports.off = exports.on = void 0;
30
30
  /* eslint-disable @typescript-eslint/naming-convention */
31
31
  const Jwt = __importStar(require("@arcblock/jwt"));
32
32
  const events_1 = __importDefault(require("events"));
@@ -56,7 +56,7 @@ const getSender = () => {
56
56
  // eslint-disable-next-line require-await
57
57
  const doSendToUser = async (receiver, notification, options) => {
58
58
  (0, check_blocklet_env_1.default)();
59
- return (0, send_notification_1.sendToUser)(receiver, notification, getSender(), process.env.ABT_NODE_SERVICE_PORT, options);
59
+ return (0, send_notification_1.sendToUser)(receiver, notification, getSender(), process.env.ABT_NODE_SERVICE_PORT, options, 'send-to-user');
60
60
  };
61
61
  exports.sendToUser = doSendToUser;
62
62
  // eslint-disable-next-line require-await
@@ -65,6 +65,12 @@ const doSendToRelay = async (topic, event, data) => {
65
65
  return (0, send_notification_1.sendToRelay)(topic, event, data, getSender(), process.env.ABT_NODE_SERVICE_PORT);
66
66
  };
67
67
  exports.sendToRelay = doSendToRelay;
68
+ // eslint-disable-next-line require-await
69
+ const doSendMail = async (receiver, notification, options) => {
70
+ (0, check_blocklet_env_1.default)();
71
+ return (0, send_notification_1.sendToUser)(receiver, notification, getSender(), process.env.ABT_NODE_SERVICE_PORT, options, 'send-to-mail');
72
+ };
73
+ exports.sendToMail = doSendMail;
68
74
  /**
69
75
  *
70
76
  * @param {Notification} notification
@@ -219,6 +225,7 @@ exports._message = {
219
225
  exports.default = {
220
226
  sendToUser: doSendToUser,
221
227
  sendToRelay: doSendToRelay,
228
+ sendToMail: doSendMail,
222
229
  broadcast,
223
230
  on: exports.on,
224
231
  off: exports.off,
@@ -111,4 +111,5 @@ export interface TSendOptions {
111
111
  */
112
112
  [x: string]: any;
113
113
  keepForOfflineUser?: boolean;
114
+ locale?: string;
114
115
  }
@@ -1,4 +1,4 @@
1
- import { TNotificationInput, TSendOptions } from '../types/notification';
1
+ import { TNotification, TNotificationInput, TSendOptions } from '../types/notification';
2
2
  export type TNotificationSender = {
3
3
  appDid: string;
4
4
  appSk: string;
@@ -14,12 +14,12 @@ export type TNotificationSender = {
14
14
  * @param {Object} options
15
15
  * @returns
16
16
  */
17
- declare const sendToUser: (receiver: string | string[], notification: TNotificationInput, { appDid, appSk }: TNotificationSender, port?: string, options?: {}) => Promise<any>;
17
+ declare const sendToUser: (receiver: string | string[], notification: TNotification | TNotificationInput, { appDid, appSk }: TNotificationSender, port?: string, options?: {}, pathname?: string) => Promise<any>;
18
18
  declare const sendToAppChannel: (channel: string, event: string, notification: TNotificationInput, { appDid, appSk }: TNotificationSender, port?: string, options?: TSendOptions) => Promise<any>;
19
19
  declare const sendToRelay: (topic: string, event: string, data: any, { appDid, appSk }: TNotificationSender, port?: string) => Promise<any>;
20
20
  export { sendToUser, sendToAppChannel, sendToRelay };
21
21
  declare const _default: {
22
- sendToUser: (receiver: string | string[], notification: TNotificationInput, { appDid, appSk }: TNotificationSender, port?: string, options?: {}) => Promise<any>;
22
+ sendToUser: (receiver: string | string[], notification: TNotification | TNotificationInput, { appDid, appSk }: TNotificationSender, port?: string, options?: {}, pathname?: string) => Promise<any>;
23
23
  sendToAppChannel: (channel: string, event: string, notification: TNotificationInput, { appDid, appSk }: TNotificationSender, port?: string, options?: TSendOptions) => Promise<any>;
24
24
  sendToRelay: (topic: string, event: string, data: any, { appDid, appSk }: TNotificationSender, port?: string) => Promise<any>;
25
25
  };
@@ -51,15 +51,20 @@ const getRequestHeaders = () => ({ 'User-Agent': `BlockletSDK/${VERSION}` });
51
51
  * @param {Object} options
52
52
  * @returns
53
53
  */
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']);
54
+ const sendToUser = async (receiver, notification, { appDid, appSk }, port = process.env.ABT_NODE_SERVICE_PORT, options = {}, pathname = 'send-to-user') => {
55
+ if (pathname === 'send-to-user') {
56
+ await (0, index_1.validateReceiver)(receiver);
57
+ }
58
+ if (pathname === 'send-to-mail') {
59
+ await (0, index_1.validateEmail)(receiver);
60
+ }
61
+ const opt = (0, pick_1.default)(options, ['keepForOfflineUser', 'locale']);
57
62
  await (0, index_1.validateOption)(opt);
58
63
  if (SERVER_MODE !== NODE_MODES.DEBUG) {
59
64
  await (0, index_1.validateNotification)(notification);
60
65
  }
61
66
  try {
62
- const { data: res } = await axios.post(`http://127.0.0.1:${port}${constants_1.SERVICE_PREFIX}/api/send-to-user`, {
67
+ const { data: res } = await axios.post(`http://127.0.0.1:${port}${constants_1.SERVICE_PREFIX}/api/${pathname}`, {
63
68
  apiVersion: VERSION,
64
69
  data: {
65
70
  sender: { appDid, token: JWT.sign(appDid, appSk) },
@@ -1,12 +1,14 @@
1
- import { validateNotification, validateReceiver, validateOption, validateChannelEvent } from './notification';
1
+ import { validateNotification, validateReceiver, validateOption, validateChannelEvent, validateEmail } from './notification';
2
2
  export { validateNotification };
3
3
  export { validateReceiver };
4
4
  export { validateOption };
5
5
  export { validateChannelEvent };
6
+ export { validateEmail };
6
7
  declare const _default: {
7
8
  validateNotification: any;
8
9
  validateReceiver: any;
9
10
  validateOption: any;
10
11
  validateChannelEvent: any;
12
+ validateEmail: any;
11
13
  };
12
14
  export default _default;
@@ -1,14 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateChannelEvent = exports.validateOption = exports.validateReceiver = exports.validateNotification = void 0;
3
+ exports.validateEmail = exports.validateChannelEvent = exports.validateOption = exports.validateReceiver = exports.validateNotification = void 0;
4
4
  const notification_1 = require("./notification");
5
5
  Object.defineProperty(exports, "validateNotification", { enumerable: true, get: function () { return notification_1.validateNotification; } });
6
6
  Object.defineProperty(exports, "validateReceiver", { enumerable: true, get: function () { return notification_1.validateReceiver; } });
7
7
  Object.defineProperty(exports, "validateOption", { enumerable: true, get: function () { return notification_1.validateOption; } });
8
8
  Object.defineProperty(exports, "validateChannelEvent", { enumerable: true, get: function () { return notification_1.validateChannelEvent; } });
9
+ Object.defineProperty(exports, "validateEmail", { enumerable: true, get: function () { return notification_1.validateEmail; } });
9
10
  exports.default = {
10
11
  validateNotification: notification_1.validateNotification,
11
12
  validateReceiver: notification_1.validateReceiver,
12
13
  validateOption: notification_1.validateOption,
13
14
  validateChannelEvent: notification_1.validateChannelEvent,
15
+ validateEmail: notification_1.validateEmail,
14
16
  };
@@ -28,6 +28,7 @@ export declare const validateNotification: any;
28
28
  export declare const validateMessage: any;
29
29
  export declare const validateChannelEvent: any;
30
30
  export declare const validateOption: any;
31
+ export declare const validateEmail: any;
31
32
  export { tokenSchema };
32
33
  export { actionSchema };
33
34
  export { assetSchema };
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
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.dappSchema = exports.imageSchema = exports.linkSchema = exports.textSchema = exports.transactionSchema = exports.vcSchema = exports.assetSchema = exports.actionSchema = exports.tokenSchema = exports.validateOption = exports.validateChannelEvent = exports.validateMessage = exports.validateNotification = exports.validateReceiver = void 0;
6
+ exports.feedTypeSchema = exports.connectTypeSchema = exports.notificationTypeSchema = exports.inputNotificationSchema = exports.NOTIFICATION_TYPES = exports.channelEventSchema = exports.optionSchema = exports.messageSchema = exports.notificationSchema = exports.attachmentSchema = exports.dappSchema = exports.imageSchema = exports.linkSchema = exports.textSchema = exports.transactionSchema = exports.vcSchema = exports.assetSchema = exports.actionSchema = exports.tokenSchema = exports.validateEmail = exports.validateOption = exports.validateChannelEvent = exports.validateMessage = exports.validateNotification = exports.validateReceiver = void 0;
7
7
  const joi_1 = __importDefault(require("joi"));
8
8
  const extension_1 = require("@blocklet/meta/lib/extension");
9
9
  const Joi = joi_1.default.extend(extension_1.didExtension);
@@ -203,17 +203,20 @@ exports.inputNotificationSchema = inputNotificationSchema;
203
203
  const inputReceiverSchema = Joi.array().items(receiverSchema).single().required().meta({ className: 'TReceiverInput' });
204
204
  const optionSchema = Joi.object({
205
205
  keepForOfflineUser: Joi.boolean(),
206
+ locale: Joi.string(),
206
207
  })
207
208
  .unknown()
208
209
  .meta({ className: 'TSendOptions', unknownType: 'any' });
209
210
  exports.optionSchema = optionSchema;
210
211
  const channelEventSchema = Joi.string().required().meta({ className: 'TChannelEvent' });
211
212
  exports.channelEventSchema = channelEventSchema;
213
+ const schemaEmail = Joi.string().email().required();
212
214
  exports.validateReceiver = inputReceiverSchema.validateAsync.bind(inputReceiverSchema);
213
215
  exports.validateNotification = inputNotificationSchema.validateAsync.bind(inputNotificationSchema);
214
216
  exports.validateMessage = messageSchema.validateAsync.bind(messageSchema);
215
217
  exports.validateChannelEvent = channelEventSchema.validateAsync.bind(channelEventSchema);
216
218
  exports.validateOption = optionSchema.validateAsync.bind(optionSchema);
219
+ exports.validateEmail = schemaEmail.validateAsync.bind(schemaEmail);
217
220
  exports.default = {
218
221
  validateReceiver: exports.validateReceiver,
219
222
  validateNotification: exports.validateNotification,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.20-beta-cf6dfce1",
6
+ "version": "1.16.20-beta-148929e2",
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",
@@ -26,15 +26,15 @@
26
26
  "author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
27
27
  "license": "Apache-2.0",
28
28
  "dependencies": {
29
- "@abtnode/client": "1.16.20-beta-cf6dfce1",
30
- "@abtnode/constant": "1.16.20-beta-cf6dfce1",
29
+ "@abtnode/client": "1.16.20-beta-148929e2",
30
+ "@abtnode/constant": "1.16.20-beta-148929e2",
31
31
  "@arcblock/did": "1.18.103",
32
32
  "@arcblock/did-auth": "1.18.103",
33
33
  "@arcblock/jwt": "1.18.103",
34
34
  "@arcblock/ws": "1.18.103",
35
- "@blocklet/constant": "1.16.20-beta-cf6dfce1",
36
- "@blocklet/env": "1.16.20-beta-cf6dfce1",
37
- "@blocklet/meta": "1.16.20-beta-cf6dfce1",
35
+ "@blocklet/constant": "1.16.20-beta-148929e2",
36
+ "@blocklet/env": "1.16.20-beta-148929e2",
37
+ "@blocklet/meta": "1.16.20-beta-148929e2",
38
38
  "@did-connect/authenticator": "^2.2.1",
39
39
  "@did-connect/handler": "^2.2.1",
40
40
  "@nedb/core": "^2.1.5",
@@ -50,7 +50,8 @@
50
50
  "semver": "^7.3.8",
51
51
  "sitemap": "^7.1.1",
52
52
  "ufo": "^1.1.1",
53
- "url-join": "^4.0.1"
53
+ "url-join": "^4.0.1",
54
+ "wait-port": "^1.1.0"
54
55
  },
55
56
  "resolutions": {
56
57
  "@nedb/core": "^2.1.2"
@@ -74,5 +75,5 @@
74
75
  "ts-node": "^10.9.1",
75
76
  "typescript": "^5.0.4"
76
77
  },
77
- "gitHead": "bc2f0c9c5a39b124c7a7b64ec907527b3e8ccdf1"
78
+ "gitHead": "99e23380f73b63a8e63ce1fe8f75908194df5d80"
78
79
  }