@blocklet/sdk 1.16.15-beta-d8e7b6c0 → 1.16.15-beta-9318a201

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.
@@ -19,13 +19,16 @@ type CallComponent = {
19
19
  };
20
20
  declare const call: CallComponent;
21
21
  declare const getComponentMountPoint: (keyword: string) => string;
22
+ declare const getUrl: (...parts: string[]) => string;
22
23
  export { call };
24
+ export { getUrl };
23
25
  export { getComponentMountPoint };
24
26
  export { getComponentWebEndpoint };
25
27
  export { getChildWebEndpoint };
26
28
  export { getParentWebEndpoint };
27
29
  declare const _default: {
28
30
  call: CallComponent;
31
+ getUrl: (...parts: string[]) => string;
29
32
  getComponentMountPoint: (keyword: string) => string;
30
33
  getComponentWebEndpoint: (keyword: string) => string;
31
34
  getChildWebEndpoint: (name: string) => string;
@@ -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.getParentWebEndpoint = exports.getChildWebEndpoint = exports.getComponentWebEndpoint = exports.getComponentMountPoint = exports.call = void 0;
6
+ exports.getParentWebEndpoint = exports.getChildWebEndpoint = exports.getComponentWebEndpoint = exports.getComponentMountPoint = exports.getUrl = exports.call = void 0;
7
7
  const util_1 = require("@blocklet/meta/lib/util");
8
8
  const axios_1 = __importDefault(require("axios"));
9
9
  const get_1 = __importDefault(require("lodash/get"));
@@ -93,8 +93,15 @@ const getComponentMountPoint = (keyword) => {
93
93
  return item ? item.mountPoint : '';
94
94
  };
95
95
  exports.getComponentMountPoint = getComponentMountPoint;
96
+ const getUrl = (...parts) => {
97
+ const { BLOCKLET_COMPONENT_DID, BLOCKLET_APP_URL } = process.env;
98
+ const mountPoint = getComponentMountPoint(BLOCKLET_COMPONENT_DID);
99
+ return (0, url_join_1.default)(BLOCKLET_APP_URL, mountPoint === '/' ? '' : mountPoint, ...parts);
100
+ };
101
+ exports.getUrl = getUrl;
96
102
  exports.default = {
97
103
  call,
104
+ getUrl,
98
105
  getComponentMountPoint,
99
106
  getComponentWebEndpoint,
100
107
  getChildWebEndpoint,
package/lib/config.d.ts CHANGED
@@ -1,7 +1,15 @@
1
1
  /// <reference types="node" />
2
2
  import EventEmitter from 'events';
3
- import { TComponentInternalInfo } from '@blocklet/meta/lib/util';
3
+ import { TComponentInternalInfo } from '@blocklet/meta/lib/blocklet';
4
4
  declare const events: EventEmitter;
5
+ declare const Events: {
6
+ componentAdded: string;
7
+ componentUpdated: string;
8
+ componentStarted: string;
9
+ componentStopped: string;
10
+ componentRemoved: string;
11
+ envUpdate: string;
12
+ };
5
13
  declare const logger: {
6
14
  info: {
7
15
  (...data: any[]): void;
@@ -35,18 +43,36 @@ declare const env: Readonly<{
35
43
  name: string;
36
44
  }[];
37
45
  preferences: Record<string, any>;
46
+ componentDid: string;
38
47
  }>;
39
48
  type MountPoint = TComponentInternalInfo & {
40
- webEndpoint: string;
49
+ webEndpoint?: string;
41
50
  };
42
- type TComponents = Array<MountPoint>;
43
- declare const components: TComponents;
44
- declare const handleComponentUpdate: (data: {
51
+ type TComponent = MountPoint;
52
+ type TComponents = Array<TComponent>;
53
+ declare const componentStore: TComponents;
54
+ declare const _handleComponentUpdateOld: (data: {
45
55
  components: TComponents;
46
56
  }) => void;
47
- declare const handleConfigUpdate: (data: any) => void;
57
+ declare const _handleComponentStarted: (data: {
58
+ components: Partial<TComponent>[];
59
+ }) => void;
60
+ declare const _handleComponentStopped: (data: {
61
+ components: Partial<TComponent>[];
62
+ }) => void;
63
+ declare const _handleComponentRemoved: (data: {
64
+ components: Partial<TComponent>[];
65
+ }) => void;
66
+ declare const _handleComponentUpdated: (data: {
67
+ components: TComponents;
68
+ }) => void;
69
+ declare const _handleComponentInstalled: (data: {
70
+ components: TComponents;
71
+ }) => void;
72
+ declare const _handleConfigUpdate: (data: any) => void;
48
73
  declare const getBlockletJs: (pageGroup?: string, pathPrefix?: string, source?: string) => string;
49
- export { logger, env, components, MountPoint, events, getBlockletJs, handleComponentUpdate, handleConfigUpdate };
74
+ export { logger, env, componentStore as components, MountPoint, // @deprecated, for backward compatibility
75
+ TComponent, events, Events, getBlockletJs, _handleComponentUpdateOld, _handleConfigUpdate, _handleComponentInstalled, _handleComponentUpdated, _handleComponentStarted, _handleComponentStopped, _handleComponentRemoved, };
50
76
  declare const _default: {
51
77
  logger: {
52
78
  info: {
@@ -81,13 +107,18 @@ declare const _default: {
81
107
  name: string;
82
108
  }[];
83
109
  preferences: Record<string, any>;
110
+ componentDid: string;
84
111
  }>;
85
112
  components: TComponents;
86
113
  events: EventEmitter;
87
- handleComponentUpdate: (data: {
88
- components: TComponents;
89
- }) => void;
90
- handleConfigUpdate: (data: any) => void;
114
+ Events: {
115
+ componentAdded: string;
116
+ componentUpdated: string;
117
+ componentStarted: string;
118
+ componentStopped: string;
119
+ componentRemoved: string;
120
+ envUpdate: string;
121
+ };
91
122
  fetchBlockletJs: () => Promise<any>;
92
123
  getBlockletJs: (pageGroup?: string, pathPrefix?: string, source?: string) => string;
93
124
  };
package/lib/config.js CHANGED
@@ -3,7 +3,8 @@ 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.handleConfigUpdate = exports.handleComponentUpdate = exports.getBlockletJs = exports.events = exports.components = exports.env = exports.logger = void 0;
6
+ exports._handleComponentRemoved = exports._handleComponentStopped = exports._handleComponentStarted = exports._handleComponentUpdated = exports._handleComponentInstalled = exports._handleConfigUpdate = exports._handleComponentUpdateOld = exports.getBlockletJs = exports.Events = exports.events = exports.components = exports.env = exports.logger = void 0;
7
+ /* eslint-disable prettier/prettier */
7
8
  const url_join_1 = __importDefault(require("url-join"));
8
9
  const events_1 = __importDefault(require("events"));
9
10
  const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
@@ -15,12 +16,18 @@ const util_2 = require("@blocklet/meta/lib/util");
15
16
  const axios_1 = __importDefault(require("axios"));
16
17
  const version_1 = require("./version");
17
18
  const notification_1 = __importDefault(require("./service/notification"));
19
+ const server_version_1 = __importDefault(require("./util/server-version"));
18
20
  const events = new events_1.default();
19
21
  exports.events = events;
20
22
  const Events = {
21
- componentsUpdate: 'componentsUpdate',
23
+ componentAdded: 'componentAdded',
24
+ componentUpdated: 'componentUpdated',
25
+ componentStarted: 'componentStarted',
26
+ componentStopped: 'componentStopped',
27
+ componentRemoved: 'componentRemoved',
22
28
  envUpdate: 'envUpdate',
23
29
  };
30
+ exports.Events = Events;
24
31
  const AppConfigKeyMap = {
25
32
  BLOCKLET_APP_NAME: 'appName',
26
33
  BLOCKLET_APP_DESCRIPTION: 'appDescription',
@@ -45,29 +52,85 @@ const logger = {
45
52
  exports.logger = logger;
46
53
  const env = (0, cloneDeep_1.default)(env_1.default);
47
54
  exports.env = env;
48
- const parseComponents = () => {
49
- const mountPoints = JSON.parse(process.env.BLOCKLET_MOUNT_POINTS || '[]') || [];
50
- mountPoints.forEach((x) => {
55
+ const _fillWebEndpoint = (components) => {
56
+ components.forEach((x) => {
51
57
  if (x.port) {
52
58
  x.webEndpoint = `http://127.0.0.1:${x.port}`;
53
59
  }
54
60
  });
55
- return mountPoints;
56
61
  };
57
- const components = parseComponents();
58
- exports.components = components;
59
- const handleComponentUpdate = (data) => {
60
- components.splice(0, components.length);
61
- components.push(...data.components.map((x) => {
62
+ const initComponentStore = () => {
63
+ const components = JSON.parse(process.env.BLOCKLET_MOUNT_POINTS || '[]') || [];
64
+ _fillWebEndpoint(components);
65
+ return components;
66
+ };
67
+ const componentStore = initComponentStore();
68
+ exports.components = componentStore;
69
+ const _handleComponentUpdateOld = (data) => {
70
+ componentStore.splice(0, componentStore.length);
71
+ componentStore.push(...data.components.map((x) => {
62
72
  if (x.port) {
63
73
  x.webEndpoint = `http://127.0.0.1:${x.port}`;
64
74
  }
65
75
  return x;
66
76
  }));
67
- events.emit(Events.componentsUpdate, components);
68
77
  };
69
- exports.handleComponentUpdate = handleComponentUpdate;
70
- const handleConfigUpdate = (data) => {
78
+ exports._handleComponentUpdateOld = _handleComponentUpdateOld;
79
+ const _setComponentStatus = (components, status) => {
80
+ const list = componentStore.filter((x) => components.find((y) => y.did === x.did));
81
+ list.forEach((x) => {
82
+ x.status = status;
83
+ });
84
+ return (0, cloneDeep_1.default)(list);
85
+ };
86
+ const _setUpdatedComponents = (components) => {
87
+ const list = (0, cloneDeep_1.default)(components || []);
88
+ _fillWebEndpoint(list);
89
+ list.forEach((newItem) => {
90
+ const exist = componentStore.find((x) => x.did === newItem.did);
91
+ newItem.status = exist ? exist.status : constant_1.BlockletStatus.stopped;
92
+ if (exist) {
93
+ Object.assign(exist, newItem);
94
+ }
95
+ else {
96
+ componentStore.push({ ...newItem, status: constant_1.BlockletStatus.stopped });
97
+ }
98
+ });
99
+ return list;
100
+ };
101
+ const _handleComponentStarted = (data) => {
102
+ const list = _setComponentStatus(data.components, constant_1.BlockletStatus.running);
103
+ events.emit(Events.componentStarted, list);
104
+ };
105
+ exports._handleComponentStarted = _handleComponentStarted;
106
+ const _handleComponentStopped = (data) => {
107
+ const list = _setComponentStatus(data.components, constant_1.BlockletStatus.stopped);
108
+ events.emit(Events.componentStopped, list);
109
+ };
110
+ exports._handleComponentStopped = _handleComponentStopped;
111
+ const _handleComponentRemoved = (data) => {
112
+ const list = componentStore.filter((x) => data.components.find((y) => y.did !== x.did));
113
+ componentStore.splice(0, componentStore.length);
114
+ componentStore.push(...list);
115
+ events.emit(Events.componentRemoved, data.components);
116
+ };
117
+ exports._handleComponentRemoved = _handleComponentRemoved;
118
+ const _handleComponentUpdated = (data) => {
119
+ const list = _setUpdatedComponents(data.components);
120
+ events.emit(Events.componentUpdated, list);
121
+ };
122
+ exports._handleComponentUpdated = _handleComponentUpdated;
123
+ const _handleComponentInstalled = (data) => {
124
+ const list = _setUpdatedComponents(data.components);
125
+ events.emit(Events.componentAdded, list);
126
+ };
127
+ exports._handleComponentInstalled = _handleComponentInstalled;
128
+ const _handleConfigUpdate = (data) => {
129
+ // ensure version in ServerVersion
130
+ const serverVersion = data.configs.find((x) => x.key === 'ABT_NODE_VERSION')?.value;
131
+ if (serverVersion) {
132
+ server_version_1.default.version = serverVersion;
133
+ }
71
134
  const configs = data.configs || [];
72
135
  const updates = configs
73
136
  .filter((x) => !(0, util_2.isPreferenceKey)(x))
@@ -86,12 +149,12 @@ const handleConfigUpdate = (data) => {
86
149
  Object.assign(env, updates);
87
150
  events.emit(Events.envUpdate, updates);
88
151
  };
89
- exports.handleConfigUpdate = handleConfigUpdate;
152
+ exports._handleConfigUpdate = _handleConfigUpdate;
90
153
  let blockletJs = '';
91
154
  const fetchBlockletJs = async () => {
92
155
  try {
93
156
  const componentDid = process.env.BLOCKLET_COMPONENT_DID;
94
- const { mountPoint } = components.find((x) => x.did === componentDid);
157
+ const { mountPoint } = componentStore.find((x) => x.did === componentDid);
95
158
  const res = await axios_1.default.get((0, url_join_1.default)(env.appUrl, mountPoint === '/' ? '' : mountPoint, `__blocklet__.js?t=${Date.now()}`), {
96
159
  timeout: 8000,
97
160
  headers: {
@@ -117,31 +180,55 @@ const getBlockletJs = (pageGroup = '', pathPrefix = '', source = blockletJs) =>
117
180
  }
118
181
  if (pathPrefix) {
119
182
  const componentDid = process.env.BLOCKLET_COMPONENT_DID;
120
- const { mountPoint } = components.find((x) => x.did === componentDid);
183
+ const { mountPoint } = componentStore.find((x) => x.did === componentDid);
121
184
  copy = copy.replace(`prefix: "${normalize(mountPoint)}",`, `prefix: "${normalize(pathPrefix)}",`);
122
185
  }
123
186
  return copy;
124
187
  };
125
188
  exports.getBlockletJs = getBlockletJs;
126
189
  const refreshBlockletJs = (0, throttle_1.default)(fetchBlockletJs, 8000);
190
+ const runInServer = (fn, type) =>
191
+ // eslint-disable-next-line consistent-return
192
+ (...args) => {
193
+ if (server_version_1.default.gt('1.16.14')) {
194
+ if (type === 'new') {
195
+ return fn(...args);
196
+ }
197
+ }
198
+ else if (type === 'old') {
199
+ return fn(...args);
200
+ }
201
+ };
127
202
  const inRuntimeEnv = !!process.env.BLOCKLET_APP_SK;
128
203
  if (inRuntimeEnv && !process.env.BLOCKLET_HOOK_NAME) {
129
- notification_1.default.on(constant_1.BlockletInternalEvents.componentsUpdated, handleComponentUpdate);
130
- notification_1.default.on(constant_1.BlockletInternalEvents.appConfigChanged, handleConfigUpdate);
204
+ notification_1.default.on(constant_1.BlockletInternalEvents.appConfigChanged, _handleConfigUpdate);
131
205
  // Reactive fetch
132
- notification_1.default.on(constant_1.BlockletInternalEvents.componentsUpdated, refreshBlockletJs);
133
206
  notification_1.default.on(constant_1.BlockletInternalEvents.appConfigChanged, refreshBlockletJs);
134
207
  notification_1.default.on(constant_1.BlockletInternalEvents.appSettingChanged, refreshBlockletJs);
208
+ notification_1.default.on(constant_1.BlockletInternalEvents.componentInstalled, runInServer(_handleComponentInstalled, 'new'));
209
+ notification_1.default.on(constant_1.BlockletInternalEvents.componentUpgraded, runInServer(_handleComponentUpdated, 'new'));
210
+ notification_1.default.on(constant_1.BlockletInternalEvents.componentUpdated, runInServer(_handleComponentUpdated, 'new'));
211
+ notification_1.default.on(constant_1.BlockletInternalEvents.componentStarted, runInServer(_handleComponentStarted, 'new'));
212
+ notification_1.default.on(constant_1.BlockletInternalEvents.componentStopped, runInServer(_handleComponentStopped, 'new'));
213
+ notification_1.default.on(constant_1.BlockletInternalEvents.componentRemoved, runInServer(_handleComponentRemoved, 'new'));
214
+ notification_1.default.on(constant_1.BlockletInternalEvents.componentInstalled, runInServer(refreshBlockletJs, 'new'));
215
+ notification_1.default.on(constant_1.BlockletInternalEvents.componentUpgraded, runInServer(refreshBlockletJs, 'new'));
216
+ notification_1.default.on(constant_1.BlockletInternalEvents.componentUpdated, runInServer(refreshBlockletJs, 'new'));
217
+ notification_1.default.on(constant_1.BlockletInternalEvents.componentStarted, runInServer(refreshBlockletJs, 'new'));
218
+ notification_1.default.on(constant_1.BlockletInternalEvents.componentStopped, runInServer(refreshBlockletJs, 'new'));
219
+ notification_1.default.on(constant_1.BlockletInternalEvents.componentRemoved, runInServer(refreshBlockletJs, 'new'));
220
+ // for backward compatibility
221
+ notification_1.default.on(constant_1.BlockletInternalEvents.componentsUpdated, runInServer(_handleComponentUpdateOld, 'old'));
222
+ notification_1.default.on(constant_1.BlockletInternalEvents.componentsUpdated, runInServer(refreshBlockletJs, 'old'));
135
223
  // Do an initial fetch
136
224
  fetchBlockletJs();
137
225
  }
138
226
  exports.default = {
139
227
  logger,
140
228
  env,
141
- components,
229
+ components: componentStore,
142
230
  events,
143
- handleComponentUpdate,
144
- handleConfigUpdate,
231
+ Events,
145
232
  fetchBlockletJs,
146
233
  getBlockletJs,
147
234
  };
package/lib/index.d.ts CHANGED
@@ -11,7 +11,7 @@ import middlewares from './middlewares/index';
11
11
  import getWallet from './wallet';
12
12
  import Component from './component/index';
13
13
  import Security from './security/index';
14
- import config, { MountPoint } from './config';
14
+ import config, { TComponent } from './config';
15
15
  export { Auth as AuthService };
16
16
  export { Auth };
17
17
  export { Notification as NotificationService };
@@ -52,7 +52,7 @@ declare global {
52
52
  code: string;
53
53
  name: string;
54
54
  }[];
55
- componentMountPoints: MountPoint[];
55
+ componentMountPoints: TComponent[];
56
56
  alsoKnownAs: string[];
57
57
  trustedFactories: string[];
58
58
  };
@@ -33,6 +33,7 @@ const events_1 = __importDefault(require("events"));
33
33
  const ws_1 = require("@arcblock/ws");
34
34
  const channel_1 = require("@blocklet/meta/lib/channel");
35
35
  const constant_1 = require("@blocklet/constant");
36
+ const server_version_1 = __importDefault(require("../util/server-version"));
36
37
  const check_blocklet_env_1 = __importDefault(require("../util/check-blocklet-env"));
37
38
  const send_notification_1 = require("../util/send-notification");
38
39
  const constants_1 = require("../util/constants");
@@ -96,11 +97,17 @@ const ensureErrorListener = () => {
96
97
  emitter.on('error', noop);
97
98
  messageEmitter.on('error', noop);
98
99
  };
100
+ const joinChannelErrorHandler = (name, type, emitters) => (err) => {
101
+ const msg = `join ${name || 'channel'} ${type || 'error'}${err?.message ? ': ' : ''}${err?.message || ''}`;
102
+ console.error(msg);
103
+ (emitters || [emitter]).forEach((_emitter) => _emitter.emit('error', { message: msg }));
104
+ };
99
105
  let client = null;
100
106
  const initClient = () => {
101
107
  if (!client) {
102
108
  ensureErrorListener();
103
109
  const wallet = (0, wallet_1.getPermanentWallet)();
110
+ const componentDid = process.env.BLOCKLET_COMPONENT_DID;
104
111
  const { address: did, publicKey: pk, secretKey: sk } = wallet;
105
112
  const url = `ws://127.0.0.1:${process.env.ABT_NODE_SERVICE_PORT}${constants_1.SERVICE_PREFIX}`;
106
113
  const token = () => Jwt.sign(did, sk, {});
@@ -114,30 +121,23 @@ const initClient = () => {
114
121
  client.connect();
115
122
  const messageChannel = client.channel(did, () => ({ token: token(), pk }));
116
123
  const appPublicChannel = client.channel((0, channel_1.getAppPublicChannel)(did), () => ({ token: token(), pk }));
124
+ const componentChannel = client.channel((0, channel_1.getComponentChannel)(did, componentDid), () => ({
125
+ token: token(),
126
+ pk,
127
+ apiKey: process.env.BLOCKLET_COMPONENT_API_KEY,
128
+ }));
117
129
  messageChannel
118
130
  .join()
119
- .receive('error', (err) => {
120
- const msg = `join channel error: ${err.message}`;
121
- console.error(msg);
122
- emitError({ message: msg });
123
- })
124
- .receive('timeout', () => {
125
- const msg = 'join channel timeout';
126
- console.error(msg);
127
- emitError({ message: msg });
128
- });
131
+ .receive('error', joinChannelErrorHandler('message channel', 'error', [messageEmitter, emitter]))
132
+ .receive('timeout', joinChannelErrorHandler('message channel', 'timeout', [messageEmitter, emitter]));
129
133
  appPublicChannel
130
134
  .join()
131
- .receive('error', (err) => {
132
- const msg = `join channel error: ${err.message}`;
133
- console.error(msg);
134
- emitter.emit('error', { message: msg });
135
- })
136
- .receive('timeout', () => {
137
- const msg = 'join channel timeout';
138
- console.error(msg);
139
- emitter.emit('error', { message: msg });
140
- });
135
+ .receive('error', joinChannelErrorHandler('app publish channel', 'error'))
136
+ .receive('timeout', joinChannelErrorHandler('app publish channel', 'timeout'));
137
+ componentChannel
138
+ .join()
139
+ .receive('error', joinChannelErrorHandler('app component channel', 'error'))
140
+ .receive('timeout', joinChannelErrorHandler('app component channel', 'timeout'));
141
141
  messageChannel.on('message', ({ status, response } = {}) => {
142
142
  if (status === 'ok') {
143
143
  messageEmitter.emit(response.type, response);
@@ -155,7 +155,37 @@ const initClient = () => {
155
155
  });
156
156
  Object.keys(constant_1.BlockletInternalEvents).forEach((key) => {
157
157
  const event = constant_1.BlockletInternalEvents[key];
158
+ componentChannel.on(event, ({ status, response } = {}) => {
159
+ if (status === 'ok') {
160
+ const { data, sender, time } = response;
161
+ if (event === constant_1.BlockletInternalEvents.componentsUpdated) {
162
+ return;
163
+ }
164
+ if (!time || new Date(time).getMilliseconds() < new Date(process.env.BLOCKLET_START_AT).getMilliseconds()) {
165
+ return;
166
+ }
167
+ // verify sender is server
168
+ if (!Jwt.verify(sender.token, process.env.ABT_NODE_PK)) {
169
+ const message = `verify sender failed in internal events. event: ${event}, sender: ${JSON.stringify(sender)}`;
170
+ emitError({ message });
171
+ console.error(message);
172
+ return;
173
+ }
174
+ emitter.emit(event, data);
175
+ }
176
+ else {
177
+ emitError(response);
178
+ console.error({
179
+ status,
180
+ response,
181
+ });
182
+ }
183
+ });
184
+ // for backward compatibility, should be removed if Server@1.6.14 is not supported anymore
158
185
  messageChannel.on(event, ({ status, response } = {}) => {
186
+ if (server_version_1.default.gt('1.16.14')) {
187
+ return;
188
+ }
159
189
  if (status === 'ok') {
160
190
  const { data, sender } = response;
161
191
  // verify sender is server
@@ -6,7 +6,6 @@ const checkBlockletEnvironment = () => {
6
6
  'BLOCKLET_APP_DESCRIPTION',
7
7
  'BLOCKLET_APP_SK',
8
8
  'BLOCKLET_DID',
9
- 'ABT_NODE',
10
9
  'ABT_NODE_DID',
11
10
  'ABT_NODE_PK',
12
11
  'ABT_NODE_PORT',
@@ -0,0 +1,10 @@
1
+ declare class ServerVersion {
2
+ version: string;
3
+ constructor();
4
+ gte(version: any): boolean;
5
+ gt(version: any): boolean;
6
+ lte(version: any): boolean;
7
+ lt(version: any): boolean;
8
+ }
9
+ declare const serverVersion: ServerVersion;
10
+ export default serverVersion;
@@ -0,0 +1,26 @@
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
+ const env_1 = require("@blocklet/env");
7
+ const semver_1 = __importDefault(require("semver"));
8
+ class ServerVersion {
9
+ constructor() {
10
+ this.version = env_1.serverVersion || process.env.ABT_NODE_VERSION || process.env.ABT_NODE || '0.0.0';
11
+ }
12
+ gte(version) {
13
+ return semver_1.default.gte(this.version, version);
14
+ }
15
+ gt(version) {
16
+ return semver_1.default.gt(this.version, version);
17
+ }
18
+ lte(version) {
19
+ return semver_1.default.lte(this.version, version);
20
+ }
21
+ lt(version) {
22
+ return semver_1.default.lt(this.version, version);
23
+ }
24
+ }
25
+ const serverVersion = new ServerVersion();
26
+ exports.default = serverVersion;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.15-beta-d8e7b6c0",
6
+ "version": "1.16.15-beta-9318a201",
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.15-beta-d8e7b6c0",
30
- "@abtnode/constant": "1.16.15-beta-d8e7b6c0",
29
+ "@abtnode/client": "1.16.15-beta-9318a201",
30
+ "@abtnode/constant": "1.16.15-beta-9318a201",
31
31
  "@arcblock/did": "1.18.89",
32
32
  "@arcblock/did-auth": "1.18.89",
33
33
  "@arcblock/jwt": "1.18.89",
34
34
  "@arcblock/ws": "1.18.89",
35
- "@blocklet/constant": "1.16.15-beta-d8e7b6c0",
36
- "@blocklet/env": "1.16.15-beta-d8e7b6c0",
37
- "@blocklet/meta": "1.16.15-beta-d8e7b6c0",
35
+ "@blocklet/constant": "1.16.15-beta-9318a201",
36
+ "@blocklet/env": "1.16.15-beta-9318a201",
37
+ "@blocklet/meta": "1.16.15-beta-9318a201",
38
38
  "@did-connect/authenticator": "^2.2.0",
39
39
  "@did-connect/handler": "^2.2.0",
40
40
  "@nedb/core": "^2.1.5",
@@ -74,5 +74,5 @@
74
74
  "ts-node": "^10.9.1",
75
75
  "typescript": "^5.0.4"
76
76
  },
77
- "gitHead": "87ebe2e8267e634e2217d7ca28231d0b01636ae6"
77
+ "gitHead": "f3722cbd4fe10c5fa083cad7e859ecff6095060d"
78
78
  }