create-blocklet 0.2.9 → 0.2.13

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.
Files changed (37) hide show
  1. package/common/.github/workflows/main.yml +2 -2
  2. package/index.js +7 -12
  3. package/lib/{abtnode.js → server.js} +8 -12
  4. package/package.json +2 -2
  5. package/template-dapp/react/README.md +1 -1
  6. package/template-dapp/react/blocklet.yml +1 -6
  7. package/template-dapp/react/server/hooks/pre-start.js +4 -4
  8. package/template-dapp/react/server/index.js +1 -1
  9. package/template-dapp/react/server/libs/auth.js +6 -15
  10. package/template-dapp/react/server/libs/env.js +2 -8
  11. package/template-dapp/react/server/routes/index.js +2 -2
  12. package/template-dapp/react/src/pages/home.js +2 -9
  13. package/template-dapp/vue/README.md +1 -1
  14. package/template-dapp/vue/blocklet.yml +1 -6
  15. package/template-dapp/vue/server/hooks/pre-start.js +4 -4
  16. package/template-dapp/vue/server/index.js +1 -1
  17. package/template-dapp/vue/server/libs/auth.js +6 -15
  18. package/template-dapp/vue/server/libs/env.js +2 -8
  19. package/template-dapp/vue/server/routes/index.js +2 -2
  20. package/template-dapp/vue/src/App.vue +1 -9
  21. package/template-dapp/vue2/README.md +1 -1
  22. package/template-dapp/vue2/blocklet.yml +1 -6
  23. package/template-dapp/vue2/server/hooks/pre-start.js +4 -4
  24. package/template-dapp/vue2/server/index.js +1 -1
  25. package/template-dapp/vue2/server/libs/auth.js +6 -15
  26. package/template-dapp/vue2/server/libs/env.js +2 -8
  27. package/template-dapp/vue2/server/routes/index.js +2 -2
  28. package/template-dapp/vue2/src/pages/Home.vue +1 -11
  29. package/template-static/react/README.md +1 -1
  30. package/template-static/react/blocklet.yml +1 -1
  31. package/template-static/vue/README.md +1 -1
  32. package/template-static/vue/blocklet.yml +1 -1
  33. package/template-static/vue2/README.md +1 -1
  34. package/template-static/vue2/blocklet.yml +1 -1
  35. package/template-dapp/react/server/middlewares/user.js +0 -10
  36. package/template-dapp/vue/server/middlewares/user.js +0 -10
  37. package/template-dapp/vue2/server/middlewares/user.js +0 -10
@@ -27,8 +27,8 @@ jobs:
27
27
  skip-upload: false
28
28
  skip-deploy: false
29
29
  bundle-command: yarn bundle
30
- store-endpoint: ${{ secrets.STORE_ENDPOINT_STAGING }}
31
- store-access-token: ${{ secrets.STORE_ACCESS_TOKEN_STAGING }}
30
+ store-endpoint: ${{ secrets.STORE_ENDPOINT_DEV }}
31
+ store-access-token: ${{ secrets.STORE_ACCESS_TOKEN_DEV }}
32
32
  server-endpoint: ${{ secrets.STAGING_NODE_ENDPOINT }}
33
33
  server-access-key: ${{ secrets.STAGING_NODE_ACCESS_KEY }}
34
34
  server-access-secret: ${{ secrets.STAGING_NODE_ACCESS_SECRET }}
package/index.js CHANGED
@@ -12,12 +12,7 @@ import * as envfile from 'envfile';
12
12
 
13
13
  import { echoBrand, echoDocument } from './lib/arcblock.js';
14
14
  import { getAuthor } from './lib/npm.js';
15
- import {
16
- checkAbtnodeInstalled,
17
- checkAbtnodeRunning,
18
- checkSatisfiedVersion,
19
- getAbtnodeDirectory,
20
- } from './lib/abtnode.js';
15
+ import { checkServerInstalled, checkServerRunning, checkSatisfiedVersion, getServerDirectory } from './lib/server.js';
21
16
  import { toBlockletDid, toDidIcon } from './lib/did.js';
22
17
 
23
18
  const argv = minimist(process.argv.slice(2));
@@ -201,11 +196,11 @@ async function init() {
201
196
 
202
197
  console.log('Checking blocklet server runtime environment...', '\n');
203
198
 
204
- const isAbtnodeInstalled = checkAbtnodeInstalled();
199
+ const isServerInstalled = checkServerInstalled();
205
200
  const isSatisfiedVersion = checkSatisfiedVersion();
206
- const isAbtnodeRunning = checkAbtnodeRunning();
201
+ const isServerRunning = checkServerRunning();
207
202
 
208
- if (!isAbtnodeInstalled) {
203
+ if (!isServerInstalled) {
209
204
  // 未安装 blocklet server
210
205
  console.log(red('To run the blocklet, you need a running blocklet server instance on local machine.'), '\n');
211
206
  console.log(`Checkout ${green('README.md')} for more usage instructions.`);
@@ -216,9 +211,9 @@ async function init() {
216
211
  // 已安装 blocklet server,但版本不满足
217
212
  console.log(red('Your blocklet server version is outdate, please update it to the latest version.'));
218
213
  console.log('Now you should run:', '\n');
219
- if (isAbtnodeRunning) {
214
+ if (isServerRunning) {
220
215
  // blocklet server 已经启动
221
- const serverPath = getAbtnodeDirectory();
216
+ const serverPath = getServerDirectory();
222
217
  console.log(cyan(`cd ${serverPath}`));
223
218
  console.log(cyan('blocklet server stop'));
224
219
  console.log(cyan('npm install -g @blocklet/cli'));
@@ -230,7 +225,7 @@ async function init() {
230
225
  console.log(cyan('npm install -g @blocklet/cli'));
231
226
  console.log(cyan('blocklet server start -a'));
232
227
  }
233
- } else if (!isAbtnodeRunning) {
228
+ } else if (!isServerRunning) {
234
229
  // 已经安装 blocklet server,且版本满足,并且 blocklet server 未启动
235
230
  console.log(red('You need to start your blocklet server before develop this blocklet.'));
236
231
  console.log('Now you should run:', '\n');
@@ -1,27 +1,27 @@
1
1
  import semver from 'semver';
2
2
  import { getOutput } from './index.js';
3
3
 
4
- export function checkAbtnodeInstalled() {
4
+ export function checkServerInstalled() {
5
5
  const output = getOutput('which blocklet');
6
6
  return !!output;
7
7
  }
8
8
 
9
- export function getAbtnodeVersion() {
9
+ export function getServerVersion() {
10
10
  const output = getOutput('blocklet --version');
11
11
  return output.trim();
12
12
  }
13
13
 
14
- export function getAbtnodeStatus() {
14
+ export function getServerStatus() {
15
15
  const output = getOutput('blocklet server status');
16
- const [matchStr] = output.match(/ABT Node status:[\s\S]*?\n/gm) || [];
16
+ const [matchStr] = output.match(/Blocklet Server status:[\s\S]*?\n/g) || [];
17
17
  if (!matchStr) {
18
18
  return 'stop';
19
19
  }
20
- const status = matchStr.replace(/ABT Node status:[\s]*([\S]+)\n/gm, '$1');
20
+ const status = matchStr.replace(/Blocklet Server status:\s*(\S+)\s*\S*\n*[\s\S]*/gm, '$1');
21
21
  return status.toLowerCase();
22
22
  }
23
- export function checkAbtnodeRunning() {
24
- const status = getAbtnodeStatus();
23
+ export function checkServerRunning() {
24
+ const status = getServerStatus();
25
25
  return status === 'running';
26
26
  }
27
27
 
@@ -31,7 +31,7 @@ export function checkSatisfiedVersion() {
31
31
  return semver.satisfies(version, '>= 1.6.1');
32
32
  }
33
33
 
34
- export function getAbtnodeDirectory() {
34
+ export function getServerDirectory() {
35
35
  const output = getOutput('blocklet server status');
36
36
  const [matchStr] = output.match(/Blocklet Server Data Directory:[\s\S]*?\n/gm) || [];
37
37
  if (!matchStr) return null;
@@ -39,7 +39,3 @@ export function getAbtnodeDirectory() {
39
39
  const directory = matchStr.replace(/Blocklet Server Data Directory:[\s]*([\S]+)\/\.abtnode\n/gm, '$1');
40
40
  return directory;
41
41
  }
42
-
43
- const dic = getAbtnodeDirectory();
44
-
45
- console.log(dic);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-blocklet",
3
- "version": "0.2.9",
3
+ "version": "0.2.13",
4
4
  "exports": "./index.js",
5
5
  "type": "module",
6
6
  "repository": "git@github.com:blocklet/create-blocklet.git",
@@ -40,7 +40,7 @@
40
40
  "prompts": "^2.4.1",
41
41
  "rc": "^1.2.8",
42
42
  "semver": "^7.3.5",
43
- "shelljs": "^0.8.4",
43
+ "shelljs": "^0.8.5",
44
44
  "terminal-link": "^3.0.0",
45
45
  "yaml": "^1.10.2"
46
46
  },
@@ -145,7 +145,7 @@ After developing a blocklet, you may need to bundle it. Use `npm run bundle` com
145
145
  ## Learn More
146
146
 
147
147
  - Full specification of `blocklet.yml`: [https://github.com/blocklet/blocklet-specification/blob/main/docs/meta.md](https://github.com/blocklet/blocklet-specification/blob/main/docs/meta.md)
148
- - Full document of AbtNode & blocklet development: [https://docs.arcblock.io/abtnode/en/introduction](https://docs.arcblock.io/abtnode/en/introduction)
148
+ - Full document of Blocklet Server & blocklet development: [https://docs.arcblock.io/abtnode/en/introduction](https://docs.arcblock.io/abtnode/en/introduction)
149
149
 
150
150
  ## License
151
151
 
@@ -1,6 +1,6 @@
1
1
  name: template-react
2
2
  title: Blocklet Template React
3
- description: An ABT Node blocklet
3
+ description: A Blocklet Server blocklet
4
4
  keywords:
5
5
  - blocklet
6
6
  - react
@@ -48,11 +48,6 @@ scripts:
48
48
  preStart: node server/hooks/pre-start.js
49
49
  dev: npm run start
50
50
  environments:
51
- - name: CHAIN_ID
52
- description: What's endpoint of the chain id?
53
- required: true
54
- default: 'beta'
55
- secure: false
56
51
  - name: CHAIN_HOST
57
52
  description: What's endpoint of the chain?
58
53
  required: true
@@ -1,18 +1,18 @@
1
+ require('@blocklet/sdk/lib/error-handler');
1
2
  require('dotenv-flow').config();
2
3
 
3
4
  const Client = require('@ocap/client');
4
5
 
5
6
  const env = require('../libs/env');
6
- const { wallet } = require('../libs/auth');
7
7
  const logger = require('../libs/logger');
8
+ const { wallet } = require('../libs/auth');
8
9
  const { name } = require('../../package.json');
9
10
 
10
- const client = new Client(env.chainHost);
11
-
12
11
  const ensureAccountDeclared = async () => {
13
- // Check for application account, skip this if we are running as a child component
14
12
  if (env.isComponent) return;
13
+ if (!env.chainHost) return;
15
14
 
15
+ const client = new Client(env.chainHost);
16
16
  const { state } = await client.getAccountState({ address: wallet.toAddress() }, { ignoreFields: ['context'] });
17
17
  if (!state) {
18
18
  const hash = await client.declare({ moniker: name, wallet });
@@ -47,7 +47,7 @@ if (isProduction) {
47
47
  app.use(router);
48
48
  }
49
49
 
50
- const port = parseInt(process.env.BLOCKLET_PORT || process.env.APP_PORT, 10) || 3030;
50
+ const port = parseInt(process.env.BLOCKLET_PORT, 10) || 3030;
51
51
 
52
52
  app.listen(port, (err) => {
53
53
  if (err) throw err;
@@ -1,26 +1,17 @@
1
1
  const path = require('path');
2
2
  const AuthStorage = require('@arcblock/did-auth-storage-nedb');
3
+ const getWallet = require('@blocklet/sdk/lib/wallet');
3
4
  const WalletAuthenticator = require('@blocklet/sdk/lib/wallet-authenticator');
4
- const WalletHandlers = require('@blocklet/sdk/lib/wallet-handler');
5
- const { types } = require('@ocap/mcrypto');
6
- const { fromSecretKey, WalletType } = require('@ocap/wallet');
7
- const logger = require('./logger');
5
+ const WalletHandler = require('@blocklet/sdk/lib/wallet-handler');
8
6
 
9
- const appSk = process.env.APP_SK || process.env.BLOCKLET_APP_SK;
10
- const wallet = fromSecretKey(appSk, WalletType({ role: types.RoleType.ROLE_APPLICATION }));
7
+ const env = require('./env');
11
8
 
9
+ const wallet = getWallet();
12
10
  const authenticator = new WalletAuthenticator();
13
-
14
- const handlers = new WalletHandlers({
11
+ const handlers = new WalletHandler({
15
12
  authenticator,
16
- tokenGenerator: () => Date.now().toString(),
17
13
  tokenStorage: new AuthStorage({
18
- dbPath: path.join(process.env.BLOCKLET_DATA_DIR, 'auth.db'),
19
- onload: (err) => {
20
- if (err) {
21
- logger.error(`Failed to load database from ${path.join(process.env.BLOCKLET_DATA_DIR, 'auth.db')}`, err);
22
- }
23
- },
14
+ dbPath: path.join(env.dataDir, 'auth.db'),
24
15
  }),
25
16
  });
26
17
 
@@ -1,12 +1,6 @@
1
- const blockletRealDid = process.env.BLOCKLET_REAL_DID || '';
2
- const blockletDid = process.env.BLOCKLET_DID || '';
3
- const isComponent = blockletRealDid && blockletDid && blockletRealDid !== blockletDid;
1
+ const env = require('@blocklet/sdk/lib/env');
4
2
 
5
3
  module.exports = {
6
- chainId: process.env.CHAIN_ID || '',
4
+ ...env,
7
5
  chainHost: process.env.CHAIN_HOST || '',
8
- appId: process.env.BLOCKLET_APP_ID || '',
9
- appName: process.env.APP_NAME || process.env.BLOCKLET_APP_NAME || '',
10
- appDescription: process.env.APP_DESCRIPTION || process.env.BLOCKLET_APP_DESCRIPTION || '',
11
- isComponent,
12
6
  };
@@ -1,6 +1,6 @@
1
+ const middleware = require('@blocklet/sdk/lib/middlewares');
1
2
  const router = require('express').Router();
2
- const env = require('../libs/env');
3
3
 
4
- router.use('/env', (req, res) => res.json(env));
4
+ router.use('/user', middleware.user(), (req, res) => res.json(req.user));
5
5
 
6
6
  module.exports = router;
@@ -1,21 +1,14 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React from 'react';
2
2
  import { Link } from 'react-router-dom';
3
3
 
4
4
  import logo from '../logo.svg';
5
- import api from '../libs/api';
6
5
 
7
6
  const Home = () => {
8
- const [env, setEnv] = useState({});
9
- useEffect(async () => {
10
- const { data } = await api.get('/api/env');
11
- setEnv(data);
12
- }, []);
13
-
14
7
  return (
15
8
  <header className="app-header">
16
9
  <img src={logo} className="app-logo" alt="logo" />
17
10
  <pre style={{ textAlign: 'left' }}>
18
- <code>{JSON.stringify(env, null, 2)}</code>
11
+ <code>{JSON.stringify(window.blocklet, null, 2)}</code>
19
12
  </pre>
20
13
  <Link className="app-link" to="/about">
21
14
  About
@@ -139,7 +139,7 @@ After developing a blocklet, you may need to bundle it. Use `npm run bundle` com
139
139
  ## Learn More
140
140
 
141
141
  - Full specification of `blocklet.yml`: [https://github.com/blocklet/blocklet-specification/blob/main/docs/meta.md](https://github.com/blocklet/blocklet-specification/blob/main/docs/meta.md)
142
- - Full document of AbtNode & blocklet development: [https://docs.arcblock.io/abtnode/en/introduction](https://docs.arcblock.io/abtnode/en/introduction)
142
+ - Full document of Blocklet Server & blocklet development: [https://docs.arcblock.io/abtnode/en/introduction](https://docs.arcblock.io/abtnode/en/introduction)
143
143
 
144
144
  ## License
145
145
 
@@ -1,6 +1,6 @@
1
1
  name: template-vue
2
2
  title: Blocklet Template Vue
3
- description: ABT Node blocklet project
3
+ description: A Blocklet Server blocklet
4
4
  keywords:
5
5
  - blocklet
6
6
  - vue
@@ -47,11 +47,6 @@ scripts:
47
47
  preStart: node server/hooks/pre-start.js
48
48
  dev: npm run start
49
49
  environments:
50
- - name: CHAIN_ID
51
- description: What's endpoint of the chain id?
52
- required: true
53
- default: 'beta'
54
- secure: false
55
50
  - name: CHAIN_HOST
56
51
  description: What's endpoint of the chain?
57
52
  required: true
@@ -1,18 +1,18 @@
1
+ require('@blocklet/sdk/lib/error-handler');
1
2
  require('dotenv-flow').config();
2
3
 
3
4
  const Client = require('@ocap/client');
4
5
 
5
6
  const env = require('../libs/env');
6
- const { wallet } = require('../libs/auth');
7
7
  const logger = require('../libs/logger');
8
+ const { wallet } = require('../libs/auth');
8
9
  const { name } = require('../../package.json');
9
10
 
10
- const client = new Client(env.chainHost);
11
-
12
11
  const ensureAccountDeclared = async () => {
13
- // Check for application account, skip this if we are running as a child component
14
12
  if (env.isComponent) return;
13
+ if (!env.chainHost) return;
15
14
 
15
+ const client = new Client(env.chainHost);
16
16
  const { state } = await client.getAccountState({ address: wallet.toAddress() }, { ignoreFields: ['context'] });
17
17
  if (!state) {
18
18
  const hash = await client.declare({ moniker: name, wallet });
@@ -47,7 +47,7 @@ if (isProduction) {
47
47
  app.use(router);
48
48
  }
49
49
 
50
- const port = parseInt(process.env.BLOCKLET_PORT || process.env.APP_PORT, 10) || 3030;
50
+ const port = parseInt(process.env.BLOCKLET_PORT, 10) || 3030;
51
51
 
52
52
  app.listen(port, (err) => {
53
53
  if (err) throw err;
@@ -1,26 +1,17 @@
1
1
  const path = require('path');
2
2
  const AuthStorage = require('@arcblock/did-auth-storage-nedb');
3
+ const getWallet = require('@blocklet/sdk/lib/wallet');
3
4
  const WalletAuthenticator = require('@blocklet/sdk/lib/wallet-authenticator');
4
- const WalletHandlers = require('@blocklet/sdk/lib/wallet-handler');
5
- const { types } = require('@ocap/mcrypto');
6
- const { fromSecretKey, WalletType } = require('@ocap/wallet');
7
- const logger = require('./logger');
5
+ const WalletHandler = require('@blocklet/sdk/lib/wallet-handler');
8
6
 
9
- const appSk = process.env.APP_SK || process.env.BLOCKLET_APP_SK;
10
- const wallet = fromSecretKey(appSk, WalletType({ role: types.RoleType.ROLE_APPLICATION }));
7
+ const env = require('./env');
11
8
 
9
+ const wallet = getWallet();
12
10
  const authenticator = new WalletAuthenticator();
13
-
14
- const handlers = new WalletHandlers({
11
+ const handlers = new WalletHandler({
15
12
  authenticator,
16
- tokenGenerator: () => Date.now().toString(),
17
13
  tokenStorage: new AuthStorage({
18
- dbPath: path.join(process.env.BLOCKLET_DATA_DIR, 'auth.db'),
19
- onload: (err) => {
20
- if (err) {
21
- logger.error(`Failed to load database from ${path.join(process.env.BLOCKLET_DATA_DIR, 'auth.db')}`, err);
22
- }
23
- },
14
+ dbPath: path.join(env.dataDir, 'auth.db'),
24
15
  }),
25
16
  });
26
17
 
@@ -1,12 +1,6 @@
1
- const blockletRealDid = process.env.BLOCKLET_REAL_DID || '';
2
- const blockletDid = process.env.BLOCKLET_DID || '';
3
- const isComponent = blockletRealDid && blockletDid && blockletRealDid !== blockletDid;
1
+ const env = require('@blocklet/sdk/lib/env');
4
2
 
5
3
  module.exports = {
6
- chainId: process.env.CHAIN_ID || '',
4
+ ...env,
7
5
  chainHost: process.env.CHAIN_HOST || '',
8
- appId: process.env.BLOCKLET_APP_ID || '',
9
- appName: process.env.APP_NAME || process.env.BLOCKLET_APP_NAME || '',
10
- appDescription: process.env.APP_DESCRIPTION || process.env.BLOCKLET_APP_DESCRIPTION || '',
11
- isComponent,
12
6
  };
@@ -1,6 +1,6 @@
1
+ const middleware = require('@blocklet/sdk/lib/middlewares');
1
2
  const router = require('express').Router();
2
- const env = require('../libs/env');
3
3
 
4
- router.use('/env', (req, res) => res.json(env));
4
+ router.use('/user', middleware.user(), (req, res) => res.json(req.user));
5
5
 
6
6
  module.exports = router;
@@ -3,14 +3,6 @@ import { ref } from 'vue';
3
3
  // This starter template is using Vue 3 <script setup> SFCs
4
4
  // Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
5
5
  import HelloWorld from './components/HelloWorld.vue';
6
- import api from './libs/api';
7
-
8
- const envData = ref({});
9
-
10
- (async () => {
11
- const { data } = await api.get('/api/env');
12
- envData.value = data;
13
- })();
14
6
  </script>
15
7
 
16
8
  <template>
@@ -18,7 +10,7 @@ const envData = ref({});
18
10
  <HelloWorld msg="Hello Vue 3 + Vite" />
19
11
  <div :style="{ display: 'flex', justifyContent: 'center' }">
20
12
  <pre :style="{ textAlign: 'left' }">
21
- <code>{{ JSON.stringify(envData, null, 2) }}</code>
13
+ <code>{{ JSON.stringify(window.blocklet, null, 2) }}</code>
22
14
  </pre>
23
15
  </div>
24
16
  </template>
@@ -139,7 +139,7 @@ After developing a blocklet, you may need to bundle it. Use `npm run bundle` com
139
139
  ## Learn More
140
140
 
141
141
  - Full specification of `blocklet.yml`: [https://github.com/blocklet/blocklet-specification/blob/main/docs/meta.md](https://github.com/blocklet/blocklet-specification/blob/main/docs/meta.md)
142
- - Full document of AbtNode & blocklet development: [https://docs.arcblock.io/abtnode/en/introduction](https://docs.arcblock.io/abtnode/en/introduction)
142
+ - Full document of Blocklet Server & blocklet development: [https://docs.arcblock.io/abtnode/en/introduction](https://docs.arcblock.io/abtnode/en/introduction)
143
143
 
144
144
  ## License
145
145
 
@@ -1,6 +1,6 @@
1
1
  name: template-vue2
2
2
  title: Blocklet Template Vue2
3
- description: ABT Node blocklet project
3
+ description: A Blocklet Server blocklet
4
4
  keywords:
5
5
  - blocklet
6
6
  - vue
@@ -45,11 +45,6 @@ requirements:
45
45
  scripts:
46
46
  dev: npm run start
47
47
  environments:
48
- - name: CHAIN_ID
49
- description: What's endpoint of the chain id?
50
- required: true
51
- default: 'beta'
52
- secure: false
53
48
  - name: CHAIN_HOST
54
49
  description: What's endpoint of the chain?
55
50
  required: true
@@ -1,18 +1,18 @@
1
+ require('@blocklet/sdk/lib/error-handler');
1
2
  require('dotenv-flow').config();
2
3
 
3
4
  const Client = require('@ocap/client');
4
5
 
5
6
  const env = require('../libs/env');
6
- const { wallet } = require('../libs/auth');
7
7
  const logger = require('../libs/logger');
8
+ const { wallet } = require('../libs/auth');
8
9
  const { name } = require('../../package.json');
9
10
 
10
- const client = new Client(env.chainHost);
11
-
12
11
  const ensureAccountDeclared = async () => {
13
- // Check for application account, skip this if we are running as a child component
14
12
  if (env.isComponent) return;
13
+ if (!env.chainHost) return;
15
14
 
15
+ const client = new Client(env.chainHost);
16
16
  const { state } = await client.getAccountState({ address: wallet.toAddress() }, { ignoreFields: ['context'] });
17
17
  if (!state) {
18
18
  const hash = await client.declare({ moniker: name, wallet });
@@ -47,7 +47,7 @@ if (isProduction) {
47
47
  app.use(router);
48
48
  }
49
49
 
50
- const port = parseInt(process.env.BLOCKLET_PORT || process.env.APP_PORT, 10) || 3030;
50
+ const port = parseInt(process.env.BLOCKLET_PORT, 10) || 3030;
51
51
 
52
52
  app.listen(port, (err) => {
53
53
  if (err) throw err;
@@ -1,26 +1,17 @@
1
1
  const path = require('path');
2
2
  const AuthStorage = require('@arcblock/did-auth-storage-nedb');
3
+ const getWallet = require('@blocklet/sdk/lib/wallet');
3
4
  const WalletAuthenticator = require('@blocklet/sdk/lib/wallet-authenticator');
4
- const WalletHandlers = require('@blocklet/sdk/lib/wallet-handler');
5
- const { types } = require('@ocap/mcrypto');
6
- const { fromSecretKey, WalletType } = require('@ocap/wallet');
7
- const logger = require('./logger');
5
+ const WalletHandler = require('@blocklet/sdk/lib/wallet-handler');
8
6
 
9
- const appSk = process.env.APP_SK || process.env.BLOCKLET_APP_SK;
10
- const wallet = fromSecretKey(appSk, WalletType({ role: types.RoleType.ROLE_APPLICATION }));
7
+ const env = require('./env');
11
8
 
9
+ const wallet = getWallet();
12
10
  const authenticator = new WalletAuthenticator();
13
-
14
- const handlers = new WalletHandlers({
11
+ const handlers = new WalletHandler({
15
12
  authenticator,
16
- tokenGenerator: () => Date.now().toString(),
17
13
  tokenStorage: new AuthStorage({
18
- dbPath: path.join(process.env.BLOCKLET_DATA_DIR, 'auth.db'),
19
- onload: (err) => {
20
- if (err) {
21
- logger.error(`Failed to load database from ${path.join(process.env.BLOCKLET_DATA_DIR, 'auth.db')}`, err);
22
- }
23
- },
14
+ dbPath: path.join(env.dataDir, 'auth.db'),
24
15
  }),
25
16
  });
26
17
 
@@ -1,12 +1,6 @@
1
- const blockletRealDid = process.env.BLOCKLET_REAL_DID || '';
2
- const blockletDid = process.env.BLOCKLET_DID || '';
3
- const isComponent = blockletRealDid && blockletDid && blockletRealDid !== blockletDid;
1
+ const env = require('@blocklet/sdk/lib/env');
4
2
 
5
3
  module.exports = {
6
- chainId: process.env.CHAIN_ID || '',
4
+ ...env,
7
5
  chainHost: process.env.CHAIN_HOST || '',
8
- appId: process.env.BLOCKLET_APP_ID || '',
9
- appName: process.env.APP_NAME || process.env.BLOCKLET_APP_NAME || '',
10
- appDescription: process.env.APP_DESCRIPTION || process.env.BLOCKLET_APP_DESCRIPTION || '',
11
- isComponent,
12
6
  };
@@ -1,6 +1,6 @@
1
+ const middleware = require('@blocklet/sdk/lib/middlewares');
1
2
  const router = require('express').Router();
2
- const env = require('../libs/env');
3
3
 
4
- router.use('/env', (req, res) => res.json(env));
4
+ router.use('/user', middleware.user(), (req, res) => res.json(req.user));
5
5
 
6
6
  module.exports = router;
@@ -7,7 +7,7 @@
7
7
  <HelloWorld msg="Welcome to Your Vue.js App" />
8
8
  <div :style="{ display: 'flex', justifyContent: 'center' }">
9
9
  <pre :style="{ textAlign: 'left' }">
10
- <code>{{ JSON.stringify(envData, null, 2) }}</code>
10
+ <code>{{ JSON.stringify(window.blocklet, null, 2) }}</code>
11
11
  </pre>
12
12
  </div>
13
13
  </div>
@@ -21,16 +21,6 @@ export default {
21
21
  components: {
22
22
  HelloWorld,
23
23
  },
24
- data() {
25
- return {
26
- envData: {},
27
- };
28
- },
29
- mounted() {
30
- api.get('/api/env').then(({ data }) => {
31
- this.envData = data;
32
- });
33
- },
34
24
  };
35
25
  </script>
36
26
 
@@ -139,7 +139,7 @@ After developing a blocklet, you may need to bundle it. Use `npm run bundle` com
139
139
  ## Learn More
140
140
 
141
141
  - Full specification of `blocklet.yml`: [https://github.com/blocklet/blocklet-specification/blob/main/docs/meta.md](https://github.com/blocklet/blocklet-specification/blob/main/docs/meta.md)
142
- - Full document of AbtNode & blocklet development: [https://docs.arcblock.io/abtnode/en/introduction](https://docs.arcblock.io/abtnode/en/introduction)
142
+ - Full document of Blocklet Server & blocklet development: [https://docs.arcblock.io/abtnode/en/introduction](https://docs.arcblock.io/abtnode/en/introduction)
143
143
 
144
144
  ## License
145
145
 
@@ -1,6 +1,6 @@
1
1
  name: template-react
2
2
  title: Blocklet Template React
3
- description: ABT Node blocklet project
3
+ description: A Blocklet Server blocklet
4
4
  keywords:
5
5
  - blocklet
6
6
  - react
@@ -139,7 +139,7 @@ After developing a blocklet, you may need to bundle it. Use `npm run bundle` com
139
139
  ## Learn More
140
140
 
141
141
  - Full specification of `blocklet.yml`: [https://github.com/blocklet/blocklet-specification/blob/main/docs/meta.md](https://github.com/blocklet/blocklet-specification/blob/main/docs/meta.md)
142
- - Full document of AbtNode & blocklet development: [https://docs.arcblock.io/abtnode/en/introduction](https://docs.arcblock.io/abtnode/en/introduction)
142
+ - Full document of Blocklet Server & blocklet development: [https://docs.arcblock.io/abtnode/en/introduction](https://docs.arcblock.io/abtnode/en/introduction)
143
143
 
144
144
  ## License
145
145
 
@@ -1,6 +1,6 @@
1
1
  name: template-vue
2
2
  title: Blocklet Template Vue
3
- description: ABT Node blocklet project
3
+ description: A Blocklet Server blocklet
4
4
  keywords:
5
5
  - blocklet
6
6
  - vue
@@ -139,7 +139,7 @@ After developing a blocklet, you may need to bundle it. Use `npm run bundle` com
139
139
  ## Learn More
140
140
 
141
141
  - Full specification of `blocklet.yml`: [https://github.com/blocklet/blocklet-specification/blob/main/docs/meta.md](https://github.com/blocklet/blocklet-specification/blob/main/docs/meta.md)
142
- - Full document of AbtNode & blocklet development: [https://docs.arcblock.io/abtnode/en/introduction](https://docs.arcblock.io/abtnode/en/introduction)
142
+ - Full document of Blocklet Server & blocklet development: [https://docs.arcblock.io/abtnode/en/introduction](https://docs.arcblock.io/abtnode/en/introduction)
143
143
 
144
144
  ## License
145
145
 
@@ -1,6 +1,6 @@
1
1
  name: template-vue2
2
2
  title: Blocklet Template Vue2
3
- description: ABT Node blocklet project
3
+ description: A Blocklet Server blocklet
4
4
  keywords:
5
5
  - blocklet
6
6
  - vue
@@ -1,10 +0,0 @@
1
- module.exports = (req, res, next) => {
2
- if (req.headers['x-user-did']) {
3
- req.user = {
4
- did: req.headers['x-user-did'],
5
- role: req.headers['x-user-role'],
6
- fullName: decodeURIComponent(req.headers['x-user-fullname']),
7
- };
8
- }
9
- next();
10
- };
@@ -1,10 +0,0 @@
1
- module.exports = (req, res, next) => {
2
- if (req.headers['x-user-did']) {
3
- req.user = {
4
- did: req.headers['x-user-did'],
5
- role: req.headers['x-user-role'],
6
- fullName: decodeURIComponent(req.headers['x-user-fullname']),
7
- };
8
- }
9
- next();
10
- };
@@ -1,10 +0,0 @@
1
- module.exports = (req, res, next) => {
2
- if (req.headers['x-user-did']) {
3
- req.user = {
4
- did: req.headers['x-user-did'],
5
- role: req.headers['x-user-role'],
6
- fullName: decodeURIComponent(req.headers['x-user-fullname']),
7
- };
8
- }
9
- next();
10
- };