@blocklet/sdk 1.15.17 → 1.16.0-beta-b16cb035

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 (69) hide show
  1. package/README.md +1 -198
  2. package/lib/component/index.d.ts +35 -0
  3. package/lib/component/index.js +95 -0
  4. package/lib/config.d.ts +33 -0
  5. package/lib/config.js +17 -0
  6. package/lib/connect/authenticator.d.ts +5 -0
  7. package/lib/connect/authenticator.js +18 -0
  8. package/lib/connect/handler.d.ts +2 -0
  9. package/lib/connect/handler.js +90 -0
  10. package/lib/connect/shared.d.ts +19 -0
  11. package/lib/connect/shared.js +81 -0
  12. package/lib/database/index.d.ts +13 -0
  13. package/lib/database/index.js +46 -0
  14. package/lib/embed/adapters/express.d.ts +3 -0
  15. package/lib/embed/adapters/express.js +13 -0
  16. package/lib/embed/generate.d.ts +6 -0
  17. package/lib/embed/generate.js +30 -0
  18. package/lib/embed/get-embed-url.d.ts +1 -0
  19. package/lib/embed/get-embed-url.js +55 -0
  20. package/lib/embed/get-embed.d.ts +1 -0
  21. package/lib/embed/get-embed.js +32 -0
  22. package/lib/embed/index.d.ts +10 -0
  23. package/lib/embed/index.js +13 -0
  24. package/lib/embed/message.d.ts +26 -0
  25. package/lib/embed/message.js +134 -0
  26. package/lib/env.d.ts +17 -0
  27. package/lib/env.js +3 -0
  28. package/lib/error-handler.d.ts +0 -0
  29. package/lib/error-handler.js +5 -5
  30. package/lib/index.d.ts +53 -0
  31. package/lib/index.js +49 -12
  32. package/lib/middlewares/auth.d.ts +8 -0
  33. package/lib/middlewares/auth.js +54 -0
  34. package/lib/middlewares/component.d.ts +7 -0
  35. package/lib/middlewares/component.js +32 -0
  36. package/lib/middlewares/index.d.ts +24 -0
  37. package/lib/middlewares/index.js +17 -0
  38. package/lib/middlewares/user.d.ts +10 -0
  39. package/lib/middlewares/user.js +12 -0
  40. package/lib/security/index.d.ts +9 -0
  41. package/lib/security/index.js +27 -0
  42. package/lib/service/auth.d.ts +31 -0
  43. package/lib/service/auth.js +129 -136
  44. package/lib/service/notification.d.ts +47 -0
  45. package/lib/service/notification.js +182 -18
  46. package/lib/types/notification.d.ts +113 -0
  47. package/lib/types/notification.js +3 -0
  48. package/lib/util/check-blocklet-env.d.ts +2 -0
  49. package/lib/util/check-blocklet-env.js +20 -17
  50. package/lib/util/constants.d.ts +5 -0
  51. package/lib/util/constants.js +6 -2
  52. package/lib/util/env.d.ts +19 -0
  53. package/lib/util/env.js +33 -0
  54. package/lib/util/send-notification.d.ts +26 -0
  55. package/lib/util/send-notification.js +149 -38
  56. package/lib/validators/index.d.ts +12 -0
  57. package/lib/validators/index.js +13 -5
  58. package/lib/validators/notification.d.ts +74 -0
  59. package/lib/validators/notification.js +227 -69
  60. package/lib/version.d.ts +6 -0
  61. package/lib/version.js +6 -0
  62. package/lib/wallet-authenticator.d.ts +5 -0
  63. package/lib/wallet-authenticator.js +16 -51
  64. package/lib/wallet-handler.d.ts +19 -0
  65. package/lib/wallet-handler.js +109 -87
  66. package/lib/wallet.d.ts +3 -0
  67. package/lib/wallet.js +10 -0
  68. package/package.json +52 -19
  69. package/lib/database.js +0 -98
package/package.json CHANGED
@@ -3,39 +3,72 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.15.17",
6
+ "version": "1.16.0-beta-b16cb035",
7
7
  "description": "graphql client to read/write data on abt node",
8
8
  "main": "lib/index.js",
9
+ "typings": "lib/index.d.ts",
9
10
  "files": [
10
11
  "lib",
11
12
  "service"
12
13
  ],
13
14
  "scripts": {
14
- "lint": "eslint tests lib",
15
- "lint:fix": "eslint --fix tests lib",
16
- "test": "node tools/jest.js",
17
- "coverage": "npm run test -- --coverage"
15
+ "verify": "npm run lint:fix && npm run test && npm run build",
16
+ "lint": "eslint src tests service",
17
+ "lint:fix": "npm run lint -- --fix",
18
+ "test": "jest --forceExit --detectOpenHandles",
19
+ "coverage": "npm run test -- --coverage",
20
+ "clean": "rm -fr lib",
21
+ "prebuild": "npm run clean && npm run types",
22
+ "types": "rm -rf ./src/types && node tools/version.js && ts-node tools/types.js && rm -f ./src/types/index.ts && prettier --write ./src/types/notification.ts",
23
+ "build": "tsc",
24
+ "build:watch": "npm run build -- -w"
18
25
  },
19
26
  "author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
20
27
  "license": "MIT",
21
28
  "dependencies": {
22
- "@abtnode/client": "1.15.17",
23
- "@abtnode/constant": "1.15.17",
24
- "@arcblock/did-auth": "^1.13.61",
25
- "@arcblock/jwt": "^1.13.61",
26
- "@blocklet/meta": "1.15.17",
27
- "@nedb/core": "^1.2.2",
28
- "@ocap/mcrypto": "^1.13.61",
29
- "@ocap/wallet": "^1.13.61",
30
- "axios": "^0.21.4",
31
- "fs-extra": "^10.0.0",
32
- "joi": "^17.4.0",
29
+ "@abtnode/client": "1.16.0-beta-b16cb035",
30
+ "@abtnode/constant": "1.16.0-beta-b16cb035",
31
+ "@arcblock/did-auth": "1.18.59",
32
+ "@arcblock/jwt": "1.18.59",
33
+ "@arcblock/ws": "1.18.59",
34
+ "@blocklet/constant": "1.16.0-beta-b16cb035",
35
+ "@blocklet/meta": "1.16.0-beta-b16cb035",
36
+ "@did-connect/authenticator": "^2.1.44",
37
+ "@did-connect/handler": "^2.1.44",
38
+ "@nedb/core": "^2.1.5",
39
+ "@ocap/mcrypto": "1.18.59",
40
+ "@ocap/wallet": "1.18.59",
41
+ "axios": "^0.27.2",
42
+ "cheerio": "^1.0.0-rc.12",
43
+ "fs-extra": "^10.1.0",
44
+ "joi": "17.7.0",
45
+ "json-stable-stringify": "^1.0.1",
33
46
  "lodash": "^4.17.21",
47
+ "lru-cache": "^6.0.0",
48
+ "ufo": "^1.1.1",
34
49
  "url-join": "^4.0.1"
35
50
  },
51
+ "resolutions": {
52
+ "@nedb/core": "^2.1.2"
53
+ },
36
54
  "devDependencies": {
37
- "detect-port": "^1.3.0",
38
- "jest": "^27.3.1"
55
+ "@arcblock/eslint-config-ts": "^0.2.3",
56
+ "@types/express": "^4.17.14",
57
+ "@types/jest": "^29.2.0",
58
+ "@types/json-stable-stringify": "^1.0.34",
59
+ "@types/lodash": "^4.14.186",
60
+ "@types/node": "^18.11.0",
61
+ "@typescript-eslint/eslint-plugin": "^5.40.1",
62
+ "@typescript-eslint/parser": "^5.40.1",
63
+ "detect-port": "^1.5.1",
64
+ "eslint": "^8.25.0",
65
+ "jest": "^29.2.0",
66
+ "joi-to-typescript": "^4.0.7",
67
+ "json-stable-stringify": "^1.0.1",
68
+ "prettier": "^2.7.1",
69
+ "ts-jest": "^29.0.3",
70
+ "ts-node": "^10.9.1",
71
+ "typescript": "^4.8.4"
39
72
  },
40
- "gitHead": "22715c3ea74d0230f3413162a17f491614b6735a"
73
+ "gitHead": "138bd91aee5a35b28c2de4e1e924c44932efaf3a"
41
74
  }
package/lib/database.js DELETED
@@ -1,98 +0,0 @@
1
- const path = require('path');
2
- const fs = require('fs-extra');
3
- const { PromisedDatastore } = require('@nedb/core');
4
-
5
- if (!process.env.BLOCKLET_DATA_DIR) {
6
- throw new Error('valid BLOCKLET_DATA_DIR env is required');
7
- }
8
-
9
- const DB_DIR = path.join(process.env.BLOCKLET_DATA_DIR, 'db');
10
- fs.ensureDirSync(DB_DIR);
11
-
12
- /**
13
- * 判断查询的数据是否存在
14
- * 因为函数的定义是判断指定条件是否存在,所以需要直接返回结果,而不是返回一个 nedb 对象或 nedb cursor 对象
15
- * @returns Boolean
16
- */
17
- async function exists(...args) {
18
- const tmp = await this.findOne(...args);
19
- return !!tmp;
20
- }
21
-
22
- /**
23
- * 分页查询
24
- * 这里需要返回一个 nedb cursor 对象,因为后续可能还会链式操作别的方法,所以不能使用 await
25
- * @param {number} page 页码
26
- * @param {number} size 分页大小
27
- * @returns nedb cursor
28
- */
29
- function paginate(page, size) {
30
- const tmp = this.skip(page * size - page).limit(size);
31
- return tmp;
32
- }
33
-
34
- /**
35
- * 代理 nedb cursor,如果需要对查询条件做扩展,需要把方法添加到这里
36
- * @param {Nedb Cursor} cursor
37
- * @returns nedb cursor
38
- */
39
- function proxyCursor(cursor) {
40
- return new Proxy(cursor, {
41
- get(target, prop) {
42
- if (prop === 'paginate') return paginate;
43
-
44
- return target[prop];
45
- },
46
- });
47
- }
48
-
49
- /**
50
- * 代理 nedb 对象,如果需要在 nedb 上增加方法,需要把方法添加到这里
51
- * @param {Nedb} db nedb
52
- * @returns promise
53
- */
54
- function proxyNedb(db) {
55
- return new Proxy(db, {
56
- get(target, prop) {
57
- const propFn = target[prop];
58
- if (prop === 'exists') return exists;
59
-
60
- if (PromisedDatastore.CURSOR_FN_LIST.includes(prop)) {
61
- return function wrap(...args) {
62
- const rawFn = propFn.bind(this)(...args);
63
- return proxyCursor(rawFn);
64
- };
65
- }
66
- return propFn;
67
- },
68
- });
69
- }
70
-
71
- module.exports = function Datastore(name, options = {}) {
72
- if (!new.target) {
73
- throw new Error("This function must called by 'new' command!");
74
- }
75
- const filename = options.filename || path.join(DB_DIR, `${name}.db`);
76
- const db = new PromisedDatastore({
77
- filename,
78
- autoload: true,
79
- timestampData: true,
80
- onload: (err) => {
81
- if (err) {
82
- console.error(`failed to load disk database ${filename}`, err);
83
- }
84
- },
85
- ...options,
86
- });
87
-
88
- const proxyDb = proxyNedb(db);
89
-
90
- // 如果直接返回 proxyDb,则无法使用 class 的 extends 进行类的方法扩展
91
- // 这个 proxy 首先会判断自身是否有这个方法,如果有,则直接返回;如果没有,则会去 proxyDb 中查找
92
- return new Proxy(this, {
93
- get(target, prop) {
94
- if (target[prop]) return target[prop];
95
- return proxyDb[prop];
96
- },
97
- });
98
- };