create-blocklet 0.9.5 → 0.9.7

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 (137) hide show
  1. package/common/.prettierrc +11 -1
  2. package/common/scripts/build-clean.mjs +0 -1
  3. package/common/scripts/bump-version.mjs +33 -29
  4. package/index.js +86 -10
  5. package/package.json +1 -1
  6. package/templates/base-readme.md +103 -0
  7. package/templates/did-connect-dapp/.eslintrc.js +4 -0
  8. package/templates/did-connect-dapp/README.md +143 -0
  9. package/templates/did-connect-dapp/api/dev.js +5 -0
  10. package/templates/did-connect-dapp/api/hooks/pre-start.js +33 -0
  11. package/templates/did-connect-dapp/api/index.js +48 -0
  12. package/templates/did-connect-dapp/api/libs/auth.js +25 -0
  13. package/templates/did-connect-dapp/api/libs/env.js +9 -0
  14. package/templates/did-connect-dapp/api/libs/logger.js +3 -0
  15. package/templates/did-connect-dapp/api/libs/utils.js +70 -0
  16. package/templates/did-connect-dapp/api/routes/auth/index.js +15 -0
  17. package/templates/did-connect-dapp/api/routes/auth/request-digest-signature.js +51 -0
  18. package/templates/did-connect-dapp/api/routes/auth/request-multiple-claims.js +52 -0
  19. package/templates/did-connect-dapp/api/routes/auth/request-multiple-steps.js +57 -0
  20. package/templates/did-connect-dapp/api/routes/auth/request-nft.js +82 -0
  21. package/templates/did-connect-dapp/api/routes/auth/request-payment.js +72 -0
  22. package/templates/did-connect-dapp/api/routes/auth/request-profile.js +25 -0
  23. package/templates/did-connect-dapp/api/routes/auth/request-text-signature.js +44 -0
  24. package/templates/did-connect-dapp/api/routes/auth/request-transaction-signature.js +62 -0
  25. package/templates/did-connect-dapp/blocklet.md +5 -0
  26. package/templates/did-connect-dapp/blocklet.yml +57 -0
  27. package/templates/did-connect-dapp/index.html +17 -0
  28. package/templates/did-connect-dapp/package.json +86 -0
  29. package/templates/did-connect-dapp/src/app.jsx +20 -0
  30. package/templates/did-connect-dapp/src/assets/get_wallet_en.png +0 -0
  31. package/templates/did-connect-dapp/src/assets/get_wallet_zh.png +0 -0
  32. package/templates/did-connect-dapp/src/components/connect-item.jsx +39 -0
  33. package/templates/did-connect-dapp/src/components/connects/request-digest-signature.jsx +45 -0
  34. package/templates/did-connect-dapp/src/components/connects/request-multiple-claims.jsx +55 -0
  35. package/templates/did-connect-dapp/src/components/connects/request-multiple-steps.jsx +54 -0
  36. package/templates/did-connect-dapp/src/components/connects/request-nft.jsx +75 -0
  37. package/templates/did-connect-dapp/src/components/connects/request-payment.jsx +82 -0
  38. package/templates/did-connect-dapp/src/components/connects/request-profile.jsx +72 -0
  39. package/templates/did-connect-dapp/src/components/connects/request-text-signature.jsx +44 -0
  40. package/templates/did-connect-dapp/src/components/connects/request-transaction-signature.jsx +44 -0
  41. package/templates/did-connect-dapp/src/components/info-row.jsx +39 -0
  42. package/templates/did-connect-dapp/src/components/layout.jsx +26 -0
  43. package/templates/did-connect-dapp/src/index.jsx +6 -0
  44. package/templates/did-connect-dapp/src/libs/session.js +11 -0
  45. package/templates/did-connect-dapp/src/libs/utils.js +4 -0
  46. package/templates/did-connect-dapp/src/locales/en.js +115 -0
  47. package/templates/did-connect-dapp/src/locales/index.js +5 -0
  48. package/templates/did-connect-dapp/src/locales/zh.js +115 -0
  49. package/templates/did-connect-dapp/src/pages/main.jsx +95 -0
  50. package/templates/did-connect-dapp/template-info.json +12 -0
  51. package/templates/did-connect-dapp/vite.config.mjs +11 -0
  52. package/templates/did-wallet-dapp/.eslintrc.js +7 -0
  53. package/templates/did-wallet-dapp/README.md +32 -0
  54. package/templates/did-wallet-dapp/api/dev.js +8 -0
  55. package/templates/did-wallet-dapp/api/functions/app.js +65 -0
  56. package/templates/did-wallet-dapp/api/index.js +13 -0
  57. package/templates/did-wallet-dapp/api/libs/constant.js +1 -0
  58. package/templates/did-wallet-dapp/api/routes/user.js +30 -0
  59. package/templates/did-wallet-dapp/blocklet.md +3 -0
  60. package/templates/did-wallet-dapp/blocklet.yml +58 -0
  61. package/templates/did-wallet-dapp/index.html +16 -0
  62. package/templates/did-wallet-dapp/package.json +84 -0
  63. package/templates/did-wallet-dapp/src/app.jsx +38 -0
  64. package/templates/did-wallet-dapp/src/assets/blocklet.svg +16 -0
  65. package/templates/did-wallet-dapp/src/assets/react.svg +1 -0
  66. package/templates/did-wallet-dapp/src/assets/vite.svg +1 -0
  67. package/templates/did-wallet-dapp/src/assets/wallet.png +0 -0
  68. package/templates/did-wallet-dapp/src/components/layout.jsx +28 -0
  69. package/templates/did-wallet-dapp/src/global.css +79 -0
  70. package/templates/did-wallet-dapp/src/index.jsx +6 -0
  71. package/templates/did-wallet-dapp/src/libs/api.js +7 -0
  72. package/templates/did-wallet-dapp/src/libs/session.js +13 -0
  73. package/templates/did-wallet-dapp/src/locales/en.js +13 -0
  74. package/templates/did-wallet-dapp/src/locales/index.js +4 -0
  75. package/templates/did-wallet-dapp/src/locales/zh.js +13 -0
  76. package/templates/did-wallet-dapp/src/pages/home/index.css +39 -0
  77. package/templates/did-wallet-dapp/src/pages/home/index.jsx +57 -0
  78. package/templates/did-wallet-dapp/src/pages/profile.jsx +136 -0
  79. package/templates/did-wallet-dapp/template-info.json +12 -0
  80. package/templates/did-wallet-dapp/vite.config.js +14 -0
  81. package/templates/did-wallet-dapp/vite.config.server.js +9 -0
  82. package/templates/express-api/README.md +2 -124
  83. package/templates/express-api/blocklet.yml +0 -1
  84. package/templates/express-api/package.json +9 -8
  85. package/templates/html-static/README.md +3 -125
  86. package/templates/html-static/blocklet.yml +0 -1
  87. package/templates/html-static/package.json +4 -3
  88. package/templates/monorepo/README.md +8 -8
  89. package/templates/monorepo/package.json +4 -3
  90. package/templates/monorepo/scripts/bump-version.mjs +36 -32
  91. package/templates/nestjs-api/README.md +2 -123
  92. package/templates/nestjs-api/blocklet.yml +0 -1
  93. package/templates/nestjs-api/package.json +16 -15
  94. package/templates/nextjs-dapp/README.md +2 -125
  95. package/templates/nextjs-dapp/blocklet.yml +0 -1
  96. package/templates/nextjs-dapp/package.json +7 -7
  97. package/templates/react-dapp/README.md +2 -124
  98. package/templates/react-dapp/blocklet.yml +0 -1
  99. package/templates/react-dapp/package.json +16 -15
  100. package/templates/react-dapp-ts/README.md +2 -125
  101. package/templates/react-dapp-ts/blocklet.yml +0 -1
  102. package/templates/react-dapp-ts/package.json +19 -18
  103. package/templates/react-gun-dapp/README.md +2 -125
  104. package/templates/react-gun-dapp/blocklet.yml +0 -1
  105. package/templates/react-gun-dapp/package.json +15 -14
  106. package/templates/react-static/README.md +2 -125
  107. package/templates/react-static/blocklet.yml +0 -1
  108. package/templates/react-static/package.json +11 -10
  109. package/templates/solidjs-dapp/README.md +2 -125
  110. package/templates/solidjs-dapp/blocklet.yml +0 -1
  111. package/templates/solidjs-dapp/package.json +14 -13
  112. package/templates/solidjs-static/README.md +2 -123
  113. package/templates/solidjs-static/blocklet.yml +0 -1
  114. package/templates/solidjs-static/package.json +9 -8
  115. package/templates/svelte-dapp/README.md +2 -124
  116. package/templates/svelte-dapp/blocklet.yml +0 -1
  117. package/templates/svelte-dapp/package.json +12 -11
  118. package/templates/svelte-static/README.md +2 -125
  119. package/templates/svelte-static/blocklet.yml +0 -1
  120. package/templates/svelte-static/package.json +8 -7
  121. package/templates/todo-list-example/blocklet.yml +0 -1
  122. package/templates/todo-list-example/package.json +11 -10
  123. package/templates/vue-dapp/README.md +2 -125
  124. package/templates/vue-dapp/blocklet.yml +0 -1
  125. package/templates/vue-dapp/package.json +16 -15
  126. package/templates/vue-static/README.md +2 -125
  127. package/templates/vue-static/blocklet.yml +0 -1
  128. package/templates/vue-static/package.json +11 -10
  129. package/templates/vue-ts-static/README.md +2 -124
  130. package/templates/vue-ts-static/blocklet.yml +1 -2
  131. package/templates/vue-ts-static/package.json +12 -12
  132. package/templates/vue2-dapp/README.md +2 -125
  133. package/templates/vue2-dapp/blocklet.yml +0 -1
  134. package/templates/vue2-dapp/package.json +13 -12
  135. package/templates/vue2-static/README.md +2 -125
  136. package/templates/vue2-static/blocklet.yml +0 -1
  137. package/templates/vue2-static/package.json +9 -8
@@ -0,0 +1,26 @@
1
+ import { Footer, Header } from '@blocklet/ui-react';
2
+ import { Box, Container } from '@mui/material';
3
+ import PropTypes from 'prop-types';
4
+
5
+ export default function Layout({ children }) {
6
+ return (
7
+ <Box>
8
+ <Header maxWidth="unset" />
9
+ <Container maxWidth="lg" my={3}>
10
+ {children}
11
+ </Container>
12
+ <Box
13
+ component={Footer}
14
+ sx={{
15
+ '&>div>.MuiContainer-root': {
16
+ maxWidth: 'unset',
17
+ },
18
+ }}
19
+ />
20
+ </Box>
21
+ );
22
+ }
23
+
24
+ Layout.propTypes = {
25
+ children: PropTypes.any.isRequired,
26
+ };
@@ -0,0 +1,6 @@
1
+ import ReactDOM from 'react-dom/client';
2
+
3
+ import App from './app';
4
+
5
+ const root = ReactDOM.createRoot(document.getElementById('app'));
6
+ root.render(<App />);
@@ -0,0 +1,11 @@
1
+ import { createAuthServiceSessionContext } from '@arcblock/did-connect/lib/Session';
2
+ import { useContext } from 'react';
3
+
4
+ const { SessionProvider, SessionContext, SessionConsumer, withSession } = createAuthServiceSessionContext();
5
+
6
+ function useSessionContext() {
7
+ const info = useContext(SessionContext);
8
+ return info;
9
+ }
10
+
11
+ export { SessionProvider, SessionContext, SessionConsumer, useSessionContext, withSession };
@@ -0,0 +1,4 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ export const getExplorerUrl = (assetDidOrHash, type = 'txs') => {
3
+ return `https://explorer.abtnetwork.io/explorer/${type}/${assetDidOrHash}?host=${window.blocklet.CHAIN_HOST}`;
4
+ };
@@ -0,0 +1,115 @@
1
+ import { flatten } from 'flat';
2
+
3
+ export default flatten({
4
+ result: 'Result',
5
+ step1: {
6
+ title: 'Step 1',
7
+ prepareDIDWallet: 'Prepare DID Wallet',
8
+ getWalletFromHere: 'Get DID Wallet from here',
9
+ },
10
+ step2: {
11
+ title: 'Step 2',
12
+ enjoyPlayground: 'Enjoy The DID Connect Playground',
13
+ },
14
+ claims: {
15
+ requestProfile: {
16
+ title: 'Request Profile',
17
+ description: 'If the app need user name/email to function properly, you can request a profile from the user.',
18
+ connect: {
19
+ title: 'Request Profile',
20
+ scan: 'Please provide your name and email to continue',
21
+ },
22
+ result: {
23
+ fullName: 'Full Name',
24
+ email: 'Email Address',
25
+ phone: 'Phone Number',
26
+ birthday: 'Birthday',
27
+ },
28
+ },
29
+ requestNFT: {
30
+ title: 'Request NFT',
31
+ description: 'Get a badge or Certificate from here',
32
+ connect: {
33
+ title: 'Request NFT',
34
+ scan: 'Please provide a NFT to continue',
35
+ },
36
+ },
37
+ requestTextSig: {
38
+ title: 'Request Text Signature',
39
+ description: 'In some cases, app may want user to sign some text to authorize the app to do something.',
40
+ connect: {
41
+ title: 'Request Text Signature',
42
+ scan: 'Please sign some text to continue',
43
+ },
44
+ result: {
45
+ origin: 'Original Text',
46
+ signature: 'Signature',
47
+ },
48
+ },
49
+ requestDigestSig: {
50
+ title: 'Request Digest Signature',
51
+ description:
52
+ 'In some cases, when the data to be signed is too large to display in DID Wallet, the app shall request the Wallet to sign the digest of the data.',
53
+ connect: {
54
+ title: 'Request Digest Signature',
55
+ scan: 'Please sign the digest to continue',
56
+ },
57
+ result: {
58
+ origin: 'Original Text',
59
+ digest: 'Digest',
60
+ signature: 'Signature',
61
+ },
62
+ },
63
+ requestTransactionSig: {
64
+ title: 'Request Transaction Signature',
65
+ description: 'When the app needs user to sign some transaction that can be broadcast to ArcBlock chain.',
66
+ connect: {
67
+ title: 'Request Transaction Signature',
68
+ scan: 'Please sign a transaction to continue',
69
+ },
70
+ result: {
71
+ hash: 'Transaction Hash',
72
+ signature: 'Signature',
73
+ },
74
+ },
75
+ requestPayment: {
76
+ title: 'Request Payment',
77
+ description: 'When the app needs user to pay some token to get some service.',
78
+ takeTokenFromHere: 'Please take some TBA from here',
79
+ connect: {
80
+ title: 'Request Payment',
81
+ scan: 'Please sign the transaction to continue',
82
+ },
83
+ result: {
84
+ hash: 'Transaction Hash',
85
+ signature: 'Signature',
86
+ },
87
+ },
88
+ requestMultipleClaims: {
89
+ title: 'Request Multiple Claims',
90
+ description: 'Request text signature and digest signature in a single session.',
91
+ connect: {
92
+ title: 'Request Multiple Claims',
93
+ scan: 'In that session, you will do both text signing and summary signing.',
94
+ },
95
+ result: {
96
+ origin: 'Original Text',
97
+ digest: 'Digest',
98
+ signature: 'Signature',
99
+ },
100
+ },
101
+ requestMultipleSteps: {
102
+ title: 'Request Multiple Steps',
103
+ description: 'Request text signature and then request digest signature.',
104
+ connect: {
105
+ title: 'Request Multiple Steps',
106
+ scan: 'In that session, you will do a text signature followed by a summary signature.',
107
+ },
108
+ result: {
109
+ origin: 'Original Text',
110
+ digest: 'Digest',
111
+ signature: 'Signature',
112
+ },
113
+ },
114
+ },
115
+ });
@@ -0,0 +1,5 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ import en from './en';
3
+ import zh from './zh';
4
+
5
+ export const translations = { zh, en };
@@ -0,0 +1,115 @@
1
+ import { flatten } from 'flat';
2
+
3
+ export default flatten({
4
+ result: '操作结果',
5
+ step1: {
6
+ title: '第一步',
7
+ prepareDIDWallet: '准备 DID Wallet',
8
+ getWalletFromHere: '从这里获取 DID Wallet',
9
+ },
10
+ step2: {
11
+ title: '第二步',
12
+ enjoyPlayground: '享受 DID Connect 游乐场',
13
+ },
14
+ claims: {
15
+ requestProfile: {
16
+ title: '获取用户信息',
17
+ description: '当应用需要用户名称/邮件地址来正常使用时,可以请求用户提供相关信息。',
18
+ connect: {
19
+ title: '获取用户信息',
20
+ scan: '请提供您的个人信息,以便我们可以为您提供更好的服务。',
21
+ },
22
+ result: {
23
+ fullName: '用户名',
24
+ email: '邮箱地址',
25
+ phone: '电话号码',
26
+ birthday: '生日',
27
+ },
28
+ },
29
+ requestNFT: {
30
+ title: '请求 NFT',
31
+ description: '从这里获取徽章或证书',
32
+ connect: {
33
+ title: '请出示一个 NFT',
34
+ scan: '请出示一个 NFT,以便验证您是否有抽奖的机会',
35
+ },
36
+ },
37
+ requestTextSig: {
38
+ title: '请求文本签名',
39
+ description: '在某些情况下,应用可能需要用户签名一段文本来授权应用做一些事情。',
40
+ connect: {
41
+ title: '请求文本签名',
42
+ scan: '请签名一段文本,以便验证您的安全。',
43
+ },
44
+ result: {
45
+ origin: '签名数据',
46
+ signature: '签名结果',
47
+ },
48
+ },
49
+ requestDigestSig: {
50
+ title: '请求摘要签名',
51
+ description:
52
+ '在某些情况下,当需要签名的数据太大,不适合在 DID Wallet 中显示时,应用可以请求 Wallet 签名数据的摘要。',
53
+ connect: {
54
+ title: '请求摘要签名',
55
+ scan: '请签名一段摘要,以便验证您的安全。',
56
+ },
57
+ result: {
58
+ origin: '签名数据',
59
+ digest: '摘要数据',
60
+ signature: '签名结果',
61
+ },
62
+ },
63
+ requestTransactionSig: {
64
+ title: '请求交易签名',
65
+ description: '当应用需要用户签名一个可以广播到 ArcBlock 链的交易时。',
66
+ connect: {
67
+ title: '请求交易签名',
68
+ scan: '请签名一个交易,以便验证交易的安全性。',
69
+ },
70
+ result: {
71
+ hash: '交易 hash',
72
+ signature: '签名结果',
73
+ },
74
+ },
75
+ requestPayment: {
76
+ title: '请求付款',
77
+ description: '当应用需要用户支付一些代币来获取某种服务时。',
78
+ takeTokenFromHere: '请从这里获取一些代币',
79
+ connect: {
80
+ title: '请求付款',
81
+ scan: '该笔订单需要您确认,才能完成付款。',
82
+ },
83
+ result: {
84
+ hash: '交易 hash',
85
+ signature: '签名结果',
86
+ },
87
+ },
88
+ requestMultipleClaims: {
89
+ title: '多个操作',
90
+ description: '在同一个会话中请求文本签名和摘要签名。',
91
+ connect: {
92
+ title: '请求多个操作',
93
+ scan: '在该会话中,您将同时进行文本签名和摘要签名。',
94
+ },
95
+ result: {
96
+ origin: '签名数据',
97
+ digest: '摘要数据',
98
+ signature: '签名结果',
99
+ },
100
+ },
101
+ requestMultipleSteps: {
102
+ title: '多个步骤',
103
+ description: '先请求文本签名,然后再请求摘要签名。',
104
+ connect: {
105
+ title: '请求多步操作',
106
+ scan: '在该会话中,您将先进行文本签名,然后进行摘要签名。',
107
+ },
108
+ result: {
109
+ origin: '签名数据',
110
+ digest: '摘要数据',
111
+ signature: '签名结果',
112
+ },
113
+ },
114
+ },
115
+ });
@@ -0,0 +1,95 @@
1
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
2
+ import iconOpenInNewRounded from '@iconify-icons/material-symbols/open-in-new-rounded';
3
+ import { Icon } from '@iconify/react';
4
+ import { Box, Link, Typography } from '@mui/material';
5
+
6
+ import getWalletEnImg from '../assets/get_wallet_en.png';
7
+ import getWalletZhImg from '../assets/get_wallet_zh.png';
8
+ import RequestDigestSignature from '../components/connects/request-digest-signature';
9
+ import RequestMultipleClaims from '../components/connects/request-multiple-claims';
10
+ import RequestMultipleSteps from '../components/connects/request-multiple-steps';
11
+ import RequestNFT from '../components/connects/request-nft';
12
+ import RequestPayment from '../components/connects/request-payment';
13
+ import RequestProfile from '../components/connects/request-profile';
14
+ import RequestTextSignature from '../components/connects/request-text-signature';
15
+ import RequestTransactionSignature from '../components/connects/request-transaction-signature';
16
+ import Layout from '../components/layout';
17
+
18
+ function Main() {
19
+ const { locale, t } = useLocaleContext();
20
+ const getWalletImgUrl = locale === 'zh' ? getWalletZhImg : getWalletEnImg;
21
+ const getWalletUrl = `https://www.didwallet.io/${locale === 'zh' ? 'zh' : 'en'}`;
22
+
23
+ return (
24
+ <Layout>
25
+ <Typography component="h3" variant="h4" color="textPrimary" gutterBottom>
26
+ {t('step1.title')}{' '}
27
+ <Typography component="small" color="text.secondary">
28
+ {t('step1.prepareDIDWallet')}
29
+ </Typography>
30
+ </Typography>
31
+ <Typography variant="body1">
32
+ {t('step1.getWalletFromHere')}{' '}
33
+ <Link
34
+ href={getWalletUrl}
35
+ target="_blank"
36
+ underline="hover"
37
+ sx={{
38
+ display: 'inline-flex',
39
+ alignItems: 'center',
40
+ gap: 0.5,
41
+ }}>
42
+ DID Wallet <Icon icon={iconOpenInNewRounded} />
43
+ </Link>
44
+ </Typography>
45
+ <Box
46
+ component="a"
47
+ href={getWalletUrl}
48
+ target="_blank"
49
+ rel="noreferrer"
50
+ sx={{
51
+ display: 'block',
52
+ px: {
53
+ sm: 0,
54
+ md: 8,
55
+ lg: 16,
56
+ },
57
+ }}>
58
+ <Box
59
+ component="img"
60
+ src={getWalletImgUrl}
61
+ alt="Prepare DID Wallet"
62
+ sx={{
63
+ width: '100%',
64
+ }}
65
+ />
66
+ </Box>
67
+
68
+ <Typography component="h3" variant="h4" color="text.primary" gutterBottom sx={{ mt: 2 }}>
69
+ {t('step2.title')}{' '}
70
+ <Typography component="small" color="text.secondary">
71
+ {t('step2.enjoyPlayground')}
72
+ </Typography>
73
+ </Typography>
74
+
75
+ <Box
76
+ sx={{
77
+ display: 'flex',
78
+ flexDirection: 'column',
79
+ gap: 5,
80
+ mb: 10,
81
+ }}>
82
+ <RequestProfile />
83
+ <RequestNFT />
84
+ <RequestTextSignature />
85
+ <RequestDigestSignature />
86
+ <RequestTransactionSignature />
87
+ <RequestPayment />
88
+ <RequestMultipleClaims />
89
+ <RequestMultipleSteps />
90
+ </Box>
91
+ </Layout>
92
+ );
93
+ }
94
+
95
+ export default Main;
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "did-connect-dapp",
3
+ "desc": {
4
+ "en": "Showcase various use cases of DID Connect, help you get started with DID Connect quickly",
5
+ "zh": "展示 DID Connect 各种用法, 帮助你快速上手 DID Connect"
6
+ },
7
+ "blockletType": "dapp",
8
+ "composable": true,
9
+ "languages": "JavaScript",
10
+ "useCase": "Starter",
11
+ "author": "Blocklet"
12
+ }
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from 'vite';
2
+ import react from '@vitejs/plugin-react';
3
+ import { createBlockletPlugin } from 'vite-plugin-blocklet';
4
+ import svgr from 'vite-plugin-svgr';
5
+
6
+ // https://vitejs.dev/config/
7
+ export default defineConfig(() => {
8
+ return {
9
+ plugins: [react(), createBlockletPlugin(), svgr()],
10
+ };
11
+ });
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ root: true,
3
+ extends: '@arcblock/eslint-config',
4
+ globals: {
5
+ logger: true,
6
+ },
7
+ };
@@ -0,0 +1,32 @@
1
+ ## PROJECT_DESCRIPTION
2
+
3
+ This is a full stack app (react.js + express.js) with DID Wallet integration. That means you can use your DID wallet to login and get a user session.
4
+
5
+ ## FILE_STRUCTURE
6
+
7
+ - public/ - static files
8
+ - favicon.ico - favicon
9
+ - favicon.svg - favicon
10
+ - index.html - main html file, template for react
11
+ - screenshots/ - Screenshots
12
+ - api/ - Api side code
13
+ - hooks/ - blocklet lifecycle hooks
14
+ - libs/ - Api side libraries
15
+ - middlewares/ - Api side middlewares
16
+ - routes/ - Api side routes
17
+ - index.js - Api side entry point
18
+ - src/ - Client side code (A standard react app structure)
19
+ - .env - Environment variables
20
+ - .env.local - Local environment variables
21
+ - .eslintrc.js - ESLint configuration
22
+ - .gitignore - Git ignore file
23
+ - .prettierrc - Prettier configuration
24
+ - blocklet.md - Blocklet README
25
+ - blocklet.yml - Blocklet configuration
26
+ - LICENSE - License file
27
+ - logo.png - Blocklet logo file
28
+ - package.json - Npm package file
29
+ - README.md - A guide for this blocklet
30
+ - version - Version file
31
+
32
+
@@ -0,0 +1,8 @@
1
+ const { app, server } = require('./index');
2
+
3
+ import('vite-plugin-blocklet').then(({ setupClient }) => {
4
+ setupClient(app, {
5
+ server,
6
+ importMetaHot: import.meta.hot,
7
+ });
8
+ });
@@ -0,0 +1,65 @@
1
+ /* eslint-disable no-console */
2
+ const path = require('path');
3
+ const cors = require('cors');
4
+ const morgan = require('morgan');
5
+ const express = require('express');
6
+ const cookieParser = require('cookie-parser');
7
+ const bodyParser = require('body-parser');
8
+ const fallback = require('@blocklet/sdk/lib/middlewares/fallback');
9
+
10
+ const userRoutes = require('../routes/user');
11
+
12
+ const isProduction = process.env.NODE_ENV !== 'development';
13
+
14
+ // Create and config express application
15
+ const server = express();
16
+ server.use(cookieParser());
17
+ server.use(bodyParser.json());
18
+ server.use(bodyParser.urlencoded({ extended: true }));
19
+ server.use(cors());
20
+
21
+ const router = express.Router();
22
+
23
+ userRoutes.init(router);
24
+
25
+ if (isProduction) {
26
+ server.use(
27
+ morgan((tokens, req, res) => {
28
+ const log = [
29
+ tokens.method(req, res),
30
+ tokens.url(req, res),
31
+ tokens.status(req, res),
32
+ tokens.res(req, res, 'content-length'),
33
+ '-',
34
+ tokens['response-time'](req, res),
35
+ 'ms',
36
+ ].join(' ');
37
+
38
+ if (isProduction) {
39
+ // Log only in AWS context to get back function logs
40
+ console.log(log);
41
+ }
42
+
43
+ return log;
44
+ }),
45
+ );
46
+ server.use(router);
47
+
48
+ const staticDir = path.resolve(__dirname, '../../', 'dist');
49
+ server.use(express.static(staticDir, { maxAge: '365d', index: false }));
50
+ server.use(fallback('index.html', { root: staticDir }));
51
+
52
+ server.use((req, res) => {
53
+ res.status(404).send('404 NOT FOUND');
54
+ });
55
+
56
+ // eslint-disable-next-line no-unused-vars
57
+ server.use((err, req, res, next) => {
58
+ console.error(err.stack);
59
+ res.status(500).send('Something broke!');
60
+ });
61
+ } else {
62
+ server.use(router);
63
+ }
64
+
65
+ module.exports = { server };
@@ -0,0 +1,13 @@
1
+ /* eslint-disable no-console */
2
+ const dotenv = require('dotenv-flow');
3
+ dotenv.config();
4
+
5
+ const { server: app } = require('./functions/app');
6
+
7
+ const port = parseInt(process.env.BLOCKLET_PORT, 10) || 3030;
8
+ const server = app.listen(port, (err) => {
9
+ if (err) throw err;
10
+ console.log(`> app ready on ${port}`);
11
+ });
12
+
13
+ module.exports = { app, server };
@@ -0,0 +1 @@
1
+ module.exports = {};
@@ -0,0 +1,30 @@
1
+ const AuthService = require('@blocklet/sdk/service/auth');
2
+ const middlewares = require('@blocklet/sdk/lib/middlewares');
3
+
4
+ const authClient = new AuthService();
5
+
6
+ module.exports = {
7
+ init(app) {
8
+ // middleware.user() is used to get the user info from the session, see more: https://www.arcblock.io/docs/blocklet-developer/blocklet-sdk#session
9
+ app.get('/api/user', middlewares.user(), async (req, res) => {
10
+ if (!req.user) {
11
+ res.json({ user: null });
12
+ return;
13
+ }
14
+ try {
15
+ // get user info from auth service
16
+ const { user } = await authClient.getUser(req.user.did);
17
+ user.role = user.role || req.user.role;
18
+ res.json({ user });
19
+ } catch (err) {
20
+ console.error(err);
21
+ res.json({ user: null });
22
+ }
23
+ });
24
+ app.get('/api/data', (req, res) => {
25
+ res.json({
26
+ message: 'Hello Blocklet!',
27
+ });
28
+ });
29
+ },
30
+ };
@@ -0,0 +1,3 @@
1
+ # Please update here
2
+
3
+ A did wallet dapp template.
@@ -0,0 +1,58 @@
1
+ title: Blocklet Template DID Wallet Dapp
2
+ description: A Blocklet DAPP blocklet
3
+ keywords:
4
+ - blocklet
5
+ - react
6
+ group: dapp
7
+ did: ''
8
+ main: api/index.js
9
+ author:
10
+ name: Blocklet
11
+ email: blocklet@arcblock.io
12
+ repository:
13
+ type: git
14
+ url: 'git+https://github.com/blocklet/create-blocklet.git'
15
+ specVersion: 1.2.8
16
+ version: 0.1.0
17
+ logo: logo.png
18
+ files:
19
+ - dist
20
+ - logo.png
21
+ - screenshots
22
+ interfaces:
23
+ - type: web
24
+ name: publicUrl
25
+ path: /
26
+ prefix: '*'
27
+ port: BLOCKLET_PORT
28
+ protocol: http
29
+ community: ''
30
+ documentation: ''
31
+ homepage: ''
32
+ license: ''
33
+ payment:
34
+ price: []
35
+ share: []
36
+ timeout:
37
+ start: 60
38
+ requirements:
39
+ server: '>=1.16.28'
40
+ os: '*'
41
+ cpu: '*'
42
+ scripts:
43
+ dev: npm run start
44
+ environments: []
45
+ capabilities: {}
46
+ screenshots: []
47
+ components: []
48
+ navigation:
49
+ - id: home
50
+ title:
51
+ en: Home page
52
+ zh: 首页
53
+ link: /home
54
+ - id: profile
55
+ title:
56
+ en: Profile page
57
+ zh: Profile 页面
58
+ link: /profile
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0" />
7
+ <meta name="theme-color" content="#000000" />
8
+ </head>
9
+
10
+ <body>
11
+ <noscript> You need to enable JavaScript to run this app. </noscript>
12
+ <div id="app"></div>
13
+ <script type="module" src="/src/index.jsx"></script>
14
+ </body>
15
+
16
+ </html>