@blocklet/sdk 1.16.11-next-470e8c41 → 1.16.11

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/config.d.ts CHANGED
@@ -1,4 +1,7 @@
1
+ /// <reference types="node" />
2
+ import EventEmitter from 'events';
1
3
  import { TComponentInternalInfo } from '@blocklet/meta/lib/util';
4
+ declare const events: EventEmitter;
2
5
  declare const logger: {
3
6
  info: {
4
7
  (...data: any[]): void;
@@ -27,16 +30,22 @@ declare const env: Readonly<{
27
30
  mode: string;
28
31
  appStorageEndpoint: string;
29
32
  serverVersion: string;
30
- preferences: {
31
- [key: string]: any;
32
- };
33
+ languages: {
34
+ code: string;
35
+ name: string;
36
+ }[];
37
+ preferences: Record<string, any>;
33
38
  }>;
34
39
  type MountPoint = TComponentInternalInfo & {
35
40
  webEndpoint: string;
36
41
  };
37
42
  type TComponents = Array<MountPoint>;
38
43
  declare const components: TComponents;
39
- export { logger, env, components, MountPoint };
44
+ declare const handleComponentUpdate: (data: {
45
+ components: TComponents;
46
+ }) => void;
47
+ declare const handleConfigUpdate: (data: any) => void;
48
+ export { logger, env, components, MountPoint, events, handleComponentUpdate, handleConfigUpdate };
40
49
  declare const _default: {
41
50
  logger: {
42
51
  info: {
@@ -66,10 +75,17 @@ declare const _default: {
66
75
  mode: string;
67
76
  appStorageEndpoint: string;
68
77
  serverVersion: string;
69
- preferences: {
70
- [key: string]: any;
71
- };
78
+ languages: {
79
+ code: string;
80
+ name: string;
81
+ }[];
82
+ preferences: Record<string, any>;
72
83
  }>;
73
84
  components: TComponents;
85
+ events: EventEmitter;
86
+ handleComponentUpdate: (data: {
87
+ components: TComponents;
88
+ }) => void;
89
+ handleConfigUpdate: (data: any) => void;
74
90
  };
75
91
  export default _default;
package/lib/config.js CHANGED
@@ -3,14 +3,16 @@ 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.components = exports.env = exports.logger = void 0;
7
- /* eslint-disable no-console */
6
+ exports.handleConfigUpdate = exports.handleComponentUpdate = exports.events = exports.components = exports.env = exports.logger = void 0;
8
7
  const events_1 = __importDefault(require("events"));
9
8
  const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
10
9
  const env_1 = __importDefault(require("@blocklet/env"));
11
10
  const constant_1 = require("@blocklet/constant");
11
+ const util_1 = require("@blocklet/env/lib/util");
12
+ const util_2 = require("@blocklet/meta/lib/util");
12
13
  const notification_1 = __importDefault(require("./service/notification"));
13
- const emitter = new events_1.default();
14
+ const events = new events_1.default();
15
+ exports.events = events;
14
16
  const Events = {
15
17
  componentsUpdate: 'componentsUpdate',
16
18
  envUpdate: 'envUpdate',
@@ -20,13 +22,16 @@ const AppConfigKeyMap = {
20
22
  BLOCKLET_APP_DESCRIPTION: 'appDescription',
21
23
  BLOCKLET_APP_URL: 'appUrl',
22
24
  BLOCKLET_APP_SPACE_ENDPOINT: 'appStorageEndpoint',
25
+ BLOCKLET_APP_LANGUAGES: ['languages', util_1.getBlockletLanguages],
23
26
  ABT_NODE_VERSION: 'serverVersion',
24
27
  ABT_NODE: 'serverVersion', // for backup compatibility
25
28
  };
26
29
  const logger = {
30
+ // eslint-disable-next-line no-console
27
31
  info: console.log,
28
32
  debug: (...args) => {
29
33
  if (process.env.NODE_ENV === 'development') {
34
+ // eslint-disable-next-line no-console
30
35
  console.debug(...args);
31
36
  }
32
37
  },
@@ -47,29 +52,47 @@ const parseComponents = () => {
47
52
  };
48
53
  const components = parseComponents();
49
54
  exports.components = components;
55
+ const handleComponentUpdate = (data) => {
56
+ components.splice(0, components.length);
57
+ components.push(...data.components.map((x) => {
58
+ if (x.port) {
59
+ x.webEndpoint = `http://127.0.0.1:${x.port}`;
60
+ }
61
+ return x;
62
+ }));
63
+ events.emit(Events.componentsUpdate, components);
64
+ };
65
+ exports.handleComponentUpdate = handleComponentUpdate;
66
+ const handleConfigUpdate = (data) => {
67
+ const configs = data.configs || [];
68
+ const updates = configs
69
+ .filter((x) => !(0, util_2.isPreferenceKey)(x))
70
+ .reduce((o, { key, value }) => {
71
+ const item = AppConfigKeyMap[key];
72
+ const k = Array.isArray(item) ? item[0] : item || key;
73
+ const v = Array.isArray(item) ? item[1](value) : value;
74
+ o[k] = v;
75
+ return o;
76
+ }, {});
77
+ // Just do a merge
78
+ updates.preferences = Object.assign(env.preferences || {}, (0, util_1.getBlockletPreferences)(configs.reduce((acc, x) => {
79
+ acc[x.key] = x.value;
80
+ return acc;
81
+ }, {})));
82
+ Object.assign(env, updates);
83
+ events.emit(Events.envUpdate, updates);
84
+ };
85
+ exports.handleConfigUpdate = handleConfigUpdate;
50
86
  const inRuntimeEnv = !!process.env.BLOCKLET_APP_SK;
51
87
  if (inRuntimeEnv) {
52
- notification_1.default.on(constant_1.BlockletInternalEvents.componentsUpdated, (data) => {
53
- components.splice(0, components.length);
54
- components.push(...data.components.map((x) => {
55
- if (x.port) {
56
- x.webEndpoint = `http://127.0.0.1:${x.port}`;
57
- }
58
- return x;
59
- }));
60
- emitter.emit(Events.componentsUpdate, components);
61
- });
62
- notification_1.default.on(constant_1.BlockletInternalEvents.appConfigChanged, (data) => {
63
- const configObj = (data.configs || []).reduce((o, { key, value }) => {
64
- o[AppConfigKeyMap[key] || key] = value;
65
- return o;
66
- }, {});
67
- Object.assign(env, configObj);
68
- emitter.emit(Events.envUpdate, configObj);
69
- });
88
+ notification_1.default.on(constant_1.BlockletInternalEvents.componentsUpdated, handleComponentUpdate);
89
+ notification_1.default.on(constant_1.BlockletInternalEvents.appConfigChanged, handleConfigUpdate);
70
90
  }
71
91
  exports.default = {
72
92
  logger,
73
93
  env,
74
94
  components,
95
+ events,
96
+ handleComponentUpdate,
97
+ handleConfigUpdate,
75
98
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.11-next-470e8c41",
6
+ "version": "1.16.11",
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,20 +26,20 @@
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.11-next-470e8c41",
30
- "@abtnode/constant": "1.16.11-next-470e8c41",
31
- "@arcblock/did": "1.18.80",
32
- "@arcblock/did-auth": "1.18.80",
33
- "@arcblock/jwt": "1.18.80",
34
- "@arcblock/ws": "1.18.80",
35
- "@blocklet/constant": "1.16.11-next-470e8c41",
36
- "@blocklet/env": "1.16.11-next-470e8c41",
37
- "@blocklet/meta": "1.16.11-next-470e8c41",
29
+ "@abtnode/client": "1.16.11",
30
+ "@abtnode/constant": "1.16.11",
31
+ "@arcblock/did": "1.18.84",
32
+ "@arcblock/did-auth": "1.18.84",
33
+ "@arcblock/jwt": "1.18.84",
34
+ "@arcblock/ws": "1.18.84",
35
+ "@blocklet/constant": "1.16.11",
36
+ "@blocklet/env": "1.16.11",
37
+ "@blocklet/meta": "1.16.11",
38
38
  "@did-connect/authenticator": "^2.1.59",
39
39
  "@did-connect/handler": "^2.1.59",
40
40
  "@nedb/core": "^2.1.5",
41
- "@ocap/mcrypto": "1.18.80",
42
- "@ocap/wallet": "1.18.80",
41
+ "@ocap/mcrypto": "1.18.84",
42
+ "@ocap/wallet": "1.18.84",
43
43
  "axios": "^0.27.2",
44
44
  "cheerio": "^1.0.0-rc.12",
45
45
  "fs-extra": "^10.1.0",
@@ -73,5 +73,5 @@
73
73
  "ts-node": "^10.9.1",
74
74
  "typescript": "^5.0.4"
75
75
  },
76
- "gitHead": "2f27bfc6522fdf0db1e9b6df717144c98ae30390"
76
+ "gitHead": "bf1a5bd70ed2ee7cd044c6b629c18bbc900f1598"
77
77
  }