@blocklet/sdk 1.16.22 → 1.16.23-beta-f85576a6

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.
@@ -5,6 +5,7 @@ type Resource = {
5
5
  version: string;
6
6
  status?: number;
7
7
  path?: string;
8
+ env?: Record<string, any>;
8
9
  };
9
10
  declare function getResources({ scope, components: allComponents, types, skipRunningCheck, ignorePublic, }?: {
10
11
  scope?: 'all' | 'pack' | 'excludePack';
@@ -4,8 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getResources = void 0;
7
+ const path_1 = __importDefault(require("path"));
7
8
  const pick_1 = __importDefault(require("lodash/pick"));
8
9
  const constant_1 = require("@blocklet/constant");
10
+ const parse_env_file_1 = require("../util/parse-env-file");
9
11
  function getResources({ scope, components: allComponents, types, skipRunningCheck, ignorePublic, } = {
10
12
  scope: 'all',
11
13
  components: [],
@@ -14,6 +16,7 @@ function getResources({ scope, components: allComponents, types, skipRunningChec
14
16
  if (!types?.length) {
15
17
  return list;
16
18
  }
19
+ const appDataDir = process.env.BLOCKLET_APP_DATA_DIR;
17
20
  let components = allComponents;
18
21
  if (scope === 'pack') {
19
22
  components = allComponents.filter((x) => x.group === constant_1.BlockletGroup.pack);
@@ -31,10 +34,20 @@ function getResources({ scope, components: allComponents, types, skipRunningChec
31
34
  return types.some((item) => item?.did === resourceDid && item?.type === resourceType);
32
35
  });
33
36
  if (resource?.path) {
34
- list.push({
37
+ const item = {
35
38
  ...(0, pick_1.default)(component, ['title', 'did', 'version', 'status']),
36
39
  path: resource.path,
37
- });
40
+ };
41
+ // import env from public env file
42
+ try {
43
+ const envFile = path_1.default.join(appDataDir, constant_1.APP_CONFIG_PUBLIC_DIR, component.did, constant_1.COMPONENT_ENV_FILE_NAME);
44
+ const env = (0, parse_env_file_1.parseEnvFile)(envFile);
45
+ item.env = env;
46
+ }
47
+ catch (error) {
48
+ console.error(error);
49
+ }
50
+ list.push(item);
38
51
  }
39
52
  });
40
53
  return list;
package/lib/config.js CHANGED
@@ -21,6 +21,7 @@ const security_1 = require("./security");
21
21
  const version_1 = require("./version");
22
22
  const notification_1 = __importDefault(require("./service/notification"));
23
23
  const server_version_1 = __importDefault(require("./util/server-version"));
24
+ const parse_env_file_1 = require("./util/parse-env-file");
24
25
  const events = new events_1.default();
25
26
  exports.events = events;
26
27
  const Events = {
@@ -71,18 +72,10 @@ if (appDataDir) {
71
72
  }
72
73
  try {
73
74
  const envFile = path_1.default.join(appDataDir, constant_1.APP_CONFIG_DIR, process.env.BLOCKLET_COMPONENT_DID, constant_1.COMPONENT_ENV_FILE_NAME);
74
- if (fs_1.default.existsSync(envFile)) {
75
- const raw = fs_1.default.readFileSync(envFile).toString();
76
- const decrypted = (0, security_1.decrypt)(raw, process.env.BLOCKLET_COMPONENT_API_KEY, process.env.BLOCKLET_COMPONENT_DID);
77
- const configObj = JSON.parse(decrypted);
78
- envFromDisk = Object.keys(configObj)
79
- .filter((key) => !(0, util_2.isPreferenceKey)({ key }))
80
- .reduce((o, key) => {
81
- o[key] = configObj[key];
82
- return o;
83
- }, {});
84
- envFromDisk.preferences = (0, util_1.getBlockletPreferences)(configObj);
85
- }
75
+ envFromDisk = (0, parse_env_file_1.parseEnvFile)(envFile, {
76
+ apiKey: process.env.BLOCKLET_COMPONENT_API_KEY,
77
+ componentDid: process.env.BLOCKLET_COMPONENT_DID,
78
+ });
86
79
  }
87
80
  catch (error) {
88
81
  logger.error(error);
@@ -0,0 +1,12 @@
1
+ declare const parseEnvFile: (envFile: string, { apiKey, componentDid }?: {
2
+ apiKey?: string;
3
+ componentDid?: string;
4
+ }) => Record<string, any>;
5
+ export { parseEnvFile };
6
+ declare const _default: {
7
+ parseEnvFile: (envFile: string, { apiKey, componentDid }?: {
8
+ apiKey?: string;
9
+ componentDid?: string;
10
+ }) => Record<string, any>;
11
+ };
12
+ export default _default;
@@ -0,0 +1,28 @@
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.parseEnvFile = void 0;
7
+ const fs_extra_1 = __importDefault(require("fs-extra"));
8
+ const util_1 = require("@blocklet/meta/lib/util");
9
+ const util_2 = require("@blocklet/env/lib/util");
10
+ const security_1 = require("../security");
11
+ const parseEnvFile = (envFile, { apiKey, componentDid } = {}) => {
12
+ if (!fs_extra_1.default.existsSync(envFile)) {
13
+ return {};
14
+ }
15
+ const raw = fs_extra_1.default.readFileSync(envFile).toString();
16
+ const decrypted = apiKey ? (0, security_1.decrypt)(raw, apiKey, componentDid) : raw;
17
+ const configObj = JSON.parse(decrypted);
18
+ const env = Object.keys(configObj)
19
+ .filter((key) => !(0, util_1.isPreferenceKey)({ key }))
20
+ .reduce((o, key) => {
21
+ o[key] = configObj[key];
22
+ return o;
23
+ }, {});
24
+ env.preferences = (0, util_2.getBlockletPreferences)(configObj);
25
+ return env;
26
+ };
27
+ exports.parseEnvFile = parseEnvFile;
28
+ exports.default = { parseEnvFile };
package/lib/version.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- declare const version = "1.16.22";
1
+ declare const version = "1.16.23";
2
2
  export { version };
3
3
  declare const _default: {
4
4
  version: string;
package/lib/version.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
- const version = '1.16.22';
4
+ const version = '1.16.23';
5
5
  exports.version = version;
6
6
  exports.default = { version };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.22",
6
+ "version": "1.16.23-beta-f85576a6",
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.22",
30
- "@abtnode/constant": "1.16.22",
29
+ "@abtnode/client": "1.16.23-beta-f85576a6",
30
+ "@abtnode/constant": "1.16.23-beta-f85576a6",
31
31
  "@arcblock/did": "1.18.108",
32
32
  "@arcblock/did-auth": "1.18.108",
33
33
  "@arcblock/jwt": "1.18.108",
34
34
  "@arcblock/ws": "1.18.108",
35
- "@blocklet/constant": "1.16.22",
36
- "@blocklet/env": "1.16.22",
37
- "@blocklet/meta": "1.16.22",
35
+ "@blocklet/constant": "1.16.23-beta-f85576a6",
36
+ "@blocklet/env": "1.16.23-beta-f85576a6",
37
+ "@blocklet/meta": "1.16.23-beta-f85576a6",
38
38
  "@did-connect/authenticator": "^2.2.1",
39
39
  "@did-connect/handler": "^2.2.1",
40
40
  "@nedb/core": "^2.1.5",
@@ -75,5 +75,5 @@
75
75
  "ts-node": "^10.9.1",
76
76
  "typescript": "^5.0.4"
77
77
  },
78
- "gitHead": "eba523c2d8f62f2a1c742b23e3280774bf9bc4cf"
78
+ "gitHead": "bac83a74944b4cef3ccb386277023caf0e1d5cd4"
79
79
  }