@blocklet/sdk 1.16.21-beta-edf184e1 → 1.16.21-beta-e828f413

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.js CHANGED
@@ -282,7 +282,7 @@ const runInServer = (fn, type) =>
282
282
  }
283
283
  };
284
284
  const inRuntimeEnv = !!process.env.BLOCKLET_APP_SK;
285
- if (inRuntimeEnv && !process.env.BLOCKLET_HOOK_NAME) {
285
+ if (inRuntimeEnv && !process.env.BLOCKLET_HOOK_NAME && process.env.BLOCKLET_MODE !== 'test') {
286
286
  notification_1.default.on(constant_1.BlockletInternalEvents.appConfigChanged, _handleConfigUpdate);
287
287
  notification_1.default.on(constant_1.BlockletInternalEvents.componentConfigChanged, _handleComponentConfigUpdate);
288
288
  // Reactive fetch
@@ -205,6 +205,9 @@ const initClient = () => {
205
205
  }
206
206
  };
207
207
  const ensureClient = () => {
208
+ if (process.env.BLOCKLET_MODE === 'test') {
209
+ return;
210
+ }
208
211
  if (!client) {
209
212
  initClient();
210
213
  }
@@ -0,0 +1 @@
1
+ export default function setupJest(): void;
@@ -0,0 +1,52 @@
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
+ // Setup blocklet environments for jest
7
+ const os_1 = __importDefault(require("os"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const parse_1 = __importDefault(require("@blocklet/meta/lib/parse"));
11
+ const mcrypto_1 = require("@ocap/mcrypto");
12
+ const wallet_1 = require("@ocap/wallet");
13
+ function setupJest() {
14
+ try {
15
+ const dir = process.cwd();
16
+ const wallet = (0, wallet_1.fromRandom)({ role: mcrypto_1.types.RoleType.ROLE_APPLICATION });
17
+ const meta = (0, parse_1.default)(dir, { ensureComponentStore: false });
18
+ const tmpDir = path_1.default.join(os_1.default.tmpdir(), meta.did);
19
+ if (fs_1.default.existsSync(tmpDir) === false) {
20
+ fs_1.default.mkdirSync(tmpDir, { recursive: true });
21
+ }
22
+ process.env.BLOCKLET_MODE = 'test';
23
+ process.env.BLOCKLET_DID = meta.did;
24
+ process.env.BLOCKLET_COMPONENT_DID = meta.did;
25
+ process.env.BLOCKLET_DATA_DIR = path_1.default.join(tmpDir, wallet.address);
26
+ process.env.BLOCKLET_LOG_DIR = path_1.default.join(tmpDir, wallet.address);
27
+ process.env.BLOCKLET_APP_SK = wallet.secretKey;
28
+ process.env.BLOCKLET_APP_PSK = wallet.secretKey;
29
+ process.env.BLOCKLET_APP_ID = wallet.address;
30
+ process.env.BLOCKLET_APP_PID = wallet.address;
31
+ process.env.BLOCKLET_APP_IDS = wallet.address;
32
+ process.env.BLOCKLET_APP_NAME = meta.title;
33
+ process.env.BLOCKLET_APP_DESCRIPTION = meta.description;
34
+ process.env.BLOCKLET_APP_URL = 'http://192.168.0.10:3030';
35
+ process.env.BLOCKLET_MOUNT_POINTS = JSON.stringify([
36
+ {
37
+ title: meta.title,
38
+ did: meta.did,
39
+ name: meta.name,
40
+ version: meta.version,
41
+ mountPoint: '/',
42
+ status: 6,
43
+ port: 8181,
44
+ resources: [],
45
+ },
46
+ ]);
47
+ }
48
+ catch (err) {
49
+ console.error('Failed to setup blocklet environment for jest', err);
50
+ }
51
+ }
52
+ exports.default = setupJest;
@@ -0,0 +1 @@
1
+ export default function setupJest(): void;
@@ -0,0 +1,24 @@
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
+ // Setup blocklet environments for jest
7
+ const os_1 = __importDefault(require("os"));
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const parse_1 = __importDefault(require("@blocklet/meta/lib/parse"));
11
+ function setupJest() {
12
+ try {
13
+ const dir = process.cwd();
14
+ const meta = (0, parse_1.default)(dir, { ensureComponentStore: false });
15
+ const tmpDir = path_1.default.join(os_1.default.tmpdir(), meta.did);
16
+ if (fs_extra_1.default.existsSync(tmpDir)) {
17
+ fs_extra_1.default.rm(tmpDir, { recursive: true });
18
+ }
19
+ }
20
+ catch (err) {
21
+ console.error('Failed to tear blocklet environment for jest', err);
22
+ }
23
+ }
24
+ exports.default = setupJest;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.21-beta-edf184e1",
6
+ "version": "1.16.21-beta-e828f413",
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.21-beta-edf184e1",
30
- "@abtnode/constant": "1.16.21-beta-edf184e1",
31
- "@arcblock/did": "1.18.105",
32
- "@arcblock/did-auth": "1.18.105",
33
- "@arcblock/jwt": "1.18.105",
34
- "@arcblock/ws": "1.18.105",
35
- "@blocklet/constant": "1.16.21-beta-edf184e1",
36
- "@blocklet/env": "1.16.21-beta-edf184e1",
37
- "@blocklet/meta": "1.16.21-beta-edf184e1",
29
+ "@abtnode/client": "1.16.21-beta-e828f413",
30
+ "@abtnode/constant": "1.16.21-beta-e828f413",
31
+ "@arcblock/did": "1.18.107",
32
+ "@arcblock/did-auth": "1.18.107",
33
+ "@arcblock/jwt": "1.18.107",
34
+ "@arcblock/ws": "1.18.107",
35
+ "@blocklet/constant": "1.16.21-beta-e828f413",
36
+ "@blocklet/env": "1.16.21-beta-e828f413",
37
+ "@blocklet/meta": "1.16.21-beta-e828f413",
38
38
  "@did-connect/authenticator": "^2.2.1",
39
39
  "@did-connect/handler": "^2.2.1",
40
40
  "@nedb/core": "^2.1.5",
41
- "@ocap/mcrypto": "1.18.105",
42
- "@ocap/wallet": "1.18.105",
41
+ "@ocap/mcrypto": "1.18.107",
42
+ "@ocap/wallet": "1.18.107",
43
43
  "axios": "^0.27.2",
44
44
  "cheerio": "^1.0.0-rc.12",
45
45
  "fs-extra": "^10.1.0",
@@ -75,5 +75,5 @@
75
75
  "ts-node": "^10.9.1",
76
76
  "typescript": "^5.0.4"
77
77
  },
78
- "gitHead": "e89c7e31d2d9ca5d00ae1f72304bdc7dcb78cc44"
78
+ "gitHead": "936af9cb0549f341d3683ea63085b460bf6ddbf0"
79
79
  }